Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,10 @@ updates:
open-pull-requests-limit: 5
reviewers:
- 'cubehouse'
# Actions are pinned to commit SHAs; one grouped PR moves all the pins.
groups:
actions:
patterns:
- '*'
commit-message:
prefix: 'ci'
9 changes: 7 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ on:
# see spec-drift.yml. Kept because dispatching CI by hand is still useful.
workflow_dispatch:

# Least privilege for the workflow token. A job that needs more asks for it
# in its own permissions block.
permissions:
contents: read

jobs:
test:
name: Test (Node ${{ matrix.node }})
Expand All @@ -26,8 +31,8 @@ jobs:
matrix:
node: [20, 22, 24]
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- uses: actions/setup-node@8fccf151e3ba8038c300f83b40c8fd1e94f9c5ce # v7
with:
node-version: ${{ matrix.node }}
cache: npm
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- uses: actions/setup-node@8fccf151e3ba8038c300f83b40c8fd1e94f9c5ce # v7
with: { node-version: '20', cache: 'npm' }
- run: npm ci
- run: npm run docs
- uses: actions/upload-pages-artifact@v5
- uses: actions/upload-pages-artifact@fc324d3547104276b827a68afc52ff2a11cc49c9 # v5
with: { path: docs-site }

deploy:
Expand All @@ -33,4 +33,4 @@ jobs:
url: ${{ steps.deployment.outputs.page_url }}
steps:
- id: deployment
uses: actions/deploy-pages@v5
uses: actions/deploy-pages@368f82528645a54fb793d4d04e342629a3f51346 # v5
9 changes: 7 additions & 2 deletions .github/workflows/mutation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,17 @@ on:
paths:
- 'test/mutation/**'

# Least privilege for the workflow token. A job that needs more asks for it
# in its own permissions block.
permissions:
contents: read

jobs:
mutate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- uses: actions/setup-node@8fccf151e3ba8038c300f83b40c8fd1e94f9c5ce # v7
with:
node-version: 22
cache: npm
Expand Down
39 changes: 36 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ on:
tags:
- 'v*'

# Least privilege for the workflow token. A job that needs more asks for it
# in its own permissions block.
permissions:
contents: read

jobs:
release:
name: Publish to npm
Expand All @@ -13,8 +18,36 @@ jobs:
contents: write
id-token: write
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
# Full history: the on-main check below needs the ancestry.
fetch-depth: 0
# A tag can be pushed on any commit, reviewed or not. Only a commit that
# is already on main may be published, so the check runs before anything
# is installed. HEAD is the tagged commit; the checkout above fetched the
# full history, and main is fetched again by name so the comparison does
# not depend on which refs that checkout happened to bring.
- name: Tagged commit must be on main
run: |
git fetch --no-tags origin '+refs/heads/main:refs/remotes/origin/main'
COMMIT=$(git rev-parse HEAD)
if ! git merge-base --is-ancestor "$COMMIT" origin/main; then
echo "::error::$GITHUB_REF_NAME points at $COMMIT, which is not on main. Merge it first, then tag the merged commit."
exit 1
fi
echo "$GITHUB_REF_NAME ($COMMIT) is on main"
# The tag is the only thing typed by hand, so it is the thing most likely
# to be wrong. Publishing 1.2.0 from a tag reading v1.3.0 would be silent.
- name: Tag must match package.json
run: |
TAG="${GITHUB_REF_NAME#v}"
PKG=$(node -p "require('./package.json').version")
echo "tag=$TAG package.json=$PKG"
if [ "$TAG" != "$PKG" ]; then
echo "::error::tag $TAG does not match package.json $PKG"
exit 1
fi
- uses: actions/setup-node@8fccf151e3ba8038c300f83b40c8fd1e94f9c5ce # v7
with:
node-version: 20
cache: npm
Expand All @@ -37,6 +70,6 @@ jobs:
else
npm publish --provenance --access public
fi
- uses: softprops/action-gh-release@v3
- uses: softprops/action-gh-release@88b783939ccdbabad21b9a37510aed7fad5f2e60 # v3
with:
generate_release_notes: true
102 changes: 80 additions & 22 deletions .github/workflows/spec-drift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,29 @@ on:
- cron: '17 6 * * *'
workflow_dispatch:

# Least privilege for the workflow token. A job that needs more asks for it
# in its own permissions block.
permissions:
contents: read

jobs:
drift:
# TWO JOBS, deliberately. This one installs dependencies and runs the
# generator, the build and the tests, so it gets a read-only token and no
# secrets. The drift bot's credentials exist only in the second job, which
# runs none of that code: it receives the generated files as an artifact.
regenerate:
name: Regenerate schema and run smoke tests
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
issues: write
contents: read
outputs:
build: ${{ steps.build.outcome }}
smoke: ${{ steps.smoke.outcome }}
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
persist-credentials: false
- uses: actions/setup-node@8fccf151e3ba8038c300f83b40c8fd1e94f9c5ce # v7
with:
node-version: 20
cache: npm
Expand All @@ -37,6 +49,58 @@ jobs:
continue-on-error: true
run: npm run test:live

