Skip to content

Commit 33e0198

Browse files
authored
BANDA-899 chore: add GitHub Actions workflow to deploy Workers (#160)
also refactored the existing workflows a bit
1 parent ecbeee8 commit 33e0198

28 files changed

+620
-39
lines changed

.changeset/config.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,9 @@
77
"access": "restricted",
88
"baseBranch": "main",
99
"updateInternalDependencies": "patch",
10-
"ignore": []
10+
"ignore": [],
11+
"privatePackages": {
12+
"version": true,
13+
"tag": true
14+
}
1115
}

.changeset/proud-gifts-end.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@repo/tools': minor
3+
---
4+
5+
BANDA-899 feat: add runx deploy-published-workers script

.github/actions/setup/action.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: 'Setup Node.js Environment'
2+
description: 'Install pnpm, Node.js, and project dependencies'
3+
4+
inputs:
5+
node-version:
6+
description: 'Node.js version to use'
7+
required: false
8+
default: '22'
9+
10+
runs:
11+
using: "composite"
12+
steps:
13+
- name: Install pnpm
14+
# note: version is inferred from the packageManager field in package.json
15+
uses: pnpm/action-setup@v4
16+
17+
- name: Use Node.js
18+
uses: actions/setup-node@v4
19+
with:
20+
node-version: ${{ inputs.node-version }}
21+
cache: 'pnpm'
22+
23+
- name: Install dependencies
24+
shell: bash
25+
run: pnpm install --frozen-lockfile --child-concurrency=10
Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
1-
name: Test and check
1+
name: Branches
22
on:
33
push:
4+
branches-ignore: ['main']
5+
6+
env:
7+
FORCE_COLOR: 1
48

59
jobs:
610
test:
11+
name: Test & Check
712
runs-on: ubuntu-24.04
13+
permissions:
14+
contents: read
15+
timeout-minutes: 10
816
strategy:
917
matrix:
1018
node-version: [20, 22]
1119
steps:
1220
- uses: actions/checkout@v4
13-
- name: Install pnpm
14-
uses: pnpm/action-setup@v4
15-
with:
16-
version: 10.8.0
17-
- name: Use Node.js ${{ matrix.node-version }}
18-
uses: actions/setup-node@v4
21+
- uses: ./.github/actions/setup
1922
with:
2023
node-version: ${{ matrix.node-version }}
21-
cache: 'pnpm'
22-
- name: Install dependencies
23-
run: pnpm install --frozen-lockfile --child-concurrency=10
24+
2425
- name: Syncpack lint
2526
run: pnpm check:deps
2627
- name: Run linter
@@ -29,3 +30,4 @@ jobs:
2930
run: pnpm check:format
3031
- name: Run tests
3132
run: pnpm test
33+

.github/workflows/evals.yml

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,19 @@ name: Evals
22
on:
33
push:
44

5+
env:
6+
FORCE_COLOR: 1
7+
58
jobs:
69
eval:
10+
name: Eval
711
runs-on: ubuntu-24.04
8-
strategy:
9-
matrix:
10-
node-version: [22]
12+
permissions:
13+
contents: read
14+
timeout-minutes: 10
1115
steps:
1216
- uses: actions/checkout@v4
13-
- name: Install pnpm
14-
uses: pnpm/action-setup@v4
15-
with:
16-
version: 10.8.0
17-
- name: Use Node.js ${{ matrix.node-version }}
18-
uses: actions/setup-node@v4
19-
with:
20-
node-version: ${{ matrix.node-version }}
21-
cache: 'pnpm'
17+
- uses: ./.github/actions/setup
2218
- name: Create .dev.vars file
2319
run: |
2420
echo "OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }}" > ./apps/sandbox-container/.dev.vars
@@ -29,7 +25,5 @@ jobs:
2925
run: |
3026
du -h ./apps/sandbox-container/.dev.vars
3127
du -h ./apps/workers-bindings/.dev.vars
32-
- name: Install dependencies
33-
run: pnpm install --frozen-lockfile --child-concurrency=10
3428
- name: Run evals
3529
run: pnpm eval:ci

.github/workflows/main.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Main
2+
3+
on:
4+
push:
5+
branches: ['main']
6+
7+
env:
8+
FORCE_COLOR: 1
9+
10+
jobs:
11+
deploy-staging:
12+
name: Deploy (staging)
13+
runs-on: ubuntu-24.04
14+
permissions:
15+
contents: read
16+
timeout-minutes: 10
17+
concurrency: ${{ github.workflow }}-deploy-staging
18+
steps:
19+
- name: Checkout Repo
20+
uses: actions/checkout@v4
21+
- uses: ./.github/actions/setup
22+
23+
# Run tests & checks before deploying
24+
- name: Syncpack lint
25+
run: pnpm check:deps
26+
- name: Run linter
27+
run: pnpm check:turbo
28+
- name: Run linter (formatting)
29+
run: pnpm check:format
30+
- name: Run tests
31+
run: pnpm test
32+
33+
- name: Deploy Workers (staging)
34+
run: pnpm turbo deploy -- -e staging
35+
env:
36+
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
37+
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}

