Skip to content

Commit a68ce4e

Browse files
authored
Release workflow simplifications (open-telemetry#4534)
* Release workflow simplifications * sync * Fix
1 parent d2e6b55 commit a68ce4e

File tree

6 files changed

+174
-97
lines changed

6 files changed

+174
-97
lines changed

.github/workflows/backport.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ jobs:
1010
backport:
1111
runs-on: ubuntu-latest
1212
steps:
13+
- run: |
14+
if [[ ! $GITHUB_REF_NAME =~ ^release/v[0-9]+\.[0-9]+\.x$ ]]; then
15+
echo this workflow should only be run against release branches
16+
exit 1
17+
fi
18+
1319
- uses: actions/checkout@v3
1420
with:
1521
# history is needed to run git cherry-pick below
@@ -21,12 +27,11 @@ jobs:
2127
- name: Create pull request
2228
env:
2329
NUMBER: ${{ github.event.inputs.number }}
24-
# not using the default GITHUB_TOKEN because pull requests generated by it do not run any workflows
30+
# not using secrets.GITHUB_TOKEN since pull requests from that token do not run workflows
2531
GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }}
2632
run: |
2733
commit=$(gh pr view $NUMBER --json mergeCommit --jq .mergeCommit.oid)
2834
title=$(gh pr view $NUMBER --json title --jq .title)
29-
url=$(gh pr view $NUMBER --json url --jq .url)
3035
3136
branch="backport-${NUMBER}-to-${GITHUB_REF_NAME//\//-}"
3237

.github/workflows/merge-change-log-to-main.yml

Lines changed: 0 additions & 36 deletions
This file was deleted.

.github/workflows/prepare-patch-release.yml

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,21 @@ jobs:
88
steps:
99
- uses: actions/checkout@v3
1010

11+
- run: |
12+
if [[ ! $GITHUB_REF_NAME =~ ^release/v[0-9]+\.[0-9]+\.x$ ]]; then
13+
echo this workflow should only be run against release branches
14+
exit 1
15+
fi
16+
17+
if ! grep --quiet "^## Unreleased$" CHANGELOG.md; then
18+
echo the change log is missing an \"Unreleased\" section
19+
exit 1
20+
fi
21+
1122
- name: Set environment variables
1223
run: |
1324
version=$(.github/scripts/get-version.sh)
14-
if [[ $version =~ ([0-9]+\.[0-9]+)\.([0-9]+) ]]; then
25+
if [[ $version =~ ^([0-9]+\.[0-9]+)\.([0-9]+)$ ]]; then
1526
major_minor="${BASH_REMATCH[1]}"
1627
patch="${BASH_REMATCH[2]}"
1728
else
@@ -21,15 +32,19 @@ jobs:
2132
echo "VERSION=$major_minor.$((patch + 1))" >> $GITHUB_ENV
2233
2334
- name: Update version
35+
run: sed -Ei "s/[0-9]+\.[0-9]+\.[0-9]+/$VERSION/" version.gradle.kts
36+
37+
- name: Update the change log with the approximate release date
2438
run: |
25-
sed -Ei "s/[0-9]+\.[0-9]+\.[0-9]+/$VERSION/" version.gradle.kts
39+
date=$(date "+%Y-%m-%d")
40+
sed -Ei "s/^## Unreleased$/## Version $VERSION ($date)/" CHANGELOG.md
2641
2742
- name: Set git user
2843
run: .github/scripts/set-git-user.sh
2944

3045
- name: Create pull request
3146
env:
32-
# not using the default GITHUB_TOKEN because pull requests generated by it do not run any workflows
47+
# not using secrets.GITHUB_TOKEN since pull requests from that token do not run workflows
3348
GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }}
3449
run: |
3550
message="Prepare release $VERSION"

.github/workflows/prepare-release-branch.yml

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,58 @@ on:
33
workflow_dispatch:
44

