-
Notifications
You must be signed in to change notification settings - Fork 19
/
pos-check-for-release.yaml
156 lines (138 loc) · 6.1 KB
/
pos-check-for-release.yaml
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
###########################################################
# This is a GCP CloudBuild Trigger config file. The trigger
# is for when a PR is open from a branch named release-x.
# x can be major, minor, or patch.
###########################################################
steps:
###########################################################
# Gating step to ensure we run it only once
###########################################################
- id: 'gate-ci'
name: 'python'
entrypoint: bash
args:
- -c
- |
touch /workspace/release.done
COMMIT_MSG=$(git log -1 --oneline --format=%s | sed 's/^.*: //')
if [[ $$COMMIT_MSG == 'update version before release' ]] || [[ $$COMMIT_MSG == 'bump version to next snapshot' ]]; then
echo "Commit message [$$COMMIT_MSG] indicates release version already being updated. Skip steps."
echo "RELEASE_COMPLETE" > /workspace/release.done
fi
# indicates that the step need not wait for any other step
waitFor: [ '-' ]
###########################################################
# Version bump on release PR
###########################################################
- id: 'bump-version'
name: 'python'
entrypoint: bash
args:
- -c
- |
STATUS=$(cat /workspace/release.done)
if [[ $$STATUS == 'RELEASE_COMPLETE' ]]; then
exit 0
fi
pip install -r .github/releases/requirements.txt
echo "PR openned on branch [$_HEAD_BRANCH] for pr-$_PR_NUMBER"
if [[ $_HEAD_BRANCH == 'release-minor' ]]; then
echo "Updating versions for a minor release"
python3 .github/releases/releaser.py -t minor
elif [[ $_HEAD_BRANCH == 'release-patch' ]]; then
echo "Updating versions for a patch release"
python3 .github/releases/releaser.py -t patch
elif [[ $_HEAD_BRANCH == 'release-major' ]]; then
echo "Updating versions for a major release"
python3 .github/releases/releaser.py -t major
else
echo "Nothing to do since it's not a 'release' PR"
echo "RELEASE_COMPLETE" > /workspace/release.done
fi
VERSION=$(python3 .github/releases/releaser.py -p true)
echo "$$VERSION" > release-version.txt
# indicates that the step need not wait for any other step
waitFor: [ 'gate-ci' ]
###########################################################
# Push the version changes to the repo
###########################################################
- id: 'push-changes-to-repo'
name: 'gcr.io/cloud-builders/git'
secretEnv: [ 'GITHUB_TOKEN', 'GITHUB_EMAIL' ]
entrypoint: bash
args:
- -c
- |
STATUS=$(cat /workspace/release.done)
if [[ $$STATUS == 'RELEASE_COMPLETE' ]]; then
exit 0
fi
# we do this so that the deploy triggers can know the PR number
echo "$_PR_NUMBER" > release-pr.number
git config user.email "$$GITHUB_EMAIL"
git config user.name "Anthos DPE"
# as per: https://stackoverflow.com/a/67886960/3396045
git remote set-branches --add origin $_HEAD_BRANCH
git fetch 'origin'
git checkout --track origin/$_HEAD_BRANCH
git add -A
git commit -m "release: update version before release"
git push -u https://$$GITHUB_TOKEN@github.com/GoogleCloudPlatform/point-of-sale.git $_HEAD_BRANCH
waitFor: [ 'bump-version' ]
###########################################################
# Comment about the release status on the release PR
###########################################################
- id: 'comment-release-status-to-github'
name: 'us-docker.pkg.dev/point-of-sale-ci/third-party-images/github-cli:mar-22'
secretEnv: [ 'GITHUB_TOKEN' ]
entrypoint: bash
args:
- -c
- |
STATUS=$(cat /workspace/release.done)
if [[ $$STATUS == 'RELEASE_COMPLETE' ]]; then
exit 0
fi
COMMIT_MSG=$(git log -1 --oneline --format=%s | sed 's/^.*: //')
if [[ $$COMMIT_MSG != 'update version before release' ]]; then
echo "Commit message [$$COMMIT_MSG] is not a release commit. Skipping step."
exit 0
fi
RELEASE_TYPE='patch'
if [[ $_HEAD_BRANCH == 'release-minor' ]]; then
RELEASE_TYPE='minor'
elif [[ $_HEAD_BRANCH == 'release-major' ]]; then
RELEASE_TYPE='major'
fi
LAST_COMMIT=$(cat .git/refs/heads/$_HEAD_BRANCH)
cat <<EOF > /workspace/gh-comment.txt -
:zap: Release Status :zap: </br>
- **Version updated**: Version in the `pom.xml/package.json` has been updated to the next **$$RELEASE_TYPE** release version.
- **Publish Artifacts:** Check the most recent commit ($$LAST_COMMIT) for correctness and run the ["pos-publish-release-artifacts"](https://console.cloud.google.com/cloud-build/triggers;region=global?project=point-of-sale-ci) trigger against this branch **[$BRANCH_NAME]** to upload the artifacts _(Jars and Images)_ to Artifact registry.
EOF
gh pr comment $_PR_NUMBER --repo $_HEAD_REPO_URL --body-file /workspace/gh-comment.txt
# waitFor: commented out, so this step waits for all previous steps
availableSecrets:
inline:
- kmsKeyName: 'projects/$PROJECT_ID/locations/global/keyRings/$_GHTOKEN_KEYRING_NAME/cryptoKeys/$_GHTOKEN_KEY_NAME'
envMap:
GITHUB_TOKEN: 'CiQAuVI6Z93rj1B1R4yer3G1VzEmW7aHtjATP2jOtyJjkW5qOR8SUQBHWet7zXRDJQTBSvFZuXXsOBIxtvf0VDM610Tjgb5XJY8hbIuBxhsMfDy3+/p2ojVnYmE+Mg9NDg5FGZhlJlB/+PBMCumkbMovTXD582u17A=='
- kmsKeyName: 'projects/$PROJECT_ID/locations/global/keyRings/$_GHEMAIL_KEYRING_NAME/cryptoKeys/$_GHEMAIL_KEY_NAME'
envMap:
GITHUB_EMAIL: 'CiQA/ThyQ4p/sDUR2fsc4Q2GgF/PntA048keplEhVQTrmgESLfcSOACXDXFpPP/ASB9nwBao91OK4677dEaGsJQjVKkStDpHtY1ZtF7qefjxq1qK93BSezLllJX/rHbY'
logsBucket: 'gs://pos-cloudbuild-logs'
options:
logging: GCS_ONLY