.github/workflows/release.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
branches: ['main']
6+
7+
env:
8+
FORCE_COLOR: 1
9+
10+
jobs:
11+
create-release-pr:
12+
name: Create Release PR
13+
runs-on: ubuntu-24.04
14+
permissions:
15+
contents: write
16+
pull-requests: write
17+
timeout-minutes: 5
18+
concurrency: ${{ github.workflow }}-create-release-pr
19+
outputs:
20+
published: ${{ steps.create-release-pr.outputs.published }}
21+
steps:
22+
- name: Checkout Repo
23+
uses: actions/checkout@v4
24+
- uses: ./.github/actions/setup
25+
- name: Create Release PR
26+
id: create-release-pr
27+
uses: changesets/action@v1
28+
with:
29+
publish: pnpm changeset publish
30+
env:
31+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
32+
- name: Save Published Packages
33+
if: steps.create-release-pr.outputs.published == 'true'
34+
run: |
35+
echo '${{steps.create-release-pr.outputs.publishedPackages}}' \
36+
> ${{ github.workspace }}/published-packages.json
37+
- name: Upload Published Packages
38+
if: steps.create-release-pr.outputs.published == 'true'
39+
uses: actions/upload-artifact@v4
40+
with:
41+
name: published-packages
42+
path: ${{ github.workspace }}/published-packages.json
43+
44+
deploy-production:
45+
name: Deploy (production)
46+
needs: create-release-pr
47+
if: needs.create-release-pr.outputs.published == 'true'
48+
runs-on: ubuntu-24.04
49+
timeout-minutes: 10
50+
concurrency: ${{ github.workflow }}-deploy-production
51+
permissions:
52+
contents: read
53+
steps:
54+
- name: Checkout Repo
55+
uses: actions/checkout@v4
56+
- name: Download published packages
57+
uses: actions/download-artifact@v4
58+
with:
59+
name: published-packages
60+
path: ${{ runner.temp }}
61+
- uses: ./.github/actions/setup
62+
- name: Deploy Published Workers (production)
63+
run: pnpm runx deploy-published-workers --env production
64+
env:
65+
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
66+
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ vitest.config.ts.timestamp*
55
vite.config.ts.timestamp*
66
worker-configuration.d.ts
77
**/dist/**
8+
packages/tools/src/test/fixtures/changesets/invalid-json/*.json

.syncpackrc.cjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ const config = {
4545
// snapTo removes it from syncpack update list, which is the main goal
4646
snapTo: ['@repo/eslint-config'],
4747
},
48+
{
49+
label: 'use zod v4 in packages/tools',
50+
dependencies: ['zod'],
51+
pinVersion: '4.0.0-beta.20250505T195954',
52+
packages: ['@repo/tools'],
53+
},
4854
],
4955
semverGroups: [
5056
{

packages/tools/.eslintrc.cjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/** @type {import("eslint").Linter.Config} */
2+
module.exports = {
3+
root: true,
4+
extends: ['@repo/eslint-config/default.cjs'],
5+
}

packages/tools/README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# @repo/tools
2+
3+
A collection of shared scripts for automating the monorepo while ensuring consistency across packages.
4+
5+
## Scripts
6+
7+
### Bin Scripts
8+
9+
Simple shell scripts for common development tasks:
10+
11+
- `run-tsc`: Run TypeScript type checking
12+
- `run-eslint-workers`: Run ESLint checks
13+
- `run-vitest`: Run tests
14+
- `run-vitest-ci`: Run tests in CI mode
15+
- `run-turbo`: Run Turbo commands with tracking disabled
16+
- `run-wrangler-deploy`: Deploy using Wrangler
17+
- `run-wrangler-types`: Generate Wrangler types
18+
- `run-fix-deps`: Fix dependencies
19+
20+
### Runx CLI
21+
22+
A TypeScript-based CLI for more complex automation tasks. While the bin scripts work well for simple tasks, the runx CLI provides better type safety and more sophisticated programmatic control.
23+
24+
Usage:
25+
26+
```bash
27+
pnpm runx <command> [options]
28+
```
29+
30+
Available commands:
31+
32+
- `deploy-published-workers`: Deploy Cloudflare Workers (based on which packages changesets marked as published in the release).
33+
34+
Note:
35+
36+
The CLI will automatically use Bun if available, but falls back to tsx if not installed.

packages/tools/bin/runx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env sh
2+
set -eu
3+
4+
script_path="$(realpath "$(dirname "$0")/../src/bin/runx.ts")"
5+
6+
bin_dir="$(realpath "$(dirname "$0")")"
7+
tsx_path="$(realpath "$bin_dir/../node_modules/.bin/tsx")"
8+
9+
if command -v bun >/dev/null 2>&1; then
10+
bun "$script_path" "$@"
11+
else
12+
"$tsx_path" "$script_path" "$@"
13+
fi

packages/tools/package.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@
88
"bin": "bin"
99
},
1010
"devDependencies": {
11-
"@types/node": "22.14.1"
11+
"@types/fs-extra": "11.0.4",
12+
"@types/node": "22.14.1",
13+
"vitest": "3.0.9"
14+
},
15+
"dependencies": {
16+
"@commander-js/extra-typings": "13.1.0",
17+
"@jahands/cli-tools": "0.10.2",
18+
"commander": "13.1.0",
19+
"empathic": "1.1.0",
20+
"tsx": "4.19.3",
21+
"zod": "4.0.0-beta.20250505T195954",
22+
"zx": "8.5.4"
1223
}
1324
}

packages/tools/src/bin/runx.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import 'zx/globals'
2+
3+
import { program } from '@commander-js/extra-typings'
4+
import { catchProcessError } from '@jahands/cli-tools'
5+
6+
import { deployPublishedWorkersCmd } from '../cmd/deploy-published-packages'
7+
8+
program
9+
.name('runx')
10+
.description('A CLI for scripts that automate this repo')
11+
12+
// While `packages/tools/bin` scripts work well for simple tasks,
13+
// a typescript CLI is nicer for more complex things.
14+
15+
.addCommand(deployPublishedWorkersCmd)
16+
17+
// Don't hang for unresolved promises
18+
.hook('postAction', () => process.exit(0))
19+
.parseAsync()
20+
.catch(catchProcessError())

0 commit comments

Comments
 (0)