Skip to content

Commit dd7afe0

Browse files
authored
Automated release workflow (open-telemetry#1580)
1 parent e23dd5c commit dd7afe0

13 files changed

+740
-129
lines changed

Diff for: .github/scripts/update-version.sh

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash -e
2+
3+
sed -i "/\[stable\]/{n;s/version=.*/version=$1/}" eachdist.ini
4+
sed -i "/\[prerelease\]/{n;s/version=.*/version=$2/}" eachdist.ini
5+
6+
./scripts/eachdist.py update_versions --versions stable,prerelease

Diff for: .github/scripts/use-cla-approved-github-bot.sh

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash -e
2+
3+
git config user.name opentelemetrybot
4+
git config user.email [email protected]

Diff for: .github/workflows/backport.yml

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Backport
2+
on:
3+
workflow_dispatch:
4+
inputs:
5+
number:
6+
description: "The pull request # to backport"
7+
required: true
8+
9+
jobs:
10+
backport:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- run: |
14+
if [[ ! $GITHUB_REF_NAME =~ ^release/v[0-9]+\.[0-9]+\.x-0\.[0-9]+bx$ ]]; then
15+
echo this workflow should only be run against long-term release branches
16+
exit 1
17+
fi
18+
19+
- uses: actions/checkout@v3
20+
with:
21+
# history is needed to run git cherry-pick below
22+
fetch-depth: 0
23+
24+
- name: Use CLA approved github bot
25+
run: .github/scripts/use-cla-approved-github-bot.sh
26+
27+
- name: Create pull request
28+
env:
29+
NUMBER: ${{ github.event.inputs.number }}
30+
# not using secrets.GITHUB_TOKEN since pull requests from that token do not run workflows
31+
GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }}
32+
run: |
33+
commit=$(gh pr view $NUMBER --json mergeCommit --jq .mergeCommit.oid)
34+
title=$(gh pr view $NUMBER --json title --jq .title)
35+
36+
branch="opentelemetrybot/backport-${NUMBER}-to-${GITHUB_REF_NAME//\//-}"
37+
38+
git cherry-pick $commit
39+
git push origin HEAD:$branch
40+
gh pr create --title "[$GITHUB_REF_NAME] $title" \
41+
--body "Clean cherry-pick of #$NUMBER to the \`$GITHUB_REF_NAME\` branch." \
42+
--head $branch \
43+
--base $GITHUB_REF_NAME

Diff for: .github/workflows/changelog.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ on:
1313
jobs:
1414
changelog:
1515
runs-on: ubuntu-latest
16-
if: "!contains(github.event.pull_request.labels.*.name, 'Skip Changelog')"
16+
if: |
17+
!contains(github.event.pull_request.labels.*.name, 'Skip Changelog')
18+
&& github.actor != 'opentelemetrybot'
1719
1820
steps:
1921
- uses: actions/checkout@v2

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

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: Prepare patch release
2+
on:
3+
workflow_dispatch:
4+
5+
jobs:
6+
prepare-patch-release:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v3
10+
11+
- run: |
12+
if [[ ! $GITHUB_REF_NAME =~ ^release/v[0-9]+\.[0-9]+\.x-0\.[0-9]+bx$ ]]; then
13+
echo this workflow should only be run against long-term 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+
22+
- name: Set environment variables
23+
run: |
24+
stable_version=$(./scripts/eachdist.py version --mode stable)
25+
unstable_version=$(./scripts/eachdist.py version --mode prerelease)
26+
27+
if [[ $stable_version =~ ^([0-9]+\.[0-9]+)\.([0-9]+)$ ]]; then
28+
stable_major_minor="${BASH_REMATCH[1]}"
29+
stable_patch="${BASH_REMATCH[2]}"
30+
else
31+
echo "unexpected stable_version: $stable_version"
32+
exit 1
33+
fi
34+
35+
if [[ $unstable_version =~ ^0\.([0-9]+)b([0-9]+)$ ]]; then
36+
unstable_minor="${BASH_REMATCH[1]}"
37+
unstable_patch="${BASH_REMATCH[2]}"
38+
else
39+
echo "unexpected unstable_version: $unstable_version"
40+
exit 1
41+
fi
42+
43+
stable_version="$stable_major_minor.$((stable_patch + 1))"
44+
unstable_version="0.${unstable_minor}b$((unstable_patch + 1))"
45+
46+
echo "STABLE_VERSION=$stable_version" >> $GITHUB_ENV
47+
echo "UNSTABLE_VERSION=$unstable_version" >> $GITHUB_ENV
48+
49+
- name: Update version
50+
run: .github/scripts/update-version.sh $STABLE_VERSION $UNSTABLE_VERSION
51+
52+
- name: Set up Python 3.9
53+
uses: actions/setup-python@v2
54+
with:
55+
python-version: 3.9
56+
- name: Install tox
57+
run: pip install tox==3.27.1
58+
- name: run tox
59+
run: tox -e generate
60+
61+
- name: Update the change log with the approximate release date
62+
run: |
63+
date=$(date "+%Y-%m-%d")
64+
sed -Ei "s/^## Unreleased$/## Version ${STABLE_VERSION}\/${UNSTABLE_VERSION} ($date)/" CHANGELOG.md
65+
66+
- name: Use CLA approved github bot
67+
run: .github/scripts/use-cla-approved-github-bot.sh
68+
69+
- name: Create pull request
70+
env:
71+
# not using secrets.GITHUB_TOKEN since pull requests from that token do not run workflows
72+
GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }}
73+
run: |
74+
message="Prepare release ${STABLE_VERSION}/${UNSTABLE_VERSION}"
75+
branch="opentelemetrybot/prepare-release-${STABLE_VERSION}-${UNSTABLE_VERSION}"
76+
77+
git commit -a -m "$message"
78+
git push origin HEAD:$branch
79+
gh pr create --title "[$GITHUB_REF_NAME] $message" \
80+
--body "$message." \
81+
--head $branch \
82+
--base $GITHUB_REF_NAME

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