55
jobs:
6+
prereqs:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v3
10+
11+
- run: |
12+
if [[ $GITHUB_REF_NAME != main ]]; then
13+
echo this workflow should only be run against main
14+
exit 1
15+
fi
16+
17+
if ! grep --quiet "^## Unreleased$" CHANGELOG.md; then
18+
echo the change log is missing an \"Unreleased\" section
19+
exit 1
20+
fi
21+
622
create-pull-request-against-release-branch:
723
runs-on: ubuntu-latest
24+
needs: prereqs
825
steps:
926
- uses: actions/checkout@v3
1027

1128
- name: Create release branch
12-
id: create-release-branch
1329
run: |
1430
version=$(.github/scripts/get-version.sh)
1531
version=${version//-SNAPSHOT/}
16-
release_branch_name=$(echo $version | sed -E 's/([0-9]+)\.([0-9]+)\.0/release\/v\1.\2.x/')
32+
if [[ $version =~ ^([0-9]+)\.([0-9]+)\.0$ ]]; then
33+
release_branch_name=$(echo $version | sed -E 's/([0-9]+)\.([0-9]+)\.0/release\/v\1.\2.x/')
34+
else
35+
echo "unexpected version: $version"
36+
exit 1
37+
fi
1738
1839
git push origin HEAD:$release_branch_name
1940
2041
echo "VERSION=$version" >> $GITHUB_ENV
2142
echo "RELEASE_BRANCH_NAME=$release_branch_name" >> $GITHUB_ENV
2243
2344
- name: Update version
45+
run: sed -Ei "s/val snapshot = true/val snapshot = false/" version.gradle.kts
46+
47+
- name: Update the change log with the approximate release date
2448
run: |
25-
sed -Ei "s/val snapshot = true/val snapshot = false/" version.gradle.kts
49+
date=$(date "+%Y-%m-%d")
50+
sed -Ei "s/^## Unreleased$/## Version $VERSION ($date)/" CHANGELOG.md
2651
2752
- name: Set git user
2853
run: .github/scripts/set-git-user.sh
2954

3055
- name: Create pull request against the release branch
3156
env:
32-
# not using the default GITHUB_TOKEN because pull requests generated by it do not run any workflows
57+
# not using secrets.GITHUB_TOKEN since pull requests from that token do not run workflows
3358
GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }}
3459
run: |
3560
message="Prepare release $VERSION"
@@ -44,32 +69,39 @@ jobs:
4469
4570
create-pull-request-against-main:
4671
runs-on: ubuntu-latest
72+
needs: prereqs
4773
steps:
4874
- uses: actions/checkout@v3
4975

5076
- name: Set environment variables
5177
run: |
5278
version=$(.github/scripts/get-version.sh)
53-
if [[ $version =~ ([0-9]+)\.([0-9]+)\.0 ]]; then
79+
if [[ $version =~ ^([0-9]+)\.([0-9]+)\.0$ ]]; then
5480
major="${BASH_REMATCH[1]}"
5581
minor="${BASH_REMATCH[2]}"
82+
next_version="$major.$((minor + 1)).0"
5683
else
5784
echo "unexpected version: $version"
5885
exit 1
5986
fi
60-
next_version="$major.$((minor + 1)).0"
6187
echo "NEXT_VERSION=$next_version" >> $GITHUB_ENV
88+
echo "VERSION=$version" >> $GITHUB_ENV
6289
6390
- name: Update version
91+
run: sed -Ei "s/[0-9]+\.[0-9]+\.[0-9]+/$NEXT_VERSION/" version.gradle.kts
92+
93+
- name: Update the change log on main
6494
run: |
65-
sed -Ei "s/[0-9]+\.[0-9]+\.[0-9]+/$NEXT_VERSION/" version.gradle.kts
95+
# the actual release date on main will be updated at the end of the release workflow
96+
date=$(date "+%Y-%m-%d")
97+
sed -Ei "s/^## Unreleased$/## Unreleased\n\n## Version $VERSION ($date)/" CHANGELOG.md
6698
6799
- name: Set git user
68100
run: .github/scripts/set-git-user.sh
69101

