35
35
- name : Set environment variables
36
36
run : |
37
37
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
39
39
major="${BASH_REMATCH[1]}"
40
40
minor="${BASH_REMATCH[2]}"
41
41
patch="${BASH_REMATCH[3]}"
@@ -57,39 +57,61 @@ jobs:
57
57
echo "VERSION=$version" >> $GITHUB_ENV
58
58
echo "PRIOR_VERSION=$prior_version" >> $GITHUB_ENV
59
59
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
+
60
78
- name : Generate release notes
61
79
env :
62
80
GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
63
81
run : |
64
82
# conditional blocks not indented because of the heredoc
65
83
if [[ $VERSION == *.0 ]]; then
66
- cat > release-notes.txt << EOF
84
+ cat > /tmp/ release-notes.txt << EOF
67
85
This release targets the OpenTelemetry SDK $VERSION.
68
86
69
87
EOF
70
88
else
71
- cat > release-notes.txt << EOF
89
+ cat > /tmp/ release-notes.txt << EOF
72
90
This is a patch release on the previous $PRIOR_VERSION release, fixing the issue(s) below.
73
91
74
92
EOF
75
93
fi
76
94
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
+
77
100
# the complex perl regex is needed because markdown docs render newlines as soft wraps
78
101
# 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
82
104
83
105
# conditional block not indented because of the heredoc
84
106
if [[ $VERSION == *.0 ]]; then
85
- cat >> release-notes.txt << EOF
107
+ cat >> /tmp/ release-notes.txt << EOF
86
108
87
109
### 🙇 Thank you
88
110
This release was possible thanks to the following contributors who shared their brilliant ideas and awesome pull requests:
89
111
90
112
EOF
91
113
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
93
115
fi
94
116
95
117
- name : Create GitHub release
@@ -98,31 +120,83 @@ jobs:
98
120
run : |
99
121
gh release create --target $GITHUB_REF_NAME \
100
122
--title "Version $VERSION" \
101
- --notes-file release-notes.txt \
123
+ --notes-file /tmp/ release-notes.txt \
102
124
--discussion-category announcements \
103
125
v$VERSION
104
126
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
106
133
env :
107
134
GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
108
135
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
111
177
112
178
- name : Set git user
113
179
run : .github/scripts/set-git-user.sh
114
180
115
- - name : Create pull request against the release branch
181
+ - name : Create pull request against main
116
182
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
118
184
GITHUB_TOKEN : ${{ secrets.BOT_TOKEN }}
119
185
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
122
196
123
197
git commit -a -m "$message"
124
198
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 " \
127
201
--head $branch \
128
- --base $GITHUB_REF_NAME
202
+ --base main
0 commit comments