Skip to content

Commit 560438c

Browse files
alrexmauriciovasquezbernal
authored andcommitted
Adding script and workflow to automate the preparation of releases (open-telemetry#615)
The prepare-release workflow is triggered when a new release/<version> branch is created. This workflow parses the <version> number from the branch name and updates version.py/changelog.md files accordingly. It then creates a pull request with those changes. This addresses part of open-telemetry#374. Co-authored-by: Mauricio Vásquez <[email protected]>
1 parent 2863846 commit 560438c

File tree

2 files changed

+107
-0
lines changed

2 files changed

+107
-0
lines changed

Diff for: .github/workflows/prepare-release.yml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: prepare-release
2+
on:
3+
push:
4+
branch: [ 'release/*' ]
5+
6+
jobs:
7+
build:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v2
11+
12+
- name: Get the version
13+
id: get_version
14+
run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//}
15+
16+
- name: Prepare the release
17+
id: update
18+
run: |
19+
./scripts/prepare_release.sh ${{ steps.get_version.outputs.VERSION }}
20+
21+
- name: Create Pull Request
22+
id: create-pr
23+
uses: peter-evans/[email protected]
24+
with:
25+
branch: ${{ steps.get_version.outputs.VERSION }}-auto
26+
title: '[pre-release] Update changelogs, version [${{ steps.get_version.outputs.VERSION }}]'
27+
if: ${{ steps.update.outputs.version_updated == 1 }}

Diff for: scripts/prepare_release.sh

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/bin/bash
2+
#
3+
# This script:
4+
# 1. parses the version number from the branch name
5+
# 2. updates version.py files to match that version
6+
# 3. iterates through CHANGELOG.md files and updates any files containing
7+
# unreleased changes
8+
# 4. sets the output variable 'version_updated' to determine whether
9+
# the github action to create a pull request should run. this allows
10+
# maintainers to merge changes back into the release branch without
11+
# triggering unnecessary pull requests
12+
#
13+
14+
VERSION=`echo $1 | awk -F "/" '{print $NF}'`
15+
echo "Using version ${VERSION}"
16+
17+
# check the version matches expected versioning e.g
18+
# 0.6, 0.6b, 0.6b0, 0.6.0
19+
if [[ ! "${VERSION}" =~ ^([0-9])(\.*[0-9]{1,5}[a-b]*){1,3}$ ]]; then
20+
echo "Version number invalid: $VERSION"
21+
exit 1
22+
fi
23+
24+
function update_version_file() {
25+
errors=0
26+
for f in `find . -name version.py`; do
27+
# check if version is already in version.py
28+
grep -q ${VERSION} $f;
29+
rc=$?
30+
if [ $rc == 0 ]; then
31+
errors=1
32+
echo "${f} already contains ${VERSION}"
33+
continue
34+
fi
35+
# update version.py
36+
perl -i -pe "s/__version__.*/__version__ = \"${VERSION}\"/g" ${f};
37+
git add ${f};
38+
echo "Updating ${f}"
39+
done
40+
if [ ${errors} != 0 ]; then
41+
echo "::set-output name=version_updated::0"
42+
exit 0
43+
fi
44+
}
45+
46+
function update_changelog() {
47+
errors=0
48+
for f in `find . -name CHANGELOG.md`; do
49+
# check if version is already in CHANGELOG
50+
grep -q ${VERSION} $f;
51+
rc=$?
52+
if [ $rc == 0 ]; then
53+
errors=1
54+
echo "${f} already contains ${VERSION}"
55+
continue
56+
fi
57+
# check if changelog contains any new details
58+
changes=`sed -n '/## Unreleased/,/^##/p' ${f} | grep -v '^##' | wc -w | awk '{$1=$1;print}'`
59+
if [ ${changes} != "0" ]; then
60+
# update CHANGELOG.md
61+
perl -i -pe 's/## Unreleased.*/## Unreleased\n\n## '${VERSION}'/' ${f};
62+
git add ${f};
63+
echo "Updating ${f}"
64+
else
65+
echo "Skipping ${f}, no changes detected"
66+
fi
67+
done
68+
if [ ${errors} != 0 ]; then
69+
echo "::set-output name=version_updated::0"
70+
exit 0
71+
fi
72+
}
73+
74+
update_version_file
75+
update_changelog
76+
77+
git config --local user.email "[email protected]"
78+
git config --local user.name "GitHub Action"
79+
git commit -m "updating changelogs and version to ${VERSION}"
80+
echo "::set-output name=version_updated::1"

0 commit comments

Comments
 (0)