-
Notifications
You must be signed in to change notification settings - Fork 212
163 lines (144 loc) · 6.42 KB
/
Copy pathchangeset-release.yml
File metadata and controls
163 lines (144 loc) · 6.42 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
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
name: Changeset Release
run-name: Changeset Release ${{ github.event_name != 'pull_request' && '- Create PR' || github.event.pull_request.user.login != vars.RELEASE_BOT_LOGIN && '- Create PR' || '- Validate Version PR' }}
on:
workflow_dispatch:
pull_request:
types: [closed, opened, labeled]
env:
REPO_PATH: ${{ github.repository }}
GIT_REF: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || 'main' }}
VERSION_BUMP_PR_TITLE: Zoo Code changeset version bump
jobs:
# Job 1: Create version bump PR when changesets are merged to main
changeset-pr-version-bump:
# Loop guard: title comparison skips the version-bump PR itself so the job
# doesn't recurse when that PR merges. The title is set by VERSION_BUMP_PR_TITLE.
if: >
( github.event_name == 'pull_request' &&
github.event.pull_request.merged == true &&
github.event.pull_request.base.ref == 'main' &&
github.event.pull_request.title != 'Zoo Code changeset version bump' ) ||
github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Generate release bot token
id: release-bot-token
uses: actions/create-github-app-token@v3
with:
app-id: ${{ vars.RELEASE_APP_ID }}
private-key: ${{ secrets.RELEASE_APP_PRIVATE_KEY }}
permission-contents: write
permission-pull-requests: write
- name: Git Checkout
uses: actions/checkout@v4
with:
token: ${{ steps.release-bot-token.outputs.token }}
fetch-depth: 0
ref: ${{ env.GIT_REF }}
- name: Setup Node.js and pnpm
uses: ./.github/actions/setup-node-pnpm
# Check if there are any new changesets to process
- name: Check for changesets
id: check-changesets
run: |
NEW_CHANGESETS=$(find .changeset -name "*.md" ! -name "README.md" | wc -l | tr -d ' ')
echo "Changesets diff with previous version: $NEW_CHANGESETS"
echo "new_changesets=$NEW_CHANGESETS" >> $GITHUB_OUTPUT
# Create version bump PR using changesets/action if there are new changesets
- name: Changeset Pull Request
if: steps.check-changesets.outputs.new_changesets != '0'
id: changesets
uses: changesets/action@v1
with:
commit: "chore: zoo code changeset version bump"
title: ${{ env.VERSION_BUMP_PR_TITLE }}
version: pnpm changeset:version # This performs the changeset version bump
env:
GITHUB_TOKEN: ${{ steps.release-bot-token.outputs.token }}
# Job 2: Validate and approve version bump PRs created by the release bot
changeset-pr-validate-approve:
name: Validate and approve Bump version PRs
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
if: >
github.event_name == 'pull_request' &&
github.event.pull_request.base.ref == 'main' &&
github.event.pull_request.user.login == vars.RELEASE_BOT_LOGIN &&
github.event.pull_request.title == 'Zoo Code changeset version bump'
steps:
- name: Determine checkout ref
id: checkout-ref
env:
EVENT_ACTION: ${{ github.event.action }}
HEAD_REF: ${{ github.head_ref }}
PR_SHA: ${{ github.event.pull_request.head.sha }}
PR_AUTHOR: ${{ github.event.pull_request.user.login }}
RELEASE_BOT_LOGIN: ${{ vars.RELEASE_BOT_LOGIN }}
run: |
echo "Event action: $EVENT_ACTION"
echo "Actor: ${{ github.actor }}"
echo "Head ref: $HEAD_REF"
echo "PR SHA: $PR_SHA"
echo "PR author: $PR_AUTHOR"
if [[ "$EVENT_ACTION" == "opened" && "$PR_AUTHOR" == "$RELEASE_BOT_LOGIN" ]]; then
echo "Using branch ref: $HEAD_REF"
echo "git_ref=$HEAD_REF" >> $GITHUB_OUTPUT
else
echo "Using SHA ref: $PR_SHA"
echo "git_ref=$PR_SHA" >> $GITHUB_OUTPUT
fi
- name: Checkout Repo
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
ref: ${{ steps.checkout-ref.outputs.git_ref }}
- name: Setup Node.js and pnpm
uses: ./.github/actions/setup-node-pnpm
with:
install-args: "--frozen-lockfile"
- name: Build workspace packages
run: |
pnpm --filter @roo-code/build build
pnpm --filter @roo-code/vscode-webview build
- name: Validate version bump PR
env:
POSTHOG_API_KEY: ${{ secrets.POSTHOG_API_KEY }}
run: |
package_name=$(node -p "require('./src/package.json').name")
publisher=$(node -p "require('./src/package.json').publisher")
package_version=$(node -p "require('./src/package.json').version")
test "$package_name" = "zoo-code"
test "$publisher" = "ZooCodeOrganization"
node -e 'const version = process.argv[1]; if (!/^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?$/.test(version)) { throw new Error("Invalid SemVer version: " + version) }' "$package_version"
grep -q "## \\[$package_version\\]\\|## $package_version" CHANGELOG.md
pnpm --filter ./src bundle --production
cmp README.md src/README.md
pnpm --filter ./src vsix
test -f "bin/zoo-code-${package_version}.vsix"
artifact_name=$(unzip -p "bin/zoo-code-${package_version}.vsix" extension/package.json | jq -r '.name')
artifact_publisher=$(unzip -p "bin/zoo-code-${package_version}.vsix" extension/package.json | jq -r '.publisher')
test "$artifact_name" = "zoo-code"
test "$artifact_publisher" = "ZooCodeOrganization"
# Add label to indicate release validation passed
- name: Add changelog-ready label
if: ${{ !contains(github.event.pull_request.labels.*.name, 'changelog-ready') }}
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
labels: ['changelog-ready']
});
- name: Auto approve PR
uses: hmarr/auto-approve-action@v4
with:
review-message: "Approving the Zoo Code changeset version bump PR after release validation passed"