+195
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
name: Prepare release branch
2+
on:
3+
workflow_dispatch:
4+
inputs:
5+
prerelease_version:
6+
description: "Pre-release version number? (e.g. 1.9.0rc2)"
7+
required: false
8+
9+
jobs:
10+
prereqs:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v3
14+
15+
- name: Verify prerequisites
16+
env:
17+
PRERELEASE_VERSION: ${{ github.event.inputs.prerelease_version }}
18+
run: |
19+
if [[ $GITHUB_REF_NAME != main ]]; then
20+
echo this workflow should only be run against main
21+
exit 1
22+
fi
23+
24+
if ! grep --quiet "^## Unreleased$" CHANGELOG.md; then
25+
echo the change log is missing an \"Unreleased\" section
26+
exit 1
27+
fi
28+
29+
if [[ ! -z $PRERELEASE_VERSION ]]; then
30+
stable_version=$(./scripts/eachdist.py version --mode stable)
31+
stable_version=${stable_version//.dev/}
32+
if [[ $PRERELEASE_VERSION != ${stable_version}* ]]; then
33+
echo "$PRERELEASE_VERSION is not a prerelease for the version on main ($stable_version)"
34+
exit 1
35+
fi
36+
fi
37+
38+
create-pull-request-against-release-branch:
39+
runs-on: ubuntu-latest
40+
needs: prereqs
41+
steps:
42+
- uses: actions/checkout@v3
43+
44+
- name: Create release branch
45+
env:
46+
PRERELEASE_VERSION: ${{ github.event.inputs.prerelease_version }}
47+
run: |
48+
if [[ -z $PRERELEASE_VERSION ]]; then
49+
stable_version=$(./scripts/eachdist.py version --mode stable)
50+
stable_version=${stable_version//.dev/}
51+
else
52+
stable_version=$PRERELEASE_VERSION
53+
fi
54+
55+
unstable_version=$(./scripts/eachdist.py version --mode prerelease)
56+
unstable_version=${unstable_version//.dev/}
57+
58+
if [[ $stable_version =~ ^([0-9]+)\.([0-9]+)\.0$ ]]; then
59+
stable_version_branch_part=$(echo $stable_version | sed -E 's/([0-9]+)\.([0-9]+)\.0/\1.\2.x/')
60+
unstable_version_branch_part=$(echo $unstable_version | sed -E 's/0\.([0-9]+)b0/0.\1bx/')
61+
release_branch_name="release/v${stable_version_branch_part}-${unstable_version_branch_part}"
62+
elif [[ $stable_version =~ ^([0-9]+)\.([0-9]+)\.0 ]]; then
63+
# pre-release version, e.g. 1.9.0rc2
64+
release_branch_name="release/v$stable_version-$unstable_version"
65+
else
66+
echo "unexpected version: $stable_version"
67+
exit 1
68+
fi
69+
70+
git push origin HEAD:$release_branch_name
71+
72+
echo "STABLE_VERSION=$stable_version" >> $GITHUB_ENV
73+
echo "UNSTABLE_VERSION=$unstable_version" >> $GITHUB_ENV
74+
echo "RELEASE_BRANCH_NAME=$release_branch_name" >> $GITHUB_ENV
75+
76+
- name: Update version
77+
run: .github/scripts/update-version.sh $STABLE_VERSION $UNSTABLE_VERSION
78+
79+
- name: Set up Python 3.9
80+
uses: actions/setup-python@v2
81+
with:
82+
python-version: 3.9
83+
- name: Install tox
84+
run: pip install tox==3.27.1
85+
- name: run tox
86+
run: tox -e generate
87+
88+
- name: Update the change log with the approximate release date
89+
run: |
90+
date=$(date "+%Y-%m-%d")
91+
sed -Ei "s/^## Unreleased$/## Version ${STABLE_VERSION}\/${UNSTABLE_VERSION} ($date)/" CHANGELOG.md
92+
93+
- name: Use CLA approved github bot
94+
run: .github/scripts/use-cla-approved-github-bot.sh
95+
96+
- name: Create pull request against the release branch
97+
env:
98+
# not using secrets.GITHUB_TOKEN since pull requests from that token do not run workflows
99+
GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }}
100+
run: |
101+
message="Prepare release ${STABLE_VERSION}/${UNSTABLE_VERSION}"
102+
branch="opentelemetrybot/prepare-release-${STABLE_VERSION}-${UNSTABLE_VERSION}"
103+
104+
git commit -a -m "$message"
105+
git push origin HEAD:$branch
106+
gh pr create --title "[$RELEASE_BRANCH_NAME] $message" \
107+
--body "$message." \
108+
--head $branch \
109+
--base $RELEASE_BRANCH_NAME
110+
111+
create-pull-request-against-main:
112+
runs-on: ubuntu-latest
113+
needs: prereqs
114+
steps:
115+
- uses: actions/checkout@v3
116+
117+
- name: Set environment variables
118+
env:
119+
PRERELEASE_VERSION: ${{ github.event.inputs.prerelease_version }}
120+
run: |
121+
if [[ -z $PRERELEASE_VERSION ]]; then
122+
stable_version=$(./scripts/eachdist.py version --mode stable)
123+
stable_version=${stable_version//.dev/}
124+
else
125+
stable_version=$PRERELEASE_VERSION
126+
fi
127+
128+
unstable_version=$(./scripts/eachdist.py version --mode prerelease)
129+
unstable_version=${unstable_version//.dev/}
130+
131+
if [[ $stable_version =~ ^([0-9]+)\.([0-9]+)\.0$ ]]; then
132+
stable_major="${BASH_REMATCH[1]}"
133+
stable_minor="${BASH_REMATCH[2]}"
134+
stable_next_version="$stable_major.$((stable_minor + 1)).0"
135+
elif [[ $stable_version =~ ^([0-9]+)\.([0-9]+)\.0 ]]; then
136+
# pre-release version, e.g. 1.9.0rc2
137+
stable_major="${BASH_REMATCH[1]}"
138+
stable_minor="${BASH_REMATCH[2]}"
139+
stable_next_version="$stable_major.$stable_minor.0"
140+
else
141+
echo "unexpected stable_version: $stable_version"
142+
exit 1
143+
fi
144+
145+
if [[ $unstable_version =~ ^0\.([0-9]+)b[0-9]+$ ]]; then
146+
unstable_minor="${BASH_REMATCH[1]}"
147+
else
148+
echo "unexpected unstable_version: $unstable_version"
149+
exit 1
150+
fi
151+
152+
unstable_next_version="0.$((unstable_minor + 1))b0"
153+
154+
echo "STABLE_VERSION=${stable_version}" >> $GITHUB_ENV
155+
echo "STABLE_NEXT_VERSION=${stable_next_version}.dev" >> $GITHUB_ENV
156+
157+
echo "UNSTABLE_VERSION=${unstable_version}" >> $GITHUB_ENV
158+
echo "UNSTABLE_NEXT_VERSION=${unstable_next_version}.dev" >> $GITHUB_ENV
159+
160+
- name: Update version
161+
run: .github/scripts/update-version.sh $STABLE_NEXT_VERSION $UNSTABLE_NEXT_VERSION
162+
163+
- name: Set up Python 3.9
164+
uses: actions/setup-python@v2
165+
with:
166+
python-version: 3.9
167+
- name: Install tox
168+
run: pip install tox==3.27.1
169+
- name: run tox
170+
run: tox -e generate
171+
172+
- name: Update the change log on main
173+
run: |
174+
# the actual release date on main will be updated at the end of the release workflow
175+
date=$(date "+%Y-%m-%d")
176+
sed -Ei "s/^## Unreleased$/## Unreleased\n\n## Version ${STABLE_VERSION}\/${UNSTABLE_VERSION} ($date)/" CHANGELOG.md
177+
178+
- name: Use CLA approved github bot
179+
run: .github/scripts/use-cla-approved-github-bot.sh
180+
181+
- name: Create pull request against main
182+
env:
183+
# not using secrets.GITHUB_TOKEN since pull requests from that token do not run workflows
184+
GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }}
185+
run: |
186+
message="Update version to ${STABLE_NEXT_VERSION}/${UNSTABLE_NEXT_VERSION}"
187+
body="Update version to \`${STABLE_NEXT_VERSION}/${UNSTABLE_NEXT_VERSION}\`."
188+
branch="opentelemetrybot/update-version-to-${STABLE_NEXT_VERSION}-${UNSTABLE_NEXT_VERSION}"
189+
190+
git commit -a -m "$message"
191+
git push origin HEAD:$branch
192+
gh pr create --title "$message" \
193+
--body "$body" \
194+
--head $branch \
195+
--base main

Diff for: .github/workflows/publish.yml

-37
This file was deleted.

0 commit comments

Comments
 (0)