name: Update Runtime Defaults on: schedule: - cron: "0 6 * * *" # daily at 06:00 UTC workflow_dispatch: concurrency: group: update-runtime-defaults cancel-in-progress: false permissions: contents: read jobs: update-defaults: runs-on: ubuntu-latest steps: - name: Generate App Token id: app-token uses: actions/create-github-app-token@v3 with: client-id: ${{ vars.APP_CLIENT_ID }} private-key: ${{ secrets.APP_PRIVATE_KEY }} owner: spencerbeggs - name: Checkout uses: actions/checkout@v7 with: ref: main fetch-depth: 0 token: ${{ steps.app-token.outputs.token }} - name: Setup Runtime id: runtime uses: savvy-web/silk-runtime-action@v1 - name: Generate defaults env: # The generator's GitHubAuth.layer reads GITHUB_TOKEN from config; feed it # the App token (not the ambient Actions secret of the same name). GITHUB_TOKEN: ${{ steps.app-token.outputs.token }} run: pnpm --filter @effected/runtimes exec tsx lib/scripts/generate-defaults.ts - name: Format generated files # Scope Biome to the only files the generator writes, so an unrelated # unfixable lint diagnostic elsewhere in the repo cannot abort this job. run: pnpm exec biome check --write packages/runtimes/src/internal/defaults/ - name: Check for changes id: changes run: | if git diff --quiet -- packages/runtimes/src/internal/defaults/; then echo "changed=false" >> "$GITHUB_OUTPUT" else echo "changed=true" >> "$GITHUB_OUTPUT" fi - name: Write changeset if: steps.changes.outputs.changed == 'true' run: | printf '%s\n' \ '---' \ '"@effected/runtimes": patch' \ '---' \ '' \ '## Maintenance' \ '' \ '- Refreshed the bundled Node.js, Bun and Deno version defaults from the upstream release feeds' \ > .changeset/update-runtime-defaults.md - name: Build and test if: steps.changes.outputs.changed == 'true' run: | pnpm build --filter @effected/runtimes # Smoke-check the package's own tests on the regenerated data. Coverage is # disabled: this repo's vitest config enforces global coverage thresholds # that a single-package subset run cannot meet, which would abort the job. pnpm vitest run packages/runtimes --coverage.enabled=false - name: Open auto-merging PR if: steps.changes.outputs.changed == 'true' env: GH_TOKEN: ${{ steps.app-token.outputs.token }} REPO: ${{ github.repository }} BRANCH: chore/update-runtime-defaults BASE_BRANCH: main HEADLINE: "chore(runtimes): refresh bundled runtime version defaults" # DCO only requires a well-formed trailer; keep the exact identity the # previous `git commit --signoff` produced under this App. SIGNOFF: "Signed-off-by: ${{ steps.app-token.outputs.app-slug }}[bot] <${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com>" run: | set -euo pipefail # The commit is created through the GraphQL API, not `git commit` plus # `git push`: GitHub signs commits it creates on the caller's behalf, so # the bot's commits land verified. Locally made ones are unsigned (#159). # Stage exactly the paths this job owns, then read the staged status back: # that picks up the untracked changeset file alongside the regenerated # defaults, and normalizes both into a path list. git add -- packages/runtimes/src/internal/defaults/ .changeset/update-runtime-defaults.md additions='[]' while IFS= read -r -d '' path; do additions=$(jq -c --arg path "$path" --arg contents "$(base64 -w0 <"$path")" \ '. + [{path: $path, contents: $contents}]' <<<"$additions") done < <(git diff --cached --name-only -z --diff-filter=d) deletions='[]' while IFS= read -r -d '' path; do deletions=$(jq -c --arg path "$path" '. + [{path: $path}]' <<<"$deletions") done < <(git diff --cached --name-only -z --diff-filter=D) if [ "$additions" = '[]' ] && [ "$deletions" = '[]' ]; then echo "::notice::Nothing staged for $BRANCH" exit 0 fi # createCommitOnBranch cannot force-push, so reset the branch pointer to # the current base tip first — the old `git push --force` semantics of one # fresh commit on top of main. Moving a ref creates no commit, so nothing # unsigned enters history. base_oid=$(gh api "repos/$REPO/git/ref/heads/$BASE_BRANCH" --jq '.object.sha') if gh api "repos/$REPO/git/ref/heads/$BRANCH" >/dev/null 2>&1; then gh api -X PATCH "repos/$REPO/git/refs/heads/$BRANCH" \ -f sha="$base_oid" -F force=true >/dev/null else gh api -X POST "repos/$REPO/git/refs" \ -f ref="refs/heads/$BRANCH" -f sha="$base_oid" >/dev/null fi jq -n \ --arg repo "$REPO" \ --arg branch "$BRANCH" \ --arg oid "$base_oid" \ --arg headline "$HEADLINE" \ --arg body "$SIGNOFF" \ --argjson additions "$additions" \ --argjson deletions "$deletions" \ '{ query: "mutation($input: CreateCommitOnBranchInput!) { createCommitOnBranch(input: $input) { commit { oid url } } }", variables: { input: { branch: { repositoryNameWithOwner: $repo, branchName: $branch }, message: { headline: $headline, body: $body }, expectedHeadOid: $oid, fileChanges: { additions: $additions, deletions: $deletions } } } }' \ | gh api graphql --input - --jq '.data.createCommitOnBranch.commit.url' gh pr create \ --base "$BASE_BRANCH" \ --head "$BRANCH" \ --title "$HEADLINE" \ --body "Automated daily refresh of the bundled Node.js, Bun and Deno version snapshots from the upstream release feeds." \ || echo "::notice::PR already open for $BRANCH" gh pr merge "$BRANCH" --auto --squash