Skip to content

Commit 796ccba

Browse files
authored
add changelog workflow (#2818)
1 parent bb09d5d commit 796ccba

File tree

3 files changed

+163
-25
lines changed

3 files changed

+163
-25
lines changed

.github/workflows/changelog.yaml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
on:
2+
workflow_dispatch:
3+
inputs:
4+
channel:
5+
description: "Release channel"
6+
required: true
7+
type: choice
8+
options:
9+
- nightly
10+
- stable
11+
workflow_call:
12+
inputs:
13+
channel:
14+
required: true
15+
type: string
16+
issue_number:
17+
required: false
18+
type: number
19+
comment_id:
20+
required: false
21+
type: number
22+
23+
permissions:
24+
contents: write
25+
pull-requests: write
26+
27+
jobs:
28+
generate:
29+
runs-on: ubuntu-latest
30+
env:
31+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
32+
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
33+
steps:
34+
- uses: actions/checkout@v4
35+
with:
36+
fetch-depth: 0
37+
- if: inputs.comment_id
38+
uses: ./.github/actions/add-reaction
39+
with:
40+
token: ${{ secrets.GITHUB_TOKEN }}
41+
repo: ${{ github.repository }}
42+
comment: ${{ inputs.comment_id }}
43+
reaction: eyes
44+
- id: version
45+
run: |
46+
CHANNEL="${{ inputs.channel }}"
47+
if [ "$CHANNEL" = "nightly" ]; then
48+
LATEST_TAG=$(git tag -l 'desktop_v*-nightly.*' --sort=-v:refname | head -n1)
49+
PREV_REF="main"
50+
else
51+
LATEST_TAG=$(git tag -l 'desktop_v*' --sort=-v:refname | grep -v 'nightly' | head -n1)
52+
PREV_REF=$(git tag -l 'desktop_v*-nightly.*' --sort=-v:refname | head -n1)
53+
fi
54+
VERSION="${LATEST_TAG#desktop_v}"
55+
echo "version=$VERSION" >> $GITHUB_OUTPUT
56+
echo "latest_tag=$LATEST_TAG" >> $GITHUB_OUTPUT
57+
echo "prev_ref=$PREV_REF" >> $GITHUB_OUTPUT
58+
- run: |
59+
curl -fsSL https://opencode.ai/install | bash
60+
echo "$HOME/.opencode/bin" >> $GITHUB_PATH
61+
- run: |
62+
VERSION="${{ steps.version.outputs.version }}"
63+
CHANGELOG_FILE="apps/web/content/changelog/${VERSION}.mdx"
64+
65+
opencode -p "Create ${CHANGELOG_FILE} for commits between ${{ steps.version.outputs.prev_ref }} and ${{ steps.version.outputs.latest_tag }}. Follow apps/web/content/changelog/AGENTS.md."
66+
- uses: peter-evans/create-pull-request@v8
67+
id: cpr
68+
with:
69+
token: ${{ secrets.GITHUB_TOKEN }}
70+
branch: changelog/${{ steps.version.outputs.version }}
71+
title: "docs: changelog for ${{ steps.version.outputs.version }}"
72+
body: |
73+
Auto-generated changelog for version ${{ steps.version.outputs.version }}.
74+
75+
Generated using `opencode` CLI based on commits from ${{ steps.version.outputs.prev_ref }} to ${{ steps.version.outputs.latest_tag }}.
76+
commit-message: "docs: add changelog for ${{ steps.version.outputs.version }}"
77+
delete-branch: true
78+
- if: inputs.issue_number
79+
uses: ./.github/actions/comment-result
80+
with:
81+
token: ${{ secrets.GITHUB_TOKEN }}
82+
repo: ${{ github.repository }}
83+
issue_number: ${{ inputs.issue_number }}
84+
data: |
85+
[{"header": "Version", "value": "`${{ steps.version.outputs.version }}`"}, {"header": "PR", "value": "${{ steps.cpr.outputs.pull-request-url || 'No changes' }}"}]

.github/workflows/command_dispatcher.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,30 @@ jobs:
7474
issue_number: ${{ github.event.issue.number }}
7575
comment_id: ${{ github.event.comment.id }}
7676
secrets: inherit
77+
78+
parse-changelog-channel:
79+
needs: check-permission
80+
if: needs.check-permission.outputs.allowed == 'true' && contains(github.event.comment.body, '/changelog')
81+
runs-on: ubuntu-latest
82+
outputs:
83+
channel: ${{ steps.parse.outputs.channel }}
84+
steps:
85+
- id: parse
86+
env:
87+
COMMENT: ${{ github.event.comment.body }}
88+
run: |
89+
if [[ "$COMMENT" =~ /changelog[[:space:]]+(nightly|stable)($|[[:space:]]) ]]; then
90+
echo "channel=${BASH_REMATCH[1]}" >> $GITHUB_OUTPUT
91+
else
92+
echo "channel=nightly" >> $GITHUB_OUTPUT
93+
fi
94+
95+
handle-changelog:
96+
needs: [check-permission, parse-changelog-channel]
97+
if: needs.check-permission.outputs.allowed == 'true' && contains(github.event.comment.body, '/changelog')
98+
uses: ./.github/workflows/changelog.yaml
99+
with:
100+
channel: ${{ needs.parse-changelog-channel.outputs.channel }}
101+
issue_number: ${{ github.event.issue.number }}
102+
comment_id: ${{ github.event.comment.id }}
103+
secrets: inherit

.github/workflows/handle_release.yaml

Lines changed: 51 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ jobs:
2525
REPO: ${{ github.repository }}
2626
steps:
2727
- uses: actions/checkout@v4
28+
with:
29+
fetch-depth: 0
30+
fetch-tags: true
31+
- run: git fetch --tags --force
2832
- uses: ./.github/actions/add-reaction
2933
with:
3034
token: ${{ secrets.GITHUB_TOKEN }}
@@ -33,28 +37,48 @@ jobs:
3337
reaction: eyes
3438
- id: resolve
3539
run: |
36-
PR_DATA=$(gh api repos/$REPO/pulls/${{ inputs.issue_number }} 2>/dev/null) || {
37-
echo "merged=false" >> $GITHUB_OUTPUT
38-
echo "error=Not a pull request or PR not found" >> $GITHUB_OUTPUT
39-
exit 0
40-
}
40+
if [ "${{ inputs.channel }}" == "stable" ]; then
41+
NIGHTLY_TAG=$(git tag -l 'desktop_v*-nightly.*' --sort=-v:refname | head -n1)
42+
if [ -z "$NIGHTLY_TAG" ]; then
43+
echo "resolved=false" >> $GITHUB_OUTPUT
44+
echo "error=No nightly release tag found" >> $GITHUB_OUTPUT
45+
exit 0
46+
fi
4147
42-
MERGED=$(echo "$PR_DATA" | jq -r '.merged')
43-
if [ "$MERGED" != "true" ]; then
44-
echo "merged=false" >> $GITHUB_OUTPUT
45-
echo "error=PR must be merged first" >> $GITHUB_OUTPUT
46-
exit 0
47-
fi
48+
TAG_SHA=$(git rev-list -n 1 "$NIGHTLY_TAG")
49+
TEMP_BRANCH="release-temp-${TAG_SHA:0:8}"
4850
49-
MERGE_SHA=$(echo "$PR_DATA" | jq -r '.merge_commit_sha')
50-
TEMP_BRANCH="release-temp-${MERGE_SHA:0:8}"
51+
GH_TOKEN=${{ secrets.PAT_TOKEN }} gh api repos/$REPO/git/refs -f ref="refs/heads/$TEMP_BRANCH" -f sha="$TAG_SHA"
52+
53+
echo "resolved=true" >> $GITHUB_OUTPUT
54+
echo "target_sha=$TAG_SHA" >> $GITHUB_OUTPUT
55+
echo "target_ref=$NIGHTLY_TAG" >> $GITHUB_OUTPUT
56+
echo "branch=$TEMP_BRANCH" >> $GITHUB_OUTPUT
57+
else
58+
PR_DATA=$(gh api repos/$REPO/pulls/${{ inputs.issue_number }} 2>/dev/null) || {
59+
echo "resolved=false" >> $GITHUB_OUTPUT
60+
echo "error=Not a pull request or PR not found" >> $GITHUB_OUTPUT
61+
exit 0
62+
}
5163
52-
GH_TOKEN=${{ secrets.PAT_TOKEN }} gh api repos/$REPO/git/refs -f ref="refs/heads/$TEMP_BRANCH" -f sha="$MERGE_SHA"
64+
MERGED=$(echo "$PR_DATA" | jq -r '.merged')
65+
if [ "$MERGED" != "true" ]; then
66+
echo "resolved=false" >> $GITHUB_OUTPUT
67+
echo "error=PR must be merged first" >> $GITHUB_OUTPUT
68+
exit 0
69+
fi
5370
54-
echo "merged=true" >> $GITHUB_OUTPUT
55-
echo "merge_sha=$MERGE_SHA" >> $GITHUB_OUTPUT
56-
echo "branch=$TEMP_BRANCH" >> $GITHUB_OUTPUT
57-
- if: steps.resolve.outputs.merged == 'true'
71+
MERGE_SHA=$(echo "$PR_DATA" | jq -r '.merge_commit_sha')
72+
TEMP_BRANCH="release-temp-${MERGE_SHA:0:8}"
73+
74+
GH_TOKEN=${{ secrets.PAT_TOKEN }} gh api repos/$REPO/git/refs -f ref="refs/heads/$TEMP_BRANCH" -f sha="$MERGE_SHA"
75+
76+
echo "resolved=true" >> $GITHUB_OUTPUT
77+
echo "target_sha=$MERGE_SHA" >> $GITHUB_OUTPUT
78+
echo "target_ref=$MERGE_SHA" >> $GITHUB_OUTPUT
79+
echo "branch=$TEMP_BRANCH" >> $GITHUB_OUTPUT
80+
fi
81+
- if: steps.resolve.outputs.resolved == 'true'
5882
id: trigger
5983
uses: ./.github/actions/trigger-workflow
6084
with:
@@ -67,26 +91,28 @@ jobs:
6791
- id: result
6892
run: |
6993
CHANNEL="${{ inputs.channel }}"
70-
MERGED="${{ steps.resolve.outputs.merged }}"
71-
MERGE_SHA="${{ steps.resolve.outputs.merge_sha }}"
94+
RESOLVED="${{ steps.resolve.outputs.resolved }}"
95+
TARGET_SHA="${{ steps.resolve.outputs.target_sha }}"
96+
TARGET_REF="${{ steps.resolve.outputs.target_ref }}"
97+
ERROR="${{ steps.resolve.outputs.error }}"
7298
RUN_ID="${{ steps.trigger.outputs.run_id }}"
7399
74-
if [ "$MERGED" != "true" ]; then
100+
if [ "$RESOLVED" != "true" ]; then
75101
DATA=$(jq -cn \
76102
--arg channel "\`$CHANNEL\`" \
77103
--arg sha "-" \
78-
--arg status "PR must be merged first" \
104+
--arg status "$ERROR" \
79105
'[{header: "Channel", value: $channel}, {header: "Commit", value: $sha}, {header: "Status", value: $status}]')
80106
elif [ -n "$RUN_ID" ]; then
81107
DATA=$(jq -cn \
82108
--arg channel "\`$CHANNEL\`" \
83-
--arg sha "[\`${MERGE_SHA:0:8}\`](https://github.com/$REPO/commit/$MERGE_SHA)" \
109+
--arg sha "[\`${TARGET_SHA:0:8}\`](https://github.com/$REPO/commit/$TARGET_SHA) ($TARGET_REF)" \
84110
--arg status "[View](https://github.com/$REPO/actions/runs/$RUN_ID)" \
85111
'[{header: "Channel", value: $channel}, {header: "Commit", value: $sha}, {header: "Status", value: $status}]')
86112
else
87113
DATA=$(jq -cn \
88114
--arg channel "\`$CHANNEL\`" \
89-
--arg sha "[\`${MERGE_SHA:0:8}\`](https://github.com/$REPO/commit/$MERGE_SHA)" \
115+
--arg sha "[\`${TARGET_SHA:0:8}\`](https://github.com/$REPO/commit/$TARGET_SHA) ($TARGET_REF)" \
90116
--arg status "[Logs](https://github.com/$REPO/actions/runs/${{ github.run_id }})" \
91117
'[{header: "Channel", value: $channel}, {header: "Commit", value: $sha}, {header: "Status", value: $status}]')
92118
fi
@@ -97,7 +123,7 @@ jobs:
97123
repo: ${{ github.repository }}
98124
issue_number: ${{ inputs.issue_number }}
99125
data: ${{ steps.result.outputs.data }}
100-
- if: steps.resolve.outputs.merged == 'true'
126+
- if: steps.resolve.outputs.resolved == 'true'
101127
env:
102128
GH_TOKEN: ${{ secrets.PAT_TOKEN }}
103129
run: gh api repos/${{ github.repository }}/git/refs/heads/${{ steps.resolve.outputs.branch }} -X DELETE || true

0 commit comments

Comments
 (0)