Skip to content

Commit 166e6f0

Browse files
feat: add release.yaml specific for batch chanegs
1 parent 61f4376 commit 166e6f0

File tree

1 file changed

+302
-0
lines changed

1 file changed

+302
-0
lines changed

batch-change/release.yaml

Lines changed: 302 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,302 @@
1+
meta:
2+
productName: deploy-sourcegraph-k8s
3+
repository: "github.com/sourcegraph/deploy-sourcegraph-k8s"
4+
owners:
5+
- "@sourcegraph/release"
6+
7+
inputs:
8+
- releaseId: server
9+
10+
requirements:
11+
# We use wget here, because curl --fail-with-body was introduced in a version ulterior to what we can have on the CI agents.
12+
- name: "wget"
13+
cmd: "wget --help"
14+
- name: "Github CLI"
15+
cmd: gh version
16+
fixInstructions: brew install gh
17+
- name: "GH auth status"
18+
cmd: "gh auth status"
19+
fixInstructions: "gh auth login"
20+
- name: "Docker username"
21+
env: DOCKER_USERNAME
22+
- name: "Docker password"
23+
env: DOCKER_PASSWORD
24+
25+
internal:
26+
# Please keep in mind that the CI pipeline uses the branch names defined below when creating releases.
27+
# Therefore, if you update them, or if you decide to change how we detect what kind of build we're dealing
28+
# with, please update this file as well.
29+
create:
30+
steps:
31+
patch:
32+
- name: "sg ops (base)"
33+
cmd: |
34+
set -eu
35+
sg ops update-images \
36+
--kind k8s \
37+
--registry us-central1-docker.pkg.dev/sourcegraph-ci/rfc795-internal \
38+
--docker-username=$DOCKER_USERNAME \
39+
--docker-password=$DOCKER_PASSWORD \
40+
--pin-tag {{inputs.server.tag}} \
41+
../base/
42+
- name: "sg ops (executors)"
43+
cmd: |
44+
set -eu
45+
sg ops update-images \
46+
--kind k8s \
47+
--registry us-central1-docker.pkg.dev/sourcegraph-ci/rfc795-internal \
48+
--docker-username=$DOCKER_USERNAME \
49+
--docker-password=$DOCKER_PASSWORD \
50+
--pin-tag {{inputs.server.tag}} \
51+
../components/executors/
52+
minor:
53+
- name: "sg ops (base)"
54+
cmd: |
55+
set -eu
56+
sg ops update-images \
57+
--kind k8s \
58+
--registry us-central1-docker.pkg.dev/sourcegraph-ci/rfc795-internal \
59+
--docker-username=$DOCKER_USERNAME \
60+
--docker-password=$DOCKER_PASSWORD \
61+
--pin-tag {{inputs.server.tag}} \
62+
../base/
63+
- name: "sg ops (executors)"
64+
cmd: |
65+
set -eu
66+
sg ops update-images \
67+
--kind k8s \
68+
--registry us-central1-docker.pkg.dev/sourcegraph-ci/rfc795-internal \
69+
--docker-username=$DOCKER_USERNAME \
70+
--docker-password=$DOCKER_PASSWORD \
71+
--pin-tag {{inputs.server.tag}} \
72+
../components/executors/
73+
major:
74+
- name: "sg ops (base)"
75+
cmd: |
76+
set -eu
77+
sg ops update-images \
78+
--kind k8s \
79+
--registry us-central1-docker.pkg.dev/sourcegraph-ci/rfc795-internal \
80+
--docker-username=$DOCKER_USERNAME \
81+
--docker-password=$DOCKER_PASSWORD \
82+
--pin-tag {{inputs.server.tag}} \
83+
../base/
84+
- name: "sg ops (executors)"
85+
cmd: |
86+
set -eu
87+
sg ops update-images \
88+
--kind k8s \
89+
--registry us-central1-docker.pkg.dev/sourcegraph-ci/rfc795-internal \
90+
--docker-username=$DOCKER_USERNAME \
91+
--docker-password=$DOCKER_PASSWORD \
92+
--pin-tag {{inputs.server.tag}} \
93+
../components/executors/
94+
finalize:
95+
steps:
96+
- name: 'Register on release registry'
97+
cmd: |
98+
echo "Registering internal deploy-sourcegraph-k8s {{version}} release on release registry"
99+
COMMIT_SHA=$(git rev-parse HEAD)
100+
body=$(wget --content-on-error -O- --header="Content-Type: application/json" --header="Authorization: ${RELEASE_REGISTRY_TOKEN}" --post-data '{
101+
"name": "k8s",
102+
"version": "{{version}}",
103+
"git_sha": "'${COMMIT_SHA}'"
104+
}' "https://releaseregistry.sourcegraph.com/v1/releases")
105+
exit_code=$?
106+
107+
if [ $exit_code != 0 ]; then
108+
echo "❌ Failed to create release in release registry, got:"
109+
echo "--- raw body ---"
110+
echo $body
111+
echo "--- raw body ---"
112+
exit $exit_code
113+
else
114+
echo "Release created, see:"
115+
echo $body | jq .web_url
116+
fi
117+
- name: "notifications"
118+
cmd: |
119+
set -eu
120+
121+
branch="internal/release-{{version}}"
122+
123+
# Post a comment on the PR.
124+
cat << EOF | gh pr comment "$branch" --body-file -
125+
- :green_circle: Internal release is ready for promotion!
126+
- :warning: Do not close/merge the pull request or delete the associated branch if you intend to promote it.
127+
EOF
128+
# Post an annotation.
129+
cat << EOF | buildkite-agent annotate --style info
130+
Internal release is ready for promotion under the branch [\`$branch\`](https://github.com/sourcegraph/deploy-sourcegraph-k8s/tree/$branch).
131+
EOF
132+
133+
test:
134+
steps:
135+
- name: "placeholder"
136+
cmd: |
137+
echo "-- pretending to test release ..."
138+
139+
promoteToPublic:
140+
create:
141+
steps:
142+
# TODO: anish
143+
# this is probably going to be a problem...
144+
# we don't have .git file access on batch changes
145+
- name: "git"
146+
cmd: |
147+
set -eu
148+
branch="internal/release-{{version}}"
149+
echo "Checking out origin/${branch}"
150+
git fetch origin "${branch}"
151+
git switch "${branch}"
152+
- name: "sg ops"
153+
cmd: |
154+
set -eu
155+
sg ops update-images \
156+
--kind k8s \
157+
--registry index.docker.io/sourcegraph \
158+
--docker-username=$DOCKER_USERNAME \
159+
--docker-password=$DOCKER_PASSWORD \
160+
--pin-tag {{inputs.server.tag}} \
161+
../base/
162+
- name: "sg ops (executors)"
163+
cmd: |
164+
set -eu
165+
sg ops update-images \
166+
--kind k8s \
167+
--registry index.docker.io/sourcegraph \
168+
--docker-username=$DOCKER_USERNAME \
169+
--docker-password=$DOCKER_PASSWORD \
170+
--pin-tag {{inputs.server.tag}} \
171+
../components/executors/
172+
finalize:
173+
steps:
174+
# - name: 'validate promotion criteria'
175+
# cmd: |
176+
# echo "validating promotion criteria"
177+
# body=$(wget --content-on-error -O- --header="Content-Type: application/json" "https://releaseregistry.sourcegraph.com/v1/releases/k8s/{{version}}")
178+
# exit_code=$?
179+
180+
# if [ $exit_code != 0 ]; then
181+
# echo "❌ Failed to fetch release on release registry, got:"
182+
# echo "--- raw body ---"
183+
# echo $body
184+
# echo "--- raw body ---"
185+
# exit $exit_code
186+
# fi
187+
188+
# is_development=$(echo "$body" | jq -r '.is_development')
189+
# if [ "$is_development" = "true" ]; then
190+
# echo "cannot promote a development release"
191+
# exit 1
192+
# fi
193+
- name: git:tag
194+
cmd: |
195+
set -eu
196+
197+
# Branches
198+
internal_branch="internal/release-{{version}}"
199+
promote_branch="promote/release-{{version}}"
200+
release_branch="release-{{version}}"
201+
202+
# Create the final branch holding the tagged commit
203+
git checkout "${promote_branch}"
204+
git switch -c "${release_branch}"
205+
git tag {{version}}
206+
git push origin ${release_branch} --tags
207+
208+
# Web URL to the tag
209+
tag_url="https://github.com/sourcegraph/deploy-sourcegraph-k8s/tree/{{version}}"
210+
211+
# Annotate PRs
212+
cat << EOF | gh pr comment "$internal_branch" --body-file -
213+
- :green_circle: Release has been promoted, see tag: $tag_url.
214+
- :no_entry: Do not under any circumstance delete the branch holding the tagged commit (i.e. \`$release_branch\`).
215+
- :arrow_right: You can safely close the PR and delete its a associated branch.
216+
EOF
217+
218+
cat << EOF | gh pr comment "$promote_branch" --body-file -
219+
- :green_circle: Release has been promoted, see tag: $tag_url.
220+
- :no_entry: Do not under any circumstance delete the branch holding the tagged commit (i.e. \`$release_branch\`).
221+
- :arrow_right: You can safely close that PR and delete its a associated branch.
222+
EOF
223+
224+
# Annotate build
225+
cat << EOF | buildkite-agent annotate --style info
226+
Promoted release is **publicly available** through a git tag at [\`{{version}}\`](https://github.com/sourcegraph/deploy-sourcegraph-k8s/tree/{{version}}).
227+
EOF
228+
229+
- name: 'Promote on release registry'
230+
cmd: |
231+
echo "Promoting deploy-sourcegraph-k8s {{version}} release on release registry"
232+
body=$(wget --content-on-error -O- --header="Content-Type: application/json" --header="Authorization: ${RELEASE_REGISTRY_TOKEN}" --post-data '' "https://releaseregistry.sourcegraph.com/v1/releases/k8s/{{version}}/promote")
233+
exit_code=$?
234+
235+
if [ $exit_code != 0 ]; then
236+
echo "❌ Failed to promote release on release registry, got:"
237+
echo "--- raw body ---"
238+
echo $body
239+
echo "--- raw body ---"
240+
exit $exit_code
241+
else
242+
echo "Build created, see:"
243+
echo $body | jq .web_url
244+
fi
245+
246+
- name: "update main with latest version"
247+
cmd: |
248+
set -eu
249+
branch="promote/release-{{version}}-update-main"
250+
echo "Checking out origin/main"
251+
git fetch origin main
252+
git switch main
253+
echo "Creating branch origin/${branch}"
254+
git switch -c "${branch}"
255+
256+
- name: "sg ops"
257+
cmd: |
258+
set -eu
259+
sg ops update-images \
260+
--kind k8s \
261+
--registry index.docker.io/sourcegraph \
262+
--docker-username=$DOCKER_USERNAME \
263+
--docker-password=$DOCKER_PASSWORD \
264+
--pin-tag {{inputs.server.tag}} \
265+
../base/
266+
267+
- name: "sg ops (executors)"
268+
cmd: |
269+
set -eu
270+
sg ops update-images \
271+
--kind k8s \
272+
--registry index.docker.io/sourcegraph \
273+
--docker-username=$DOCKER_USERNAME \
274+
--docker-password=$DOCKER_PASSWORD \
275+
--pin-tag {{inputs.server.tag}} \
276+
../components/executors/
277+
278+
- name: "git:commit"
279+
cmd: |
280+
set -eu
281+
branch="promote/release-{{version}}-update-main"
282+
find . -name "*.yaml" | xargs git add
283+
find . -name "*.yml" | xargs git add
284+
285+
# Careful with the quoting for the config, using double quotes will lead
286+
# to the shell dropping out all quotes from the json, leading to failed
287+
# parsing.
288+
git commit -am 'update-main: {{version}}' -m 'update main with latest release'
289+
git push origin "${branch}"
290+
291+
- name: "github:pr"
292+
cmd: |
293+
set -eu
294+
internal_branch="promote/release-{{version}}-update-main"
295+
gh pr create \
296+
--fill \
297+
--draft \
298+
--base "$internal_branch" \
299+
--title "Update main: build {{version}}" \
300+
--body "Test plan: automated release PR, CI will perform additional checks"
301+
echo "🚢 Please check the associated CI build to ensure the process completed".
302+

0 commit comments

Comments
 (0)