Skip to content

Commit ee3c826

Browse files
committed
[chore] Harden changelog automation against CI edge cases
Signed-off-by: Harshit Kushwaha <find.harshitkushwaha@gmail.com>
1 parent 3b1a722 commit ee3c826

3 files changed

Lines changed: 42 additions & 77 deletions

File tree

.chloggen/TEMPLATE.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
# Valid change types:
2-
# - breaking
3-
# - deprecation
4-
# - new_component
5-
# - enhancement
6-
# - bug_fix
1+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
72
change_type:
8-
component:
3+
# The name of the component (e.g. jmx-metrics, resource-providers, aws-xray)
4+
component:
5+
# A brief description of the change.
96
note:
7+
# One or more tracking issues related to the change. Use the PR number if no issue exists.
108
issues: []
9+
# Optional additional context.
1110
subtext:
11+
# 'user' if relevant to end users, 'api' if there is a library API change.
1212
change_logs: [user]

.github/workflows/changelog-fragment.yml

Lines changed: 10 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,23 @@ jobs:
2323
with:
2424
repository: ${{ github.event.pull_request.head.repo.full_name }}
2525
ref: ${{ github.head_ref }}
26-
token: ${{ secrets.GITHUB_TOKEN }}
26+
token: ${{ secrets.OPENTELEMETRYBOT_GITHUB_TOKEN || secrets.GITHUB_TOKEN }}
2727
fetch-depth: 0
2828

2929
- name: Install yq
3030
run: |
3131
go install github.com/mikefarah/yq/v4@v4.44.3
32-
echo "$(go env GOPATH)/bin" >> "$GITHUB_PATH"
3332
3433
- name: Check skip conditions
3534
id: skip
3635
env:
3736
PR_TITLE: ${{ github.event.pull_request.title }}
3837
PR_LABELS: ${{ toJson(github.event.pull_request.labels.*.name) }}
39-
PR_ACTOR: ${{ github.actor }}
38+
PR_USER_LOGIN: ${{ github.event.pull_request.user.login }}
4039
run: |
4140
skip=false
4241
43-
if [[ "$PR_ACTOR" == "dependabot[bot]" || "$PR_ACTOR" == "renovate[bot]" ]]; then
42+
if [[ "$PR_USER_LOGIN" == "dependabot[bot]" || "$PR_USER_LOGIN" == "renovate[bot]" ]]; then
4443
skip=true
4544
fi
4645
@@ -108,7 +107,7 @@ jobs:
108107
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
109108
-d "$request_payload")"
110109
111-
jq -r '.choices[0].message.content | fromjson' <<<"$response" | yq -P - > ".chloggen/pr-${PR_NUMBER}.yaml"
110+
jq -r '.choices[0].message.content | fromjson' <<<"$response" | "$(go env GOPATH)/bin/yq" -P - > ".chloggen/pr-${PR_NUMBER}.yaml"
112111
113112
- name: Validate AI Output
114113
if: ${{ steps.skip.outputs.skip != 'true' && steps.fragment.outputs.exists != 'true' && github.event.pull_request.head.repo.full_name == github.repository }}
@@ -117,10 +116,8 @@ jobs:
117116
run: |
118117
fragment=".chloggen/pr-${PR_NUMBER}.yaml"
119118
120-
go install go.opentelemetry.io/build-tools/chloggen@v0.15.0
121-
echo "$(go env GOPATH)/bin" >> "$GITHUB_PATH"
122-
123-
if ! chloggen validate --config .chloggen/config.yaml; then
119+
if ! "$(go env GOPATH)/bin/yq" -e 'has("change_type") and has("component") and has("note")' "$fragment" >/dev/null; then
120+
echo "missing required keys: change_type, component, note"
124121
rm -f "$fragment"
125122
exit 1
126123
fi
@@ -137,36 +134,6 @@ jobs:
137134
git commit -m "Add changelog fragment for PR #${PR_NUMBER}"
138135
git push origin HEAD:"${PR_BRANCH}"
139136
140-
- name: Fork comment fallback
141-
if: ${{ steps.skip.outputs.skip != 'true' && steps.fragment.outputs.exists != 'true' && github.event.pull_request.head.repo.full_name != github.repository }}
142-
env:
143-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
144-
PR_NUMBER: ${{ github.event.pull_request.number }}
145-
run: |
146-
{
147-
echo "I could not generate a changelog fragment automatically because this pull request comes from a fork."
148-
echo
149-
echo "Please add the following file manually at .chloggen/pr-${PR_NUMBER}.yaml:"
150-
echo
151-
echo '```yaml'
152-
printf '%s\n' \
153-
'# Valid change types:' \
154-
'# - breaking' \
155-
'# - deprecation' \
156-
'# - new_component' \
157-
'# - enhancement' \
158-
'# - bug_fix' \
159-
'change_type:' \
160-
'component:' \
161-
'note:' \
162-
'issues: []' \
163-
'subtext:' \
164-
'change_logs: [user]'
165-
echo '```'
166-
} > /tmp/changelog-comment.md
167-
168-
gh pr comment --repo "${{ github.repository }}" "${PR_NUMBER}" --body-file /tmp/changelog-comment.md
169-
170137
validate-fragment:
171138
needs: generate-fragment
172139
if: always()
@@ -176,19 +143,19 @@ jobs:
176143
with:
177144
repository: ${{ github.event.pull_request.head.repo.full_name }}
178145
ref: ${{ github.head_ref }}
179-
token: ${{ secrets.GITHUB_TOKEN }}
146+
token: ${{ secrets.OPENTELEMETRYBOT_GITHUB_TOKEN || secrets.GITHUB_TOKEN }}
180147
fetch-depth: 0
181148

