-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add release automation to update getting started guide
This change adds release automation to open a pull request to update the version in the getting started guide when a release is released. Signed-off-by: Austin Vazquez <[email protected]>
- Loading branch information
1 parent
d25a2ea
commit a5ee004
Showing
2 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
name: Update getting started guide | ||
|
||
on: | ||
release: | ||
types: ['released'] | ||
pull_request: | ||
branches: ['main', 'release/**'] | ||
paths: | ||
# Run workflow on changes to the workflow definition itself to spot check | ||
# the core release version update functionality. | ||
- '.github/workflows/update-getting-started-guide.yml' | ||
# Run workflow on changes to the getting started guide to verify if any | ||
# changes to the documentation do not break the update automation. | ||
- 'docs/getting-started.md' | ||
|
||
permissions: | ||
pull-requests: write | ||
|
||
jobs: | ||
update-version: | ||
runs-on: ubuntu-20.04 | ||
env: | ||
RELEASE_TAG: '' | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Mock release tag on pull request | ||
if: github.event_name == 'pull_request' | ||
run: echo "RELEASE_TAG=v0.0.0-${{ github.event.pull_request.number }}" >> $GITHUB_ENV | ||
|
||
- name: Set published release tag | ||
if: github.event_name == 'release' | ||
run: echo "RELEASE_TAG=${{ github.event.release.tag_name }}" >> $GITHUB_ENV | ||
|
||
- name: Update getting started version | ||
run: | | ||
release_tag=${{ env.RELEASE_TAG }} | ||
release_version=${release_tag/v/} | ||
sed -i -E "s/version=\"([0-9]+\.){2}[0-9]+\"/version=\"${release_version}\"/" docs/getting-started.md | ||
- name: Assert version was updated correctly | ||
if: github.event_name == 'pull_request' | ||
run: bash scripts/assert-getting-started-guide-version-diff.sh ${{ env.RELEASE_TAG }} | ||
|
||
- name: Create PR | ||
if: github.event_name == 'release' | ||
uses: peter-evans/create-pull-request@v6 | ||
with: | ||
title: 'Update getting started to ${{ github.event.release.tag_name }}' | ||
commit-message: 'Update getting started to ${{ github.event.release.tag_name }}' | ||
body: | | ||
This PR must be closed and reopened manually to trigger automated checks. | ||
Auto-generated by [create-pull-request](https://github.com/peter-evans/create-pull-request). | ||
labels: easy-to-review, automated-pr | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
author: "GitHub <[email protected]>" | ||
signoff: true | ||
branch: 'create-pull-request/update-getting-started-version-to-${{ github.event.release.tag_name }}' | ||
base: main | ||
delete-branch: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Copyright The Soci Snapshotter Authors. | ||
|
||
# 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. | ||
|
||
# A script to assert version in the getting started guide was updated | ||
# correctly by GitHub Actions workflow. | ||
# | ||
# Usage: bash assert-getting-started-guide-version-diff.sh <RELEASE_TAG> | ||
|
||
set -eux -o pipefail | ||
|
||
release_tag=$1 | ||
|
||
# Strip 'v' prefix from tag if not already stripped. | ||
release_version=${release_tag/v/} | ||
|
||
# Disable warning for A && B || C is not if-then-else; C may run when A is true. | ||
# Branch B contains exit, so C will not run when A and B branches fail. | ||
# This is intended to have the assertion fail if the diff is empty. | ||
# shellcheck disable=SC2015 | ||
diff_output=$(git diff --exit-code) && { | ||
echo "Error: no changes made; expected getting started version to be updated to \"${release_version}\"" && exit 1 | ||
} || { | ||
echo "${diff_output}" | ||
if [[ "${diff_output}" =~ "+version=\"${release_version}\"" ]]; then | ||
echo "Diff looks good!" | ||
else | ||
echo "Error: release version not set properly" && exit 1 | ||
fi | ||
} |