forked from open-telemetry/opentelemetry-python
-
Notifications
You must be signed in to change notification settings - Fork 0
131 lines (108 loc) · 4.89 KB
/
prepare-patch-release.yml
File metadata and controls
131 lines (108 loc) · 4.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
name: Prepare patch release
on:
workflow_dispatch:
permissions:
contents: read
jobs:
prepare-patch-release:
permissions:
contents: write # required for pushing changes
pull-requests: write # required for adding labels to PRs
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install dependencies
run: pip install toml towncrier
- run: |
if [[ ! $GITHUB_REF_NAME =~ ^release/v[0-9]+\.[0-9]+\.x-0\.[0-9]+bx$ ]]; then
echo this workflow should only be run against long-term release branches
exit 1
fi
- name: Set environment variables
run: |
stable_version=$(./scripts/eachdist.py version --mode stable)
unstable_version=$(./scripts/eachdist.py version --mode prerelease)
if [[ $stable_version =~ ^([0-9]+\.[0-9]+)\.([0-9]+)$ ]]; then
stable_major_minor="${BASH_REMATCH[1]}"
stable_patch="${BASH_REMATCH[2]}"
else
echo "unexpected stable_version: $stable_version"
exit 1
fi
if [[ $unstable_version =~ ^0\.([0-9]+)b([0-9]+)$ ]]; then
unstable_minor="${BASH_REMATCH[1]}"
unstable_patch="${BASH_REMATCH[2]}"
else
echo "unexpected unstable_version: $unstable_version"
exit 1
fi
stable_version_prev="$stable_major_minor.$((stable_patch))"
unstable_version_prev="0.${unstable_minor}b$((unstable_patch))"
stable_version="$stable_major_minor.$((stable_patch + 1))"
unstable_version="0.${unstable_minor}b$((unstable_patch + 1))"
echo "STABLE_VERSION=$stable_version" >> $GITHUB_ENV
echo "UNSTABLE_VERSION=$unstable_version" >> $GITHUB_ENV
echo "STABLE_VERSION_PREV=$stable_version_prev" >> $GITHUB_ENV
echo "UNSTABLE_VERSION_PREV=$unstable_version_prev" >> $GITHUB_ENV
- name: Update version
run: .github/scripts/update-version-patch.sh $STABLE_VERSION $UNSTABLE_VERSION $STABLE_VERSION_PREV $UNSTABLE_VERSION_PREV
- name: Generate changelog
run: towncrier build --yes --version "$STABLE_VERSION/$UNSTABLE_VERSION"
- name: Use CLA approved github bot
run: .github/scripts/use-cla-approved-github-bot.sh
- uses: actions/create-github-app-token@df432ceedc7162793a195dd1713ff69aefc7379e # v2.0.6
id: otelbot-token
with:
app-id: ${{ vars.OTELBOT_APP_ID }}
private-key: ${{ secrets.OTELBOT_PRIVATE_KEY }}
- name: Create pull request
id: create_pr
env:
# not using secrets.GITHUB_TOKEN since pull requests from that token do not run workflows
GITHUB_TOKEN: ${{ steps.otelbot-token.outputs.token }}
run: |
message="Prepare release ${STABLE_VERSION}/${UNSTABLE_VERSION}"
branch="otelbot/prepare-release-${STABLE_VERSION}-${UNSTABLE_VERSION}"
git commit -a -m "$message"
git push origin HEAD:$branch
pr_url=$(gh pr create --title "[$GITHUB_REF_NAME] $message" \
--body "$message." \
--head $branch \
--base $GITHUB_REF_NAME)
echo "pr_url=$pr_url" >> $GITHUB_OUTPUT
- name: Add prepare-release label to PR
if: steps.create_pr.outputs.pr_url != ''
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh pr edit ${{ steps.create_pr.outputs.pr_url }} --add-label "prepare-release"
- uses: actions/checkout@v4
with:
ref: main
- name: Use CLA approved github bot
run: .github/scripts/use-cla-approved-github-bot.sh
- name: Backport patch release changelog to main
id: backport_pr
env:
GITHUB_TOKEN: ${{ steps.otelbot-token.outputs.token }}
run: |
release_branch="otelbot/prepare-release-${STABLE_VERSION}-${UNSTABLE_VERSION}"
message="Backport ${STABLE_VERSION}/${UNSTABLE_VERSION} changelog"
body="Backport \`${STABLE_VERSION}/${UNSTABLE_VERSION}\` changelog"
branch="otelbot/backport-changelog-from-${STABLE_VERSION}-${UNSTABLE_VERSION}"
git fetch origin $release_branch
# Copy the updated CHANGELOG.md from the release branch
git checkout FETCH_HEAD -- CHANGELOG.md
git commit -m "$message"
git push origin HEAD:$branch
pr_url=$(gh pr create --title "$message" \
--body "$body" \
--head $branch \
--base main)
echo "pr_url=$pr_url" >> $GITHUB_OUTPUT
- name: Add Skip Changelog label to backport PR
if: steps.backport_pr.outputs.pr_url != ''
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh pr edit ${{ steps.backport_pr.outputs.pr_url }} --add-label "Skip Changelog"