70102
- name: Create pull request against main
71103
env:
72-
# not using the default GITHUB_TOKEN because pull requests generated by it do not run any workflows
104+
# not using secrets.GITHUB_TOKEN since pull requests from that token do not run workflows
73105
GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }}
74106
run: |
75107
message="Update version to $NEXT_VERSION"

.github/workflows/release.yml

Lines changed: 93 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
- name: Set environment variables
3636
run: |
3737
version=$(.github/scripts/get-version.sh)
38-
if [[ $version =~ ([0-9]+)\.([0-9]+)\.([0-9]+) ]]; then
38+
if [[ $version =~ ^([0-9]+)\.([0-9]+)\.([0-9]+) ]]; then
3939
major="${BASH_REMATCH[1]}"
4040
minor="${BASH_REMATCH[2]}"
4141
patch="${BASH_REMATCH[3]}"
@@ -57,39 +57,61 @@ jobs:
5757
echo "VERSION=$version" >> $GITHUB_ENV
5858
echo "PRIOR_VERSION=$prior_version" >> $GITHUB_ENV
5959
60+
# check out main branch to verify there won't be problems with merging the change log
61+
# at the end of this workflow
62+
- uses: actions/checkout@v3
63+
with:
64+
ref: main
65+
66+
- run: |
67+
if [[ $VERSION == *.0 ]]; then
68+
# not making a patch release
69+
if ! grep --quiet "^## Version $VERSION " CHANGELOG.md; then
70+
echo the pull request generated by prepare-release-branch.yml needs to be merged first
71+
exit 1
72+
fi
73+
fi
74+
75+
# back to the release branch
76+
- uses: actions/checkout@v3
77+
6078
- name: Generate release notes
6179
env:
6280
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6381
run: |
6482
# conditional blocks not indented because of the heredoc
6583
if [[ $VERSION == *.0 ]]; then
66-
cat > release-notes.txt << EOF
84+
cat > /tmp/release-notes.txt << EOF
6785
This release targets the OpenTelemetry SDK $VERSION.
6886
6987
EOF
7088
else
71-
cat > release-notes.txt << EOF
89+
cat > /tmp/release-notes.txt << EOF
7290
This is a patch release on the previous $PRIOR_VERSION release, fixing the issue(s) below.
7391
7492
EOF
7593
fi
7694
95+
# CHANGELOG_SECTION.md is also used at the end of the release workflow
96+
# for copying the change log updates to main
97+
sed -n "0,/^## Version $VERSION /d;/^## Version /q;p" CHANGELOG.md \
98+
> /tmp/CHANGELOG_SECTION.md
99+
77100
# the complex perl regex is needed because markdown docs render newlines as soft wraps
78101
# while release notes render them as line breaks
79-
sed -n "0,/^## Version $VERSION/d;/^## Version /q;p" CHANGELOG.md \
80-
| perl -0pe 's/(?<!\n)\n *(?!\n)(?![-*] )(?![1-9]+\. )/ /g' \
81-
>> release-notes.txt
102+
perl -0pe 's/(?<!\n)\n *(?!\n)(?![-*] )(?![1-9]+\. )/ /g' /tmp/CHANGELOG_SECTION.md \
103+
>> /tmp/release-notes.txt
82104
83105
# conditional block not indented because of the heredoc
84106
if [[ $VERSION == *.0 ]]; then
85-
cat >> release-notes.txt << EOF
107+
cat >> /tmp/release-notes.txt << EOF
86108
87109
### 🙇 Thank you
88110
This release was possible thanks to the following contributors who shared their brilliant ideas and awesome pull requests:
89111
90112
EOF
91113
92-
.github/scripts/generate-release-contributors.sh v$PRIOR_VERSION >> release-notes.txt
114+
.github/scripts/generate-release-contributors.sh v$PRIOR_VERSION >> /tmp/release-notes.txt
93115
fi
94116
95117
- name: Create GitHub release
@@ -98,31 +120,83 @@ jobs:
98120
run: |
99121
gh release create --target $GITHUB_REF_NAME \
100122
--title "Version $VERSION" \
101-
--notes-file release-notes.txt \
123+
--notes-file /tmp/release-notes.txt \
102124
--discussion-category announcements \
103125
v$VERSION
104126
105-
- name: Update the change log with the release date
127+
- uses: actions/checkout@v3
128+
with:
129+
# the step below is creating a pull request against main
130+
ref: main
131+
132+
- name: Copy change log updates to main
106133
env:
107134
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
108135
run: |
109-
date=$(gh release view v$VERSION --json publishedAt --jq .publishedAt | sed 's/T.*//')
110-
sed -Ei "s/## Version $VERSION .*/## Version $VERSION ($date)/" CHANGELOG.md
136+
if [[ $VERSION == *.0 ]]; then
137+
# this was not a patch release, so the version exists already in the CHANGELOG.md
138+
139+
# update the release date
140+
date=$(gh release view v$VERSION --json publishedAt --jq .publishedAt | sed 's/T.*//')
141+
sed -Ei "s/## Version $VERSION .*/## Version $VERSION ($date)/" CHANGELOG.md
142+
143+
# the entries are copied over from the release branch to support workflows
144+
# where change log entries may be updated after preparing the release branch
145+
146+
# copy the portion above the release, up to and including the heading
147+
sed -n "0,/^## Version $VERSION ($date)/p" CHANGELOG.md > /tmp/CHANGELOG.md
148+
149+
# copy the release notes
150+
cat /tmp/CHANGELOG_SECTION.md >> /tmp/CHANGELOG.md
151+
152+
# copy the portion below the release
153+
sed -n "0,/^## Version $VERSION /d;0,/^## Version /{/^## Version/!d};p" CHANGELOG.md \
154+
>> /tmp/CHANGELOG.md
155+
156+
# update the real CHANGELOG.md
157+
cp /tmp/CHANGELOG.md CHANGELOG.md
158+
else
159+
# this was a patch release, so the version does not exist already in the CHANGELOG.md
160+
161+
# copy the portion above the top-most release, not including the heading
162+
sed -n "0,/^## Version /{ /^## Version /!p }" CHANGELOG.md > /tmp/CHANGELOG.md
163+
164+
# add the heading
165+
date=$(gh release view v$VERSION --json publishedAt --jq .publishedAt | sed 's/T.*//')
166+
echo "## Version $VERSION ($date)" >> /tmp/CHANGELOG.md
167+
168+
# copy the release notes
169+
cat /tmp/CHANGELOG_SECTION.md >> /tmp/CHANGELOG.md
170+
171+
# copy the portion starting from the top-most release
172+
sed -n "/^## Version /,\$p" CHANGELOG.md >> /tmp/CHANGELOG.md
173+
174+
# update the real CHANGELOG.md
175+
cp /tmp/CHANGELOG.md CHANGELOG.md
176+
fi
111177
112178
- name: Set git user
113179
run: .github/scripts/set-git-user.sh
114180

115-
- name: Create pull request against the release branch
181+
- name: Create pull request against main
116182
env:
117-
# not using the default GITHUB_TOKEN because pull requests generated by it do not run any workflows
183+
# not using secrets.GITHUB_TOKEN since pull requests from that token do not run workflows
118184
GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }}
119185
run: |
120-
message="Add the release date for $VERSION to the change log"
121-
branch="add-release-date-for-${VERSION}"
186+
message="Copy change log updates from $GITHUB_REF_NAME"
187+
body="Copy log updates from \`$GITHUB_REF_NAME\`."
188+
branch="copy-change-log-updates-from-${GITHUB_REF_NAME//\//-}"
189+
190+
if [[ $VERSION == *.0 ]]; then
191+
if git diff --quiet; then
192+
echo there are no updates needed to the change log on main, not creating pull request
193+
exit 0 # success
194+
fi
195+
fi
122196
123197
git commit -a -m "$message"
124198
git push origin HEAD:$branch
125-
gh pr create --title "[$GITHUB_REF_NAME] $message" \
126-
--body "$message." \
199+
gh pr create --title "$message" \
200+
--body "$body" \
127201
--head $branch \
128-
--base $GITHUB_REF_NAME
202+
--base main

0 commit comments

Comments
 (0)