Repository navigation
178 lines (155 loc) · 5.85 KB
/
Copy pathrelease.yml
File metadata and controls
178 lines (155 loc) · 5.85 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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
name: Release
on:
push:
branches: [main]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false
permissions:
contents: write
pull-requests: write
id-token: write
jobs:
release:
name: Version or Publish
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: actions/setup-node@v5
with:
node-version: 24
registry-url: https://registry.npmjs.org
- name: Install npm with trusted publishing support
run: npm install --global npm@11.5.1
- name: Install dependencies
run: npm ci || npm install
- name: Create Release PR or Publish
id: changesets
uses: changesets/action@v1
with:
version: npm run version
publish: npm run release
title: "Version Packages"
commit: "chore: version packages"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Verify stable npm dist-tags
if: steps.changesets.outputs.hasChangesets == 'false'
run: bash scripts/verify-release-dist-tags.sh
- name: Find Version Packages PR
id: find-pr
uses: actions/github-script@v8
with:
script: |
const { data: pulls } = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
head: `${context.repo.owner}:changeset-release/main`,
base: 'main',
state: 'open',
});
if (pulls.length === 0) {
core.info('No Version Packages PR found — skipping preview');
return;
}
core.setOutput('pr_number', pulls[0].number);
core.setOutput('found', 'true');
- uses: actions/checkout@v5
if: steps.find-pr.outputs.found == 'true'
with:
ref: changeset-release/main
- name: Install preview dependencies
if: steps.find-pr.outputs.found == 'true'
run: npm ci || npm install
- name: Verify preview version collisions
if: steps.find-pr.outputs.found == 'true'
run: bash scripts/verify-release-dist-tags.sh --pre-publish
- name: Publish preview packages
if: steps.find-pr.outputs.found == 'true'
id: preview
run: |
RUN_NUMBER="${{ github.run_number }}"
PUBLISHED=""
for pkg in packages/*/package.json; do
dir=$(dirname "$pkg")
name=$(node -e "console.log(JSON.parse(require('fs').readFileSync('$pkg','utf8')).name)")
version=$(node -e "console.log(JSON.parse(require('fs').readFileSync('$pkg','utf8')).version)")
[ -z "$name" ] && continue
npm_latest=$(npm view "$name" version 2>/dev/null || echo "")
if [ -n "$npm_latest" ] && [ "$version" = "$npm_latest" ]; then
echo "Skipping $name@$version — already on npm latest, not part of this release"
continue
fi
preview_version="${version}-preview.${RUN_NUMBER}"
node -e "
const fs = require('fs');
const pkg = JSON.parse(fs.readFileSync('$pkg','utf8'));
pkg.version = '${preview_version}';
fs.writeFileSync('$pkg', JSON.stringify(pkg, null, 2) + '\n');
"
echo "Publishing $name@$preview_version with tag preview..."
(cd "$dir" && npm publish --tag preview --provenance --access public)
PUBLISHED="$PUBLISHED\n- \`$name@$preview_version\` -> \`npx $name@preview\`"
done
echo "published<<EOF" >> "$GITHUB_OUTPUT"
echo -e "$PUBLISHED" >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"
- name: Smoke test preview install
if: steps.find-pr.outputs.found == 'true'
run: npm info @windyroad/agent-plugins@preview version
- name: Comment on PR
if: steps.find-pr.outputs.found == 'true'
uses: actions/github-script@v8
env:
PR_NUMBER: ${{ steps.find-pr.outputs.pr_number }}
PUBLISHED: ${{ steps.preview.outputs.published }}
with:
script: |
const prNumber = parseInt(process.env.PR_NUMBER, 10);
const published = process.env.PUBLISHED || '(none)';
const body = [
'## Release Preview',
'',
'Preview packages published to npm with the `preview` tag.',
'',
'### Test it',
'',
'```bash',
'# Install the full preview suite',
'npx @windyroad/agent-plugins@preview',
'',
'# Or test individual packages',
'npx @windyroad/architect@preview',
'npx @windyroad/c4@preview',
'```',
'',
'### Published packages',
'',
published,
'',
'---',
'*Merge this PR to publish these versions to `latest`.*',
].join('\n');
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
});
const existing = comments.find(c =>
c.user.type === 'Bot' && c.body.includes('## Release Preview')
);
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body,
});
}