Skip to content

Commit db4d3b6

Browse files
committed
ci: move npm publish and GitHub release to CI workflow
1 parent 786684e commit db4d3b6

2 files changed

Lines changed: 103 additions & 45 deletions

File tree

.github/workflows/release.yml

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
name: Release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: "Version to publish (e.g. 0.1.0-rc.2)"
8+
required: true
9+
type: string
10+
npm-tag:
11+
description: "npm dist-tag"
12+
required: true
13+
type: choice
14+
options:
15+
- latest
16+
- rc
17+
18+
concurrency:
19+
group: release
20+
cancel-in-progress: false
21+
22+
jobs:
23+
publish:
24+
runs-on: ubuntu-latest
25+
permissions:
26+
contents: write
27+
steps:
28+
- name: Checkout tag
29+
uses: actions/checkout@v4
30+
with:
31+
ref: v${{ inputs.version }}
32+
33+
- name: Set up pnpm
34+
uses: pnpm/action-setup@v4
35+
with:
36+
version: 8.15.6
37+
38+
- name: Set up Node.js
39+
uses: actions/setup-node@v4
40+
with:
41+
node-version: 22
42+
cache: pnpm
43+
cache-dependency-path: pnpm-lock.yaml
44+
registry-url: https://registry.npmjs.org
45+
46+
- name: Install dependencies
47+
run: pnpm install --frozen-lockfile
48+
49+
- name: Type check
50+
run: pnpm turbo check-types
51+
52+
- name: Build
53+
run: pnpm turbo build
54+
55+
- name: Publish to npm
56+
run: |
57+
FAILURES=""
58+
for dir in $(pnpm -r ls --json --depth -1 | jq -r '.[] | select(.private != true) | .path'); do
59+
# Skip the root package
60+
if [ "$dir" = "$(pwd)" ]; then
61+
continue
62+
fi
63+
NAME=$(jq -r .name "$dir/package.json")
64+
VERSION="${{ inputs.version }}"
65+
# Skip if already published
66+
if npm view "${NAME}@${VERSION}" version >/dev/null 2>&1; then
67+
echo "⏭ ${NAME}@${VERSION} already published, skipping."
68+
continue
69+
fi
70+
echo "Publishing ${NAME}@${VERSION}..."
71+
if ! (cd "$dir" && pnpm publish --access public --tag ${{ inputs.npm-tag }} --no-git-checks); then
72+
FAILURES="${FAILURES} ${NAME}"
73+
fi
74+
done
75+
if [ -n "$FAILURES" ]; then
76+
echo "::error::Failed to publish:${FAILURES}"
77+
exit 1
78+
fi
79+
env:
80+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
81+
82+
- name: Create GitHub release
83+
run: |
84+
if gh release view "v${{ inputs.version }}" >/dev/null 2>&1; then
85+
echo "GitHub release v${{ inputs.version }} already exists, skipping."
86+
else
87+
PRERELEASE=""
88+
if [ "${{ inputs.npm-tag }}" = "rc" ]; then
89+
PRERELEASE="--prerelease"
90+
fi
91+
gh release create "v${{ inputs.version }}" \
92+
--title "v${{ inputs.version }}" \
93+
--generate-notes \
94+
$PRERELEASE
95+
fi
96+
env:
97+
GH_TOKEN: ${{ github.token }}

scripts/release.ts

Lines changed: 6 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@ function tryRun(cmd: string, opts?: { cwd?: string; stdio?: "pipe" | "inherit" }
2727
}
2828
}
2929

30-
function isPublished(name: string, version: string): boolean {
31-
const { ok } = tryRun(`npm view ${name}@${version} version`);
32-
return ok;
33-
}
34-
3530
function fatal(msg: string): never {
3631
console.error(`\x1b[31mError:\x1b[0m ${msg}`);
3732
process.exit(1);
@@ -155,13 +150,6 @@ async function main() {
155150
process.exit(0);
156151
}
157152

158-
// Typecheck & build
159-
console.log("\n\x1b[1mRunning typecheck...\x1b[0m");
160-
run("pnpm turbo check-types", { stdio: "inherit" });
161-
162-
console.log("\n\x1b[1mRunning build...\x1b[0m");
163-
run("pnpm turbo build", { stdio: "inherit" });
164-
165153
// Bump versions
166154
console.log(`\n\x1b[1mBumping versions to ${version}...\x1b[0m`);
167155
setVersion(ROOT, version);
@@ -183,7 +171,7 @@ async function main() {
183171
console.log(" No version changes to commit, skipping.");
184172
}
185173

186-
// Git tag & GitHub release
174+
// Git tag
187175
console.log(`\n\x1b[1mCreating git tag v${version}...\x1b[0m`);
188176
const tagExists = tryRun(`git rev-parse v${version}`).ok;
189177
if (tagExists) {
@@ -193,39 +181,12 @@ async function main() {
193181
run(`git push origin v${version}`);
194182
}
195183

196-
const prerelease = tag === "rc" ? "--prerelease" : "";
197-
const releaseExists = tryRun(`gh release view v${version}`).ok;
198-
if (releaseExists) {
199-
console.log(` GitHub release v${version} already exists, skipping.`);
200-
} else {
201-
console.log("\n\x1b[1mCreating GitHub release...\x1b[0m");
202-
run(
203-
`gh release create v${version} --title "v${version}" --generate-notes ${prerelease}`.trim(),
204-
{ stdio: "inherit" },
205-
);
206-
}
207-
208-
// Publish
209-
console.log(`\n\x1b[1mPublishing to npm (tag: ${tag})...\x1b[0m`);
210-
const failures: string[] = [];
211-
for (const pkg of packages) {
212-
const name = JSON.parse(readFileSync(join(pkg, "package.json"), "utf-8")).name;
213-
if (isPublished(name, version)) {
214-
console.log(` \x1b[33m⏭ ${name}@${version} already published, skipping.\x1b[0m`);
215-
continue;
216-
}
217-
console.log(` Publishing ${name}...`);
218-
const { ok } = tryRun(`pnpm publish --access public --tag ${tag} --no-git-checks`, { cwd: pkg, stdio: "inherit" });
219-
if (!ok) {
220-
failures.push(name);
221-
}
222-
}
223-
224-
if (failures.length > 0) {
225-
fatal(`Failed to publish: ${failures.join(", ")}`);
226-
}
184+
// Trigger CI release workflow
185+
console.log(`\n\x1b[1mTriggering CI release workflow...\x1b[0m`);
186+
run(`gh workflow run release.yml -f version=${version} -f npm-tag=${tag}`, { stdio: "inherit" });
227187

228-
console.log(`\n\x1b[32m✓ Released v${version}\x1b[0m`);
188+
console.log(`\n\x1b[32m✓ Tag v${version} pushed — CI will handle publish + GitHub release.\x1b[0m`);
189+
console.log(` Watch progress: \x1b[36mhttps://github.com/rivet-dev/secure-exec/actions/workflows/release.yml\x1b[0m`);
229190
}
230191

231192
main().catch((err) => {

0 commit comments

Comments
 (0)