182149
- name: Check skip conditions
183150
id: skip
184151
env:
185152
PR_TITLE: ${{ github.event.pull_request.title }}
186153
PR_LABELS: ${{ toJson(github.event.pull_request.labels.*.name) }}
187-
PR_ACTOR: ${{ github.actor }}
154+
PR_USER_LOGIN: ${{ github.event.pull_request.user.login }}
188155
run: |
189156
skip=false
190157
191-
if [[ "$PR_ACTOR" == "dependabot[bot]" || "$PR_ACTOR" == "renovate[bot]" ]]; then
158+
if [[ "$PR_USER_LOGIN" == "dependabot[bot]" || "$PR_USER_LOGIN" == "renovate[bot]" ]]; then
192159
skip=true
193160
fi
194161
@@ -207,7 +174,6 @@ jobs:
207174
run: exit 0
208175

209176
- name: Validate fragment
210-
if: ${{ steps.skip.outputs.skip != 'true' }}
211177
env:
212178
PR_NUMBER: ${{ github.event.pull_request.number }}
213179
run: |
@@ -219,5 +185,4 @@ jobs:
219185
fi
220186
221187
go install go.opentelemetry.io/build-tools/chloggen@v0.15.0
222-
echo "$(go env GOPATH)/bin" >> "$GITHUB_PATH"
223-
chloggen validate --config .chloggen/config.yaml
188+
"$(go env GOPATH)/bin/chloggen" validate --config .chloggen/config.yaml

.github/workflows/draft-release-changelog.yml

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@ on:
44
workflow_dispatch:
55
inputs:
66
version:
7-
description: Version to compile into the changelog
7+
description: 'Release version (e.g. 1.57.0)'
88
required: true
99
type: string
1010

11-
permissions:
12-
contents: write
13-
pull-requests: write
14-
1511
jobs:
16-
compile-changelog:
12+
draft-changelog:
1713
runs-on: ubuntu-latest
14+
permissions:
15+
contents: write
16+
pull-requests: write
17+
1818
steps:
1919
- uses: actions/checkout@v4
2020
with:
2121
fetch-depth: 0
22-
22+
2323
- name: Validate version input
2424
run: |
2525
if [[ ! "${{ inputs.version }}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
@@ -28,26 +28,26 @@ jobs:
2828
fi
2929
3030
- name: Install chloggen
31-
run: |
32-
go install go.opentelemetry.io/build-tools/chloggen@v0.15.0
33-
echo "$(go env GOPATH)/bin" >> "$GITHUB_PATH"
31+
run: go install go.opentelemetry.io/build-tools/chloggen@v0.15.0
3432

35-
- name: Preview changelog update
36-
run: |
37-
chloggen update --config .chloggen/config.yaml --dry
33+
- name: Dry run (preview)
34+
run: $(go env GOPATH)/bin/chloggen update --dry
3835

39-
- name: Compile changelog fragments
40-
run: |
41-
chloggen update --config .chloggen/config.yaml --version "${{ inputs.version }}"
36+
- name: Compile changelog
37+
run: $(go env GOPATH)/bin/chloggen update --version ${{ inputs.version }}
4238

43-
- uses: peter-evans/create-pull-request@v6
39+
- name: Create PR for Release Captain review
40+
uses: peter-evans/create-pull-request@v6
4441
with:
45-
token: ${{ secrets.OPENTELEMETRYBOT_GITHUB_TOKEN || secrets.GITHUB_TOKEN }}
46-
branch: chore/changelog-${{ inputs.version }}
47-
commit-message: "Update changelog for ${{ inputs.version }}"
48-
title: "chore: update changelog for ${{ inputs.version }}"
42+
# Strictly require the bot token for EasyCLA compliance
43+
token: ${{ secrets.OPENTELEMETRYBOT_GITHUB_TOKEN }}
44+
commit-message: "[chore] update changelog for release ${{ inputs.version }}"
45+
committer: "opentelemetrybot <107717825+opentelemetrybot@users.noreply.github.com>"
46+
author: "opentelemetrybot <107717825+opentelemetrybot@users.noreply.github.com>"
47+
title: "[chore] update changelog for release ${{ inputs.version }}"
4948
body: |
50-
Compile changelog fragments for version ${{ inputs.version }}.
51-
author: opentelemetrybot <107717825+opentelemetrybot@users.noreply.github.com>
52-
committer: opentelemetrybot <107717825+opentelemetrybot@users.noreply.github.com>
53-
delete-branch: true
49+
Automated changelog compilation for release `${{ inputs.version }}`.
50+
51+
**Release Captain:** Review the entries below, make any manual corrections, then merge.
52+
branch: "chore/changelog-${{ inputs.version }}"
53+
base: main

0 commit comments

Comments
 (0)