name: Build on: workflow_call: inputs: runs-on: required: true type: string runs-on-name: required: true type: string secrets: CODECOV_TOKEN: required: false env: CI: 1 TURBO_TELEMETRY_DISABLED: 1 jobs: get-merge-base: permissions: {} runs-on: lynx-ubuntu-26.04-medium timeout-minutes: 5 env: # We have 2 cases: # 1. Pull request # 2. Merge group BASE_REF: ${{ github.base_ref || github.event.merge_group.base_ref }} HEAD_REF: ${{ github.head_ref || github.event.merge_group.head_ref }} outputs: merge-base: ${{ steps.merge-base.outputs.merge-base }} steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 with: ref: ${{ env.HEAD_REF }} repository: ${{ github.event.pull_request.head.repo.full_name || github.repository }} persist-credentials: false - name: Disable local Git maintenance run: git config --local maintenance.auto false # Set up common variables for git operations - name: Setup git refs id: git-refs run: | # Strip refs/heads/ prefix if it exists BASE_REF_CLEAN=${BASE_REF#refs/heads/} HEAD_REF_CLEAN=${HEAD_REF#refs/heads/} echo "base-ref=$BASE_REF_CLEAN" >> $GITHUB_OUTPUT echo "head-ref=$HEAD_REF_CLEAN" >> $GITHUB_OUTPUT # Modified from https://github.com/rmacklin/fetch-through-merge-base - name: Fetch if: github.event_name != 'push' env: CLEAN_BASE_REF: ${{ steps.git-refs.outputs.base-ref }} CLEAN_HEAD_REF: ${{ steps.git-refs.outputs.head-ref }} UPSTREAM_REMOTE: ${{ github.server_url }}/${{ github.repository }} run: | git remote add upstream $UPSTREAM_REMOTE git fetch --progress --depth=1 upstream "+refs/heads/$CLEAN_BASE_REF:refs/remotes/upstream/$CLEAN_BASE_REF" MAX_ATTEMPTS=10 ATTEMPT=0 while [ -z "$( git merge-base "refs/remotes/upstream/$CLEAN_BASE_REF" "$CLEAN_HEAD_REF" )" ] && [ "$ATTEMPT" -lt "$MAX_ATTEMPTS" ]; do git fetch -q --deepen=10 upstream "refs/heads/$CLEAN_BASE_REF:refs/remotes/upstream/$CLEAN_BASE_REF" git fetch -q --deepen=10 origin "$CLEAN_HEAD_REF" ATTEMPT=$((ATTEMPT + 1)) done if [ "$ATTEMPT" -ge "$MAX_ATTEMPTS" ]; then echo "Failed to determine merge base after $MAX_ATTEMPTS attempts." >&2 exit 1 fi - name: Get merge base id: merge-base env: CLEAN_BASE_REF: ${{ format('upstream/{0}', steps.git-refs.outputs.base-ref) || github.event.base }} CLEAN_HEAD_REF: ${{ steps.git-refs.outputs.head-ref }} run: | echo "merge-base=$(git merge-base "$CLEAN_BASE_REF" "$CLEAN_HEAD_REF" || git rev-parse "$CLEAN_BASE_REF")" >> $GITHUB_OUTPUT build-all: permissions: {} name: Build (${{ inputs.runs-on-name }}) runs-on: ${{ inputs.runs-on }} timeout-minutes: 45 needs: get-merge-base env: # `turbo-v4` matches the saved caches; anything else matches nothing, # which is how a push to `main` starts from an empty cache. TURBO_RESTORE_PREFIX: ${{ github.event_name == 'push' && 'turbo-no-restore' || 'turbo-v4' }} steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 with: # `changeset status --since` runs `git merge-base HEAD`, so the # Ubuntu build -- the only job that publishes to pkg.pr.new -- needs # real history. Growing it after a depth-1 checkout does not work: # HEAD is `refs/pull//merge`, GitHub regenerates that ref whenever # the base moves, and both `--depth ` and `--deepen` then act on # the ref's new tip while HEAD stays detached at the old commit. # Ask for the history up front instead. Every other job, Windows # included, keeps the shallow clone. fetch-depth: ${{ inputs.runs-on == 'lynx-ubuntu-26.04-xlarge' && '0' || '1' }} persist-credentials: false - name: Disable local Git maintenance run: git config --local maintenance.auto false - name: Setup Rust uses: ./.github/actions/rustup with: key: build save-if: ${{ github.ref_name == 'main' }} - uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0 - name: TurboCache uses: lynx-infra/cache@5c6160a6a4c7fca80a2f3057bb9dfc9513fcb732 with: path: .turbo key: turbo-v4-${{ runner.os }}-${{ hashFiles('packages/**/src/**/*.rs') }}-${{ github.sha }} # We can restore caches from: # 1. Previous commit from base branch (merge base or base SHA) # 2. Any cache # # On a push to `main` (`deploy-main.yml`) the prefix below becomes one # nothing is stored under, so this run starts from an empty cache and # saves only what it built. Restoring there is what made the cache # grow without bound: every PR restores main's cache through key 1, so # main carrying the previous generation in and saving it back added a # generation per merge -- 193 merges in three weeks, past the 5 GB the # backend accepts, after which every save fails while still reporting # success and downstream jobs die on a cache miss: # https://github.com/lynx-family/lynx-stack/actions/runs/30186830273/job/89752986590 # # The cold build this costs is on a post-merge run nobody waits on. restore-keys: | ${{ env.TURBO_RESTORE_PREFIX }}-${{ runner.os }}-${{ hashFiles('packages/**/src/**/*.rs') }}-${{ needs.get-merge-base.outputs.merge-base }} ${{ env.TURBO_RESTORE_PREFIX }}-${{ runner.os }}-${{ hashFiles('packages/**/src/**/*.rs') }}-${{ github.event.pull_request.base.sha || github.event.merge_group.base_sha || github.event.push.before }} ${{ env.TURBO_RESTORE_PREFIX }}-${{ runner.os }}-${{ hashFiles('packages/**/src/**/*.rs') }}- ${{ env.TURBO_RESTORE_PREFIX }}-${{ runner.os }}- - name: Install uses: ./.github/actions/pnpm-install with: node-version: "22" save-if: ${{ github.ref_name == 'main' }} - name: Build id: build run: | # `benchx_cli` downloads an 86 MB binary only the benchmark job uses. # `benchmark-*` goes with it -- it depends on `benchx_cli`, so # excluding `benchx_cli` alone is a no-op. Same pair `deploy-main.yml` # uses. pnpm turbo build --summarize --filter '!benchx_cli' --filter '!@lynx-js/benchmark-*' env: NODE_OPTIONS: --max-old-space-size=32768 CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} - name: Upload turbo summary if: runner.debug == '1' uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7 with: name: turbo-summary-${{ github.sha }} path: .turbo/runs/*.json retention-days: 1 overwrite: true include-hidden-files: true # Publish PR previews to pkg.pr.new. Only runs on the Ubuntu build, and # only when the PR adds a changeset that actually # bumps a publishable package. Fork PRs are included: this is a # `pull_request` (not `pull_request_target`) workflow, so fork runs use # a read-only token with no base-repo secrets, and are gated by the # repo's required-approval setting — the same trust boundary the Build # step above (which already runs fork install/build scripts) relies on. - name: Collect packages with changesets id: changeset if: > inputs.runs-on == 'lynx-ubuntu-26.04-xlarge' && github.event_name == 'pull_request' env: MERGE_BASE: ${{ needs.get-merge-base.outputs.merge-base }} # The merge base is already computed by the `get-merge-base` job, so # pass that SHA straight to `--since` instead of resolving `origin/` # here. History comes from the `fetch-depth` above. run: | pnpm changeset status --since="$MERGE_BASE" --output .changeset-status.json PACKAGE_DIRS=$(node .github/scripts/list-changeset-packages.cjs .changeset-status.json | tr '\n' ' ') if [ -z "$(echo "$PACKAGE_DIRS" | tr -d '[:space:]')" ]; then echo "No publishable packages affected by changesets; skipping pkg.pr.new publish." echo "skip=true" >> "$GITHUB_OUTPUT" exit 0 fi echo "Publishing the following package directories to pkg.pr.new:" printf ' %s\n' $PACKAGE_DIRS { echo "skip=false" echo "package-dirs<> "$GITHUB_OUTPUT" - name: Publish to pkg.pr.new if: steps.changeset.outputs.skip == 'false' env: PACKAGE_DIRS: ${{ steps.changeset.outputs.package-dirs }} # zizmor: ignore[use-trusted-publishing] pkg.pr.new authenticates via its own GitHub App, not the npm trusted-publishing flow this heuristic suggests. run: | read -ra package_dirs <<< "$PACKAGE_DIRS" pnpm exec pkg-pr-new publish \ --compact \ --pnpm \ --previewVersion \ --peerDeps \ --commentWithSha \ --packageManager=pnpm \ --no-template \ "${package_dirs[@]}"