forked from DataDog/datadog-lambda-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpublish_prod.sh
More file actions
executable file
·107 lines (83 loc) · 2.57 KB
/
publish_prod.sh
File metadata and controls
executable file
·107 lines (83 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/bin/bash
# Use with `aws-vault exec <PROFILE> -- ./publish_prod.sh <DESIRED_NEW_VERSION>
set -e
BRANCH=$(git rev-parse --abbrev-ref HEAD)
echo $BRANCH
if [ $BRANCH != "main" ]; then
echo "Not on main, aborting"
exit 1
fi
if [ -z "$AWS_ACCESS_KEY_ID" ]; then
echo 'AWS_ACCESS_KEY_ID not set. Are you using aws-vault?'
exit 1
fi
if [ -z "$AWS_SECRET_ACCESS_KEY" ]; then
echo 'AWS_SECRET_ACCESS_KEY not set. Are you using aws-vault?'
exit 1
fi
if [ -z "$AWS_SESSION_TOKEN" ]; then
echo 'AWS_SESSION_TOKEN not set. Are you using aws-vault?'
exit 1
fi
if [ -z "$1" ]; then
echo "Must specify a desired version number"
exit 1
elif [[ ! $1 =~ [0-9]+\.[0-9]+\.[0-9]+ ]]; then
echo "Must use a semantic version, e.g., 3.1.4"
exit 1
else
NEW_VERSION=$1
fi
echo 'Checking AWS Regions'
./scripts/list_layers.sh
read -p "Do the list look good? (y/n) " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]
then
[[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1
fi
VERSION_LINE=$(sed -E -n 's/\"(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\"/"\1.\2.\3"/p' ./datadog_lambda/__init__.py)
CURRENT_VERSION=$(echo "$VERSION_LINE" | cut -d '"' -f 2)
read -p "Ready to publish layers and update the version from $CURRENT_VERSION to $NEW_VERSION? (y/n)" -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]
then
[[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1
fi
echo
echo "Replacing __version__ in ./datadog_lambda/__init__.py"
echo
sed -i "" -E "s/\"(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\"/\"$NEW_VERSION\"/" ./datadog_lambda/__init__.py
git commit ./datadog_lambda/__init__.py -m "Update module version to ${NEW_VERSION}"
echo
echo "Building layers..."
./scripts/build_layers.sh
echo
echo "Signing layers..."
./scripts/sign_layers.sh prod
echo
echo "Publishing layers to AWS regions..."
./scripts/publish_layers.sh
echo
echo 'Pushing updates to github'
MINOR_VERSION=$(echo $NEW_VERSION | cut -d '.' -f 2)
git push origin main
git tag "v$MINOR_VERSION"
git push origin "refs/tags/v$MINOR_VERSION"
echo 'Checking AWS Regions Again...'
./scripts/list_layers.sh
read -p "Do regions look good? Ready to publish $NEW_VERSION to Pypi? (y/n)" -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]
then
[[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1
fi
echo
echo "Publishing to https://pypi.org/project/datadog-lambda/"
./scripts/pypi.sh
echo
echo "Now create a new release with the tag v${MINOR_VERSION} created"
echo "https://github.com/DataDog/datadog-lambda-python/releases/new"
echo
echo "Then publish a new serverless-plugin-datadog version with the new layer versions!"
echo