-
Notifications
You must be signed in to change notification settings - Fork 849
181 lines (155 loc) · 6.32 KB
/
release.yml
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
name: Release
on:
workflow_dispatch:
jobs:
release:
runs-on: ubuntu-22.04
outputs:
version: ${{ steps.create-github-release.outputs.version }}
steps:
- run: |
if [[ $GITHUB_REF_NAME != release/* ]]; then
echo this workflow should only be run against release branches
exit 1
fi
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 17
- name: Build and publish artifacts
uses: gradle/actions/setup-gradle@v3
with:
arguments: assemble publishToSonatype closeAndReleaseSonatypeStagingRepository
env:
SONATYPE_USER: ${{ secrets.SONATYPE_USER }}
SONATYPE_KEY: ${{ secrets.SONATYPE_KEY }}
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
GPG_PASSWORD: ${{ secrets.GPG_PASSWORD }}
- name: Set environment variables
run: |
version=$(.github/scripts/get-version.sh)
if [[ $version =~ ^([0-9]+)\.([0-9]+)\.([0-9]+) ]]; then
major="${BASH_REMATCH[1]}"
minor="${BASH_REMATCH[2]}"
patch="${BASH_REMATCH[3]}"
else
echo "unexpected version: $version"
exit 1
fi
if [[ $patch == 0 ]]; then
if [[ $minor == 0 ]]; then
prior_major=$((major - 1))
prior_minor=$(grep -Po "^## Version $prior_major.\K[0-9]+" CHANGELOG.md | head -1)
prior_version="$prior_major.$prior_minor"
else
prior_version="$major.$((minor - 1)).0"
fi
else
prior_version="$major.$minor.$((patch - 1))"
fi
echo "VERSION=$version" >> $GITHUB_ENV
echo "PRIOR_VERSION=$prior_version" >> $GITHUB_ENV
# check out main branch to verify there won't be problems with merging the change log
# at the end of this workflow
- uses: actions/checkout@v4
with:
ref: main
- name: Check that change log update was merged to main
run: |
if [[ $VERSION == *.0 ]]; then
# not making a patch release
if ! grep --quiet "^## Version $VERSION " CHANGELOG.md; then
echo the pull request generated by prepare-release-branch.yml needs to be merged first
exit 1
fi
fi
# back to the release branch
- uses: actions/checkout@v4
with:
# tags are needed for the generate-release-contributors.sh script
fetch-depth: 0
- name: Generate release notes
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# conditional blocks not indented because of the heredoc
if [[ $VERSION != *.0 ]]; then
cat > /tmp/release-notes.txt << EOF
This is a patch release on the previous $PRIOR_VERSION release, fixing the issue(s) below.
EOF
fi
# CHANGELOG_SECTION.md is also used at the end of the release workflow
# for copying the change log updates to main
sed -n "0,/^## Version $VERSION /d;/^## Version /q;p" CHANGELOG.md \
> /tmp/CHANGELOG_SECTION.md
# the complex perl regex is needed because markdown docs render newlines as soft wraps
# while release notes render them as line breaks
perl -0pe 's/(?<!\n)\n *(?!\n)(?![-*] )(?![1-9]+\. )/ /g' /tmp/CHANGELOG_SECTION.md \
>> /tmp/release-notes.txt
# conditional block not indented because of the heredoc
if [[ $VERSION == *.0 ]]; then
cat >> /tmp/release-notes.txt << EOF
### 🙇 Thank you
This release was possible thanks to the following contributors who shared their brilliant ideas and awesome pull requests:
EOF
.github/scripts/generate-release-contributors.sh v$PRIOR_VERSION >> /tmp/release-notes.txt
fi
- id: create-github-release
name: Create GitHub release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release create --target $GITHUB_REF_NAME \
--title "Version $VERSION" \
--notes-file /tmp/release-notes.txt \
v$VERSION
echo "version=$VERSION" >> $GITHUB_OUTPUT
merge-change-log-to-main:
runs-on: ubuntu-latest
needs:
- release
steps:
- uses: actions/checkout@v4
- name: Copy change log section from release branch
env:
VERSION: ${{ needs.release.outputs.version }}
run: |
sed -n "0,/^## Version $VERSION /d;/^## Version /q;p" CHANGELOG.md \
> /tmp/changelog-section.md
- uses: actions/checkout@v4
with:
ref: main
- name: Merge change log to main
env:
VERSION: ${{ needs.release.outputs.version }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
release_date=$(gh release view v$VERSION --json publishedAt --jq .publishedAt | sed 's/T.*//')
RELEASE_DATE=$release_date .github/scripts/merge-change-log-after-release.sh
- name: Use CLA approved github bot
run: .github/scripts/use-cla-approved-github-bot.sh
- name: Create pull request against main
env:
VERSION: ${{ needs.release.outputs.version }}
# not using secrets.GITHUB_TOKEN since pull requests from that token do not run workflows
GH_TOKEN: ${{ secrets.OPENTELEMETRYBOT_GITHUB_TOKEN }}
run: |
if git diff --quiet; then
if [[ $VERSION =~ ^[0-9]+\.[0-9]+\.0 ]]; then
echo there are no updates to merge, not creating pull request
exit 0 # success
else
echo patch release notes did not get applied for some reason
exit 1 # failure
fi
fi
message="Merge change log updates from $GITHUB_REF_NAME"
body="Merge log updates from \`$GITHUB_REF_NAME\`."
branch="opentelemetrybot/merge-change-log-updates-from-${GITHUB_REF_NAME//\//-}"
git checkout -b $branch
git commit -a -m "$message"
git push --set-upstream origin $branch
gh pr create --title "$message" \
--body "$body" \
--base main