# BOTH GENERATED FILES. `npm run regenerate` writes the schema and the
# daily column list; committing only the schema meant the next field
# upstream added would be typed and not exported, the CSV would silently
# drop it again, and the Python SDK -- which derives its columns at
# runtime -- would pick it up, so the two headers would diverge with
# nothing red anywhere.
#
# Uploaded whether or not they changed: the second job puts them over a
# clean checkout, and an unchanged file opens no PR.
- name: Hand the generated files to the PR job
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7
with:
name: spec-drift-generated
path: |
src/_generated/schema.ts
src/_generated/dailyColumns.ts
if-no-files-found: error
retention-days: 1

open-pr:
name: Open the PR and report failures
needs: regenerate
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
issues: write
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7

# Downloaded OUTSIDE the checkout, then exactly two named files are
# copied in. Unpacking an artifact straight into the workspace would let
# whatever produced it write anywhere in it, .git included.
- name: Fetch the generated files
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8
with:
name: spec-drift-generated
path: ${{ runner.temp }}/spec-drift-generated

- name: Put the generated files in place
env:
GENERATED: ${{ runner.temp }}/spec-drift-generated
run: |
for f in schema.ts dailyColumns.ts; do
if [ ! -f "$GENERATED/$f" ] || [ -L "$GENERATED/$f" ]; then
echo "::error::the artifact has no regular file named $f"
exit 1
fi
install -m 0644 "$GENERATED/$f" "src/_generated/$f"
done
git status --short
# The PR must not be opened with GITHUB_TOKEN. GitHub does not start
# workflow runs from GITHUB_TOKEN-raised events, so a PR opened that way
# never gets its required checks and can never be merged, however good
Expand All @@ -49,21 +113,15 @@ jobs:
# that is not GITHUB_TOKEN, and this app is that identity.
- name: Mint an installation token for the drift bot
id: app-token
uses: actions/create-github-app-token@v3
uses: actions/create-github-app-token@f418cff399f7aef4c2f0ad47e25ca7a6abbdd6fc # v3
with:
app-id: ${{ secrets.DRIFT_APP_ID }}
private-key: ${{ secrets.DRIFT_APP_PRIVATE_KEY }}

- name: Open PR if schema changed
uses: peter-evans/create-pull-request@v8
uses: peter-evans/create-pull-request@3ffccacd46053766916f087ce41d627c0b8cf2d1 # v8
with:
token: ${{ steps.app-token.outputs.token }}
# BOTH GENERATED FILES. `npm run regenerate` writes the schema and the
# daily column list; committing only the schema meant the next field
# upstream added would be typed and not exported, the CSV would silently
# drop it again, and the Python SDK -- which derives its columns at
# runtime -- would pick it up, so the two headers would diverge with
# nothing red anywhere.
add-paths: |
src/_generated/schema.ts
src/_generated/dailyColumns.ts
Expand All @@ -73,36 +131,36 @@ jobs:
body: |
Automated schema regeneration from the `api.themeparks.wiki` OpenAPI spec.
- build: ${{ steps.build.outcome }}
- live smoke tests: ${{ steps.smoke.outcome || 'skipped (build failed)' }}
- build: ${{ needs.regenerate.outputs.build }}
- live smoke tests: ${{ needs.regenerate.outputs.smoke || 'skipped (build failed)' }}
A build failure here means the upstream contract changed in a way
this client cannot absorb automatically. Do not merge until it is
green.
labels: automated, spec-drift

- name: Open issue if the regenerated schema does not build
if: steps.build.outcome == 'failure'
uses: JasonEtco/create-an-issue@v2
if: needs.regenerate.outputs.build == 'failure'
uses: JasonEtco/create-an-issue@1b14a70e4d8dc185e5cc76d3bec9eab20257b2c5 # v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
filename: .github/DRIFT_BUILD_FAILURE.md
update_existing: true

- name: Open issue if smoke tests failed
if: steps.smoke.outcome == 'failure'
uses: JasonEtco/create-an-issue@v2
if: needs.regenerate.outputs.smoke == 'failure'
uses: JasonEtco/create-an-issue@1b14a70e4d8dc185e5cc76d3bec9eab20257b2c5 # v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
filename: .github/SMOKE_FAILURE.md
update_existing: true

# The job itself must go red when the build did, or a silent failure is
# The run itself must go red when the build did, or a silent failure is
# just a green tick with a stale PR behind it.
- name: Fail the run if the regenerated schema does not build
if: steps.build.outcome == 'failure'
if: needs.regenerate.outputs.build == 'failure'
run: |
echo "::error::Regenerated schema does not build — upstream contract changed."
exit 1
Loading