Skip to content

Commit 310a88e

Browse files
committed
Add workflow to update getting started guide
This change adds an automated workflow to open a pull request to update the version in the getting started guide when a release is made. Signed-off-by: Austin Vazquez <[email protected]>
1 parent 7ead0be commit 310a88e

File tree

2 files changed

+152
-0
lines changed

2 files changed

+152
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: Update getting started guide
2+
3+
on:
4+
release:
5+
types: ['released']
6+
pull_request:
7+
branches: ['main', 'release/**']
8+
paths:
9+
# Run workflow on changes to the workflow definition itself to spot check
10+
# the core version update functionality.
11+
- '.github/workflows/update-getting-started-guide.yml'
12+
- 'scripts/update-getting-started-guide-version.sh'
13+
# Run workflow on changes to the getting started guide to validate
14+
# changes to the documentation do not break the update workflow.
15+
- 'docs/getting-started.md'
16+
17+
jobs:
18+
test-update-version:
19+
if: github.event_name == 'pull_request'
20+
runs-on: ubuntu-20.04
21+
22+
permissions:
23+
contents: read
24+
pull-requests: read
25+
26+
env:
27+
RELEASE_TAG: ''
28+
29+
steps:
30+
- uses: actions/checkout@v4
31+
with:
32+
sparse-checkout: |
33+
docs/getting-started.md
34+
scripts/update-getting-started-guide-version.sh
35+
36+
- name: Mock release tag on pull request
37+
run: echo "RELEASE_TAG=v0.0.0-${{ github.event.pull_request.number }}" >> $GITHUB_ENV
38+
39+
- name: Test update getting started version
40+
run: bash scripts/update-getting-started-guide-version.sh --assert ${{ env.RELEASE_TAG }}
41+
42+
update-version:
43+
if: github.event_name == 'release'
44+
runs-on: ubuntu-20.04
45+
46+
permissions:
47+
# Write permissions needed to create pull request.
48+
# Risk is mitigated by seperating jobs such that workflows
49+
# running with write permissions only use code from main.
50+
contents: write
51+
pull-requests: write
52+
53+
steps:
54+
- uses: actions/checkout@v4
55+
with:
56+
ref: main
57+
sparse-checkout: |
58+
docs/getting-started.md
59+
scripts/update-getting-started-guide-version.sh
60+
61+
- name: Update getting started version
62+
run: bash scripts/update-getting-started-guide-version.sh --verbose ${{ github.event.release.tag_name }}
63+
64+
- name: Create PR
65+
uses: peter-evans/create-pull-request@v6
66+
with:
67+
title: 'Update getting started to ${{ github.event.release.tag_name }}'
68+
commit-message: 'Update getting started to ${{ github.event.release.tag_name }}'
69+
body: |
70+
This PR must be closed and reopened manually to trigger automated checks.
71+
72+
Auto-generated by [create-pull-request](https://github.com/peter-evans/create-pull-request).
73+
labels: easy-to-review, automated-pr
74+
token: ${{ secrets.GITHUB_TOKEN }}
75+
author: "GitHub <[email protected]>"
76+
signoff: true
77+
branch: 'create-pull-request/update-getting-started-version-to-${{ github.event.release.tag_name }}'
78+
base: main
79+
delete-branch: true
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright The Soci Snapshotter Authors.
4+
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# A script to assert version in the getting started guide was updated
18+
# correctly by GitHub Actions workflow.
19+
#
20+
# Usage: bash update-getting-started-guide-version.sh [-a|--assert] [-v|--verbose] <RELEASE_TAG>
21+
22+
set -eux -o pipefail
23+
24+
tag=$1
25+
26+
ASSERT=false
27+
VERBOSE=false
28+
29+
while [[ $# -gt 0 ]]; do
30+
case $1 in
31+
--assert|-a)
32+
ASSERT=true
33+
shift # past argument
34+
;;
35+
--verbose|-v)
36+
VERBOSE=true
37+
shift # past argument
38+
;;
39+
--*|-*)
40+
echo "Unknown option $1"
41+
exit 1
42+
;;
43+
*)
44+
tag=$1
45+
shift # past argument
46+
;;
47+
esac
48+
done
49+
50+
# Strip 'v' prefix from tag if not already stripped.
51+
VERSION=${tag/v/}
52+
53+
assert_diff() {
54+
local diff_output
55+
# Disable warning for A && B || C is not if-then-else; C may run when A is true.
56+
# Branch B contains exit, so C will not run when A and B branches fail.
57+
# This is intended to have the assertion fail if the diff is empty.
58+
# shellcheck disable=SC2015
59+
diff_output=$(git diff --exit-code) && {
60+
echo "Error: no changes made; expected getting started version to be updated to \"${VERSION}\"" && exit 1
61+
} || {
62+
if [[ "${diff_output}" == *"+version=\"${VERSION}\""* ]]; then
63+
echo "Diff looks good!"
64+
else
65+
echo "Error: release version not set properly" && exit 1
66+
fi
67+
}
68+
}
69+
70+
sed -i -E "s/version=\"([0-9]+\.){2}[0-9]+\"/version=\"${VERSION}\"/" docs/getting-started.md
71+
72+
[ $VERBOSE = true ] && git diff
73+
[ $ASSERT = true ] && assert_diff

0 commit comments

Comments
 (0)