diff --git a/.github/actions/install-nix/action.yml b/.github/actions/install-nix/action.yml index 93dcb9ae01..7a5e80dc2a 100644 --- a/.github/actions/install-nix/action.yml +++ b/.github/actions/install-nix/action.yml @@ -15,6 +15,10 @@ inputs: role-to-assume: description: AWS Role to assume when configuring aws credentials, required if push-to-cache is true required: false + single-user: + description: Install Nix in single-user mode, without the Nix daemon, even when systemd is running. Eval-heavy jobs run faster this way. + required: false + default: false runs: using: composite steps: @@ -56,6 +60,7 @@ runs: GITHUB_TOKEN: ${{ github.token }} NIX_SIGN_SECRET_KEY: ${{ inputs.nix-signing-key }} PUSH_TO_CACHE: ${{ steps.resolve-push-to-cache.outputs.value }} + SINGLE_USER: ${{ inputs.single-user }} - name: verify nix in path shell: bash diff --git a/.github/actions/install-nix/setup-nix.sh b/.github/actions/install-nix/setup-nix.sh index d5f9d94c43..e7f0b530e4 100755 --- a/.github/actions/install-nix/setup-nix.sh +++ b/.github/actions/install-nix/setup-nix.sh @@ -3,7 +3,7 @@ readonly version=2.35.3 set -euo pipefail -if systemctl whoami &>/dev/null || [[ $(uname) == Darwin ]]; then +if [[ ${SINGLE_USER:-false} != true ]] && { systemctl whoami &>/dev/null || [[ $(uname) == Darwin ]]; }; then # systemd is running so we can install in multi-user mode # or running on macos daemon=--daemon @@ -15,7 +15,8 @@ if systemctl whoami &>/dev/null || [[ $(uname) == Darwin ]]; then function maybesudo { sudo -H --preserve-env=GITHUB_TOKEN,AWS_REGION,AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY,AWS_SESSION_TOKEN,NIX_SIGN_SECRET_KEY env "$@"; } else - # systemd is *not* running so we must install in single-user mode + # Install in single-user mode: either systemd is *not* running, or the caller asked for it. + # Useful for eval-heavy jobs which run faster without the daemon. daemon=--no-daemon nixconfdir=$HOME/.config/nix path=$HOME/.nix-profile/bin diff --git a/.github/workflows/actions.lock b/.github/workflows/actions.lock index 37043f86ad..6e78fa9fcb 100644 --- a/.github/workflows/actions.lock +++ b/.github/workflows/actions.lock @@ -58,10 +58,13 @@ workflows: '.github/workflows/nix-build.yml': - 'actions/checkout@v7.0.1' - 'actions/download-artifact@v8.0.2' - - 'actions/upload-artifact@v7.0.2' - - 'aws-actions/configure-aws-credentials@v6.3.0' - 'peter-evans/create-or-update-comment@v5.0.0' - 'peter-evans/find-comment@v4.0.0' + '.github/workflows/nix-ci-per-system.yml': + - 'actions/checkout@v7.0.1' + - 'actions/download-artifact@v8.0.2' + - 'actions/upload-artifact@v7.0.2' + - 'aws-actions/configure-aws-credentials@v6.3.0' '.github/workflows/nix-dependency-analysis.yml': - 'actions/checkout@v7.0.1' - 'aws-actions/configure-aws-credentials@v6.3.0' diff --git a/.github/workflows/docker-image-test.yml b/.github/workflows/docker-image-test.yml index 65c585ac44..b9d7fb84f2 100644 --- a/.github/workflows/docker-image-test.yml +++ b/.github/workflows/docker-image-test.yml @@ -21,7 +21,7 @@ permissions: jobs: check-changes: - name: skippable + name: 🐳Changes runs-on: blacksmith-2vcpu-ubuntu-2404 outputs: should_run: ${{ steps.check.outputs.should_run }} @@ -41,7 +41,7 @@ jobs: base_ref: ${{ github.base_ref }} docker-image-test: - name: Test ${{ matrix.name }} + name: 🐳${{ matrix.name }} needs: check-changes if: needs.check-changes.outputs.should_run == 'true' runs-on: large-linux-arm diff --git a/.github/workflows/nix-build.yml b/.github/workflows/nix-build.yml index 19ec0fac70..949e5bd447 100644 --- a/.github/workflows/nix-build.yml +++ b/.github/workflows/nix-build.yml @@ -21,289 +21,44 @@ concurrency: cancel-in-progress: ${{ github.event_name == 'pull_request' }} jobs: - eval: - runs-on: blacksmith-32vcpu-ubuntu-2404 - outputs: - packages_matrix: ${{ steps.gen-matrix.outputs.packages_matrix }} - checks_matrix: ${{ steps.gen-matrix.outputs.checks_matrix }} - steps: - - name: Checkout Repo - uses: actions/checkout@v7.0.1 - - - name: Install nix - uses: $/.github/actions/install-nix - with: - push-to-cache: true - nix-signing-key: ${{ secrets.NIX_SIGN_SECRET_KEY }} - role-to-assume: ${{ secrets.DEV_AWS_ROLE }} - - - name: Push flake inputs to binary cache - continue-on-error: true - run: | - set -euo pipefail - script= - for dir in /etc/nix "$HOME/.config/nix"; do - if [[ -x $dir/upload-to-cache.sh ]]; then - script=$dir/upload-to-cache.sh - break - fi - done - if [[ -z $script ]]; then - exit 0 - fi - cmd=() - if [[ ! -O $script ]]; then - cmd=(sudo -H) - fi - # xargs appends the store paths as args; the script reads them space-separated from OUT_PATHS - # shellcheck disable=SC2016 - cmd+=(bash -c 'OUT_PATHS=$* exec "$0"' "$script") - nix flake archive --json \ - | jq -r '.inputs | .. | .path? // empty' \ - | sort -u \ - | xargs --no-run-if-empty "${cmd[@]}" - - - name: Generate Build Matrix - id: gen-matrix - run: | - nix run .#github-matrix -- --eval-output=eval.json checks legacyPackages - echo eval.json: - jq -S . eval.json - nix run .#github-matrix -- --eval-input checks legacyPackages "/tmp/drvpaths/$system.json" - done - - - name: Upload drvPaths artifact - if: github.event_name == 'pull_request' || github.event_name == 'merge_group' - uses: actions/upload-artifact@v7.0.2 - with: - name: drvpaths - path: /tmp/drvpaths/*.json - retention-days: ${{ github.event_name == 'merge_group' && 90 || 1 }} - - builds-aarch64-linux: - name: ${{ matrix.name }}${{ matrix.postgresql_version || '' }} - needs: eval - runs-on: ${{ matrix.runs_on.group && matrix.runs_on || matrix.runs_on.labels }} - if: ${{ fromJSON(needs.eval.outputs.packages_matrix).aarch64_linux != null }} - strategy: - fail-fast: false - max-parallel: 25 - matrix: ${{ fromJSON(needs.eval.outputs.packages_matrix).aarch64_linux }} - steps: - - name: Checkout Repo - if: ${{ matrix.attr != '' }} - uses: actions/checkout@v7.0.1 - - name: Install nix - if: ${{ matrix.attr != '' }} - uses: $/.github/actions/install-nix - with: - push-to-cache: true - nix-signing-key: ${{ secrets.NIX_SIGN_SECRET_KEY }} - role-to-assume: ${{ secrets.DEV_AWS_ROLE }} - - name: nix build - if: ${{ matrix.attr != '' }} - uses: $/.github/actions/nix-build-retry - with: - attr: .#${{ matrix.attr }} - - checks-aarch64-linux: - name: ${{ matrix.name }}${{ matrix.postgresql_version || '' }} - needs: - - eval - - builds-aarch64-linux - runs-on: ${{ matrix.runs_on.group && matrix.runs_on || matrix.runs_on.labels }} - if: ${{ fromJSON(needs.eval.outputs.checks_matrix).aarch64_linux != null }} - strategy: - fail-fast: false - max-parallel: 25 - matrix: ${{ fromJSON(needs.eval.outputs.checks_matrix).aarch64_linux }} - steps: - - name: Checkout Repo - if: ${{ matrix.attr != '' }} - uses: actions/checkout@v7.0.1 - - name: Install nix - if: ${{ matrix.attr != '' }} - uses: $/.github/actions/install-nix - with: - push-to-cache: true - nix-signing-key: ${{ secrets.NIX_SIGN_SECRET_KEY }} - role-to-assume: ${{ secrets.DEV_AWS_ROLE }} - - name: nix build - if: ${{ matrix.attr != '' }} - uses: $/.github/actions/nix-build-retry - with: - attr: .#${{ matrix.attr }} - - builds-aarch64-darwin: - name: ${{ matrix.name }}${{ matrix.postgresql_version || '' }} - needs: eval - runs-on: ${{ matrix.attr != '' && matrix.runs_on.group && matrix.runs_on || matrix.runs_on.labels }} - if: ${{ fromJSON(needs.eval.outputs.packages_matrix).aarch64_darwin != null }} - strategy: - fail-fast: false - max-parallel: 25 - matrix: ${{ fromJSON(needs.eval.outputs.packages_matrix).aarch64_darwin }} - steps: - - name: Checkout Repo - if: ${{ matrix.attr != '' }} - uses: actions/checkout@v7.0.1 - - name: Install nix - if: ${{ matrix.attr != '' }} - uses: $/.github/actions/install-nix - with: - push-to-cache: true - nix-signing-key: ${{ secrets.NIX_SIGN_SECRET_KEY }} - role-to-assume: ${{ secrets.DEV_AWS_ROLE }} - - name: nix build - if: ${{ matrix.attr != '' }} - uses: $/.github/actions/nix-build-retry - with: - attr: .#${{ matrix.attr }} - - checks-aarch64-darwin: - name: ${{ matrix.name }}${{ matrix.postgresql_version || '' }} - needs: - - eval - - builds-aarch64-darwin - runs-on: ${{ matrix.attr != '' && matrix.runs_on.group && matrix.runs_on || matrix.runs_on.labels }} - if: ${{ fromJSON(needs.eval.outputs.checks_matrix).aarch64_darwin != null }} - strategy: - fail-fast: false - max-parallel: 25 - matrix: ${{ fromJSON(needs.eval.outputs.checks_matrix).aarch64_darwin }} - steps: - - name: Checkout Repo - if: ${{ matrix.attr != '' }} - uses: actions/checkout@v7.0.1 - - name: Install nix - if: ${{ matrix.attr != '' }} - uses: $/.github/actions/install-nix - with: - push-to-cache: true - nix-signing-key: ${{ secrets.NIX_SIGN_SECRET_KEY }} - role-to-assume: ${{ secrets.DEV_AWS_ROLE }} - - name: nix build - if: ${{ matrix.attr != '' }} - uses: $/.github/actions/nix-build-retry - with: - attr: .#${{ matrix.attr }} - - builds-x86_64-linux: - name: ${{ matrix.name }}${{ matrix.postgresql_version || '' }} - needs: eval - runs-on: ${{ matrix.attr != '' && matrix.runs_on.group && matrix.runs_on || matrix.runs_on.labels }} - if: ${{ fromJSON(needs.eval.outputs.packages_matrix).x86_64_linux != null }} - strategy: - fail-fast: false - max-parallel: 25 - matrix: ${{ fromJSON(needs.eval.outputs.packages_matrix).x86_64_linux }} - steps: - - name: Checkout Repo - if: ${{ matrix.attr != '' }} - uses: actions/checkout@v7.0.1 - - name: Install nix - if: ${{ matrix.attr != '' }} - uses: $/.github/actions/install-nix - with: - push-to-cache: true - nix-signing-key: ${{ secrets.NIX_SIGN_SECRET_KEY }} - role-to-assume: ${{ secrets.DEV_AWS_ROLE }} - - name: nix build - if: ${{ matrix.attr != '' }} - uses: $/.github/actions/nix-build-retry - with: - attr: .#${{ matrix.attr }} - - checks-x86_64-linux: - name: ${{ matrix.name }}${{ matrix.postgresql_version || '' }} - needs: - - eval - - builds-x86_64-linux - runs-on: ${{ matrix.attr != '' && matrix.runs_on.group && matrix.runs_on || matrix.runs_on.labels }} - if: ${{ fromJSON(needs.eval.outputs.checks_matrix).x86_64_linux != null }} - strategy: - fail-fast: false - max-parallel: 25 - matrix: ${{ fromJSON(needs.eval.outputs.checks_matrix).x86_64_linux }} - steps: - - name: Checkout Repo - if: ${{ matrix.attr != '' }} - uses: actions/checkout@v7.0.1 - - name: Install nix - if: ${{ matrix.attr != '' }} - uses: $/.github/actions/install-nix - with: - push-to-cache: true - nix-signing-key: ${{ secrets.NIX_SIGN_SECRET_KEY }} - role-to-assume: ${{ secrets.DEV_AWS_ROLE }} - - name: nix build - if: ${{ matrix.attr != '' }} - uses: $/.github/actions/nix-build-retry - with: - attr: .#${{ matrix.attr }} - - checks: - name: Checks ✅ - runs-on: blacksmith-2vcpu-ubuntu-2404 - needs: - - checks-aarch64-darwin - - checks-aarch64-linux - - checks-x86_64-linux - # must always run, otherwise if any of the needs fail then this is skipped and PR is allowed through - # not sure what GH's thinking is there that skipped == passed for the branch protection rule... - # insert Mr Incredible meme -> pass is pass, skipped is not passed, PR should not merge - if: always() - steps: - - name: Check dependent job results - if: contains(needs.*.result, 'cancelled') || contains(needs.*.result, 'failure') || contains(needs.*.result, 'skipped') - run: | - jq -rn --argjson needs '${{ toJSON(needs) }}' '$needs|to_entries[]|select(.value.result!="success")|"::error::"+.key+": "+.value.result' - exit 1 - - amis: - needs: - - builds-aarch64-linux - - builds-x86_64-linux - uses: $/.github/workflows/testinfra-ami-build.yml + aarch64-darwin: + name: 🍎arm + uses: $/.github/workflows/nix-ci-per-system.yml + with: + system: aarch64-darwin secrets: DEV_AWS_ROLE: ${{ secrets.DEV_AWS_ROLE }} NIX_SIGN_SECRET_KEY: ${{ secrets.NIX_SIGN_SECRET_KEY }} - containers: - needs: builds-aarch64-linux - uses: $/.github/workflows/docker-image-test.yml + aarch64-linux: + name: 🐧arm + uses: $/.github/workflows/nix-ci-per-system.yml + with: + system: aarch64-linux secrets: DEV_AWS_ROLE: ${{ secrets.DEV_AWS_ROLE }} NIX_SIGN_SECRET_KEY: ${{ secrets.NIX_SIGN_SECRET_KEY }} - qemu: - needs: builds-aarch64-linux - uses: $/.github/workflows/qemu-image-build.yml + x86_64-linux: + name: 🐧x86 + uses: $/.github/workflows/nix-ci-per-system.yml + with: + system: x86_64-linux secrets: DEV_AWS_ROLE: ${{ secrets.DEV_AWS_ROLE }} NIX_SIGN_SECRET_KEY: ${{ secrets.NIX_SIGN_SECRET_KEY }} check: name: CI ✅ + # must always run, otherwise if any of the needs fail then this is skipped and PR is allowed through + # not sure what GH's thinking is there that skipped == passed for the branch protection rule... + # insert Mr Incredible meme -> pass is pass, skipped is not passed, PR should not merge if: always() runs-on: blacksmith-2vcpu-ubuntu-2404 needs: - - amis - - checks - - containers - - qemu + - aarch64-darwin + - aarch64-linux + - x86_64-linux steps: - name: Check dependent job results if: contains(needs.*.result, 'cancelled') || contains(needs.*.result, 'failure') || contains(needs.*.result, 'skipped') @@ -311,68 +66,12 @@ jobs: jq -rn --argjson needs '${{ toJSON(needs) }}' '$needs|to_entries[]|select(.value.result!="success")|"::error::"+.key+": "+.value.result' exit 1 - version-diff: - name: Package version diff - if: github.event_name == 'pull_request' - needs: - - eval - - builds-x86_64-linux - - builds-aarch64-linux - strategy: - fail-fast: false - matrix: - include: - - system: x86_64-linux - runs_on: blacksmith-32vcpu-ubuntu-2404 - - system: aarch64-linux - runs_on: blacksmith-4vcpu-ubuntu-2404-arm - runs-on: ${{ matrix.runs_on }} - steps: - - name: Checkout PR head - uses: actions/checkout@v7.0.1 - with: - path: head - - - name: Checkout PR base - uses: actions/checkout@v7.0.1 - with: - ref: ${{ github.event.pull_request.base.sha }} - path: base - - - name: Install nix - uses: $/.github/actions/install-nix - - - name: Download head drvPaths - uses: actions/download-artifact@v8.0.2 - with: - name: drvpaths - path: /tmp/head-drvpaths - - - name: Diff versions with nvd - env: - GH_TOKEN: ${{ github.token }} - BASE_SHA: ${{ github.event.pull_request.base.sha }} - SYSTEM: ${{ matrix.system }} - run: | - # BASE side comes from the merge queue run that evaluated the base commit - run_id=$(gh run list --repo "$GITHUB_REPOSITORY" --workflow nix-build.yml --event merge_group --commit "$BASE_SHA" --status success --limit 1 --json databaseId --jq '.[0].databaseId // empty') - if [[ -n $run_id ]] && gh run download "$run_id" --repo "$GITHUB_REPOSITORY" --name drvpaths --dir /tmp/base-drvpaths; then - ./head/ci/version-diff/diff.sh "$SYSTEM" - else - echo "Baseline unavailable for \`${BASE_SHA:0:9}\`, version diff skipped (no successful merge queue run, or it expired)." >/tmp/diff.txt - fi - - - name: Upload diff artifact - uses: actions/upload-artifact@v7.0.2 - with: - name: diff-${{ matrix.system }} - path: /tmp/diff.txt - retention-days: 7 - version-diff-comment: - name: Post package version diff comment + name: 📦Post version diff comment if: always() && github.event_name == 'pull_request' - needs: version-diff + needs: + - x86_64-linux + - aarch64-linux runs-on: blacksmith-2vcpu-ubuntu-2404 permissions: pull-requests: write diff --git a/.github/workflows/nix-ci-per-system.yml b/.github/workflows/nix-ci-per-system.yml new file mode 100644 index 0000000000..3e76d2f849 --- /dev/null +++ b/.github/workflows/nix-ci-per-system.yml @@ -0,0 +1,239 @@ +name: Nix CI for one system + +# nix-build.yml calls this workflow once per system. +# Each call evaluates only its own system, then builds and checks what isn't cached yet. +# A system's builds start as soon as its own eval finishes, without waiting for the other systems. + +on: + workflow_call: + inputs: + system: + description: Nix system to evaluate, build and check + required: true + type: string + secrets: + DEV_AWS_ROLE: + description: AWS role for the dev environment + required: true + NIX_SIGN_SECRET_KEY: + description: Key used to sign uploads to the Nix binary cache + required: true + +jobs: + eval: + name: ❄️Eval + runs-on: blacksmith-32vcpu-ubuntu-2404 + outputs: + packages_matrix: ${{ steps.gen-matrix.outputs.packages_matrix }} + checks_matrix: ${{ steps.gen-matrix.outputs.checks_matrix }} + steps: + - name: Checkout Repo + uses: actions/checkout@v7.0.1 + + - name: Install nix + uses: $/.github/actions/install-nix + with: + # Eval runs about 25 seconds faster without the Nix daemon. + nix-signing-key: ${{ secrets.NIX_SIGN_SECRET_KEY }} + push-to-cache: true + role-to-assume: ${{ secrets.DEV_AWS_ROLE }} + single-user: true + + # Every system uses the same flake inputs, so one system pushing them is enough. + - name: Push flake inputs to binary cache + if: inputs.system == 'x86_64-linux' + continue-on-error: true + run: | + set -euo pipefail + script= + for dir in /etc/nix "$HOME/.config/nix"; do + if [[ -x $dir/upload-to-cache.sh ]]; then + script=$dir/upload-to-cache.sh + break + fi + done + if [[ -z $script ]]; then + exit 0 + fi + cmd=() + if [[ ! -O $script ]]; then + cmd=(sudo -H) + fi + # xargs appends the store paths as args; the script reads them space-separated from OUT_PATHS + # shellcheck disable=SC2016 + cmd+=(bash -c 'OUT_PATHS=$* exec "$0"' "$script") + nix flake archive --json \ + | jq -r '.inputs | .. | .path? // empty' \ + | sort -u \ + | xargs --no-run-if-empty "${cmd[@]}" + + - name: Generate Build Matrix + id: gen-matrix + env: + SYSTEM: ${{ inputs.system }} + run: | + nix run .#github-matrix -- --system "$SYSTEM" --eval-output=eval.json checks legacyPackages + echo eval.json: + jq -S . eval.json + nix run .#github-matrix -- --system "$SYSTEM" --eval-input checks legacyPackages "/tmp/drvpaths/$SYSTEM.json" + + - name: Upload drvPaths artifact + if: github.event_name == 'pull_request' || github.event_name == 'merge_group' + uses: actions/upload-artifact@v7.0.2 + with: + name: drvpaths-${{ inputs.system }} + path: /tmp/drvpaths/${{ inputs.system }}.json + retention-days: ${{ github.event_name == 'merge_group' && 90 || 1 }} + + builds: + name: ❄️🔨${{ matrix.name }}${{ matrix.postgresql_version && format(' {0}', matrix.postgresql_version) || '' }} ${{ inputs.system == 'aarch64-darwin' && '🍎arm' || inputs.system == 'aarch64-linux' && '🐧arm' || '🐧x86' }} + needs: eval + runs-on: ${{ matrix.attr != '' && matrix.runs_on.group && matrix.runs_on || matrix.runs_on.labels }} + strategy: + fail-fast: false + max-parallel: 25 + matrix: ${{ fromJSON(needs.eval.outputs.packages_matrix) }} + steps: + - name: Checkout Repo + if: ${{ matrix.attr != '' }} + uses: actions/checkout@v7.0.1 + - name: Install nix + if: ${{ matrix.attr != '' }} + uses: $/.github/actions/install-nix + with: + push-to-cache: true + nix-signing-key: ${{ secrets.NIX_SIGN_SECRET_KEY }} + role-to-assume: ${{ secrets.DEV_AWS_ROLE }} + - name: nix build + if: ${{ matrix.attr != '' }} + uses: $/.github/actions/nix-build-retry + with: + attr: .#${{ matrix.attr }} + + checks: + name: ❄️🧪${{ matrix.name }}${{ matrix.postgresql_version && format(' {0}', matrix.postgresql_version) || '' }} ${{ inputs.system == 'aarch64-darwin' && '🍎arm' || inputs.system == 'aarch64-linux' && '🐧arm' || '🐧x86' }} + needs: + - eval + - builds + runs-on: ${{ matrix.attr != '' && matrix.runs_on.group && matrix.runs_on || matrix.runs_on.labels }} + strategy: + fail-fast: false + max-parallel: 25 + matrix: ${{ fromJSON(needs.eval.outputs.checks_matrix) }} + steps: + - name: Checkout Repo + if: ${{ matrix.attr != '' }} + uses: actions/checkout@v7.0.1 + - name: Install nix + if: ${{ matrix.attr != '' }} + uses: $/.github/actions/install-nix + with: + push-to-cache: true + nix-signing-key: ${{ secrets.NIX_SIGN_SECRET_KEY }} + role-to-assume: ${{ secrets.DEV_AWS_ROLE }} + - name: nix build + if: ${{ matrix.attr != '' }} + uses: $/.github/actions/nix-build-retry + with: + attr: .#${{ matrix.attr }} + + amis: + needs: builds + if: inputs.system != 'aarch64-darwin' + uses: $/.github/workflows/testinfra-ami-build.yml + with: + system: ${{ inputs.system }} + secrets: + DEV_AWS_ROLE: ${{ secrets.DEV_AWS_ROLE }} + NIX_SIGN_SECRET_KEY: ${{ secrets.NIX_SIGN_SECRET_KEY }} + + containers: + needs: builds + if: inputs.system == 'aarch64-linux' + uses: $/.github/workflows/docker-image-test.yml + secrets: + DEV_AWS_ROLE: ${{ secrets.DEV_AWS_ROLE }} + NIX_SIGN_SECRET_KEY: ${{ secrets.NIX_SIGN_SECRET_KEY }} + + qemu: + needs: builds + if: inputs.system == 'aarch64-linux' + uses: $/.github/workflows/qemu-image-build.yml + secrets: + DEV_AWS_ROLE: ${{ secrets.DEV_AWS_ROLE }} + NIX_SIGN_SECRET_KEY: ${{ secrets.NIX_SIGN_SECRET_KEY }} + + version-diff: + name: 📦Version diff + if: github.event_name == 'pull_request' && inputs.system != 'aarch64-darwin' + needs: + - eval + - builds + # The diff is a PR comment, not a gate, so a failure here must not fail the system's CI. + continue-on-error: true + runs-on: ${{ inputs.system == 'aarch64-linux' && 'blacksmith-4vcpu-ubuntu-2404-arm' || 'blacksmith-32vcpu-ubuntu-2404' }} + steps: + - name: Checkout PR head + uses: actions/checkout@v7.0.1 + with: + path: head + + - name: Checkout PR base + uses: actions/checkout@v7.0.1 + with: + ref: ${{ github.event.pull_request.base.sha }} + path: base + + - name: Install nix + uses: $/.github/actions/install-nix + + - name: Download head drvPaths + uses: actions/download-artifact@v8.0.2 + with: + name: drvpaths-${{ inputs.system }} + path: /tmp/head-drvpaths + + - name: Diff versions with nvd + env: + GH_TOKEN: ${{ github.token }} + BASE_SHA: ${{ github.event.pull_request.base.sha }} + SYSTEM: ${{ inputs.system }} + run: | + # BASE side comes from the merge queue run that evaluated the base commit + run_id=$(gh run list --repo "$GITHUB_REPOSITORY" --workflow nix-build.yml --event merge_group --commit "$BASE_SHA" --status success --limit 1 --json databaseId --jq '.[0].databaseId // empty') + # Runs from before the per-system split upload one "drvpaths" artifact for both Linux systems. + # Drop that fallback once those merge queue artifacts have expired (90 days). + found=false + if [[ -n $run_id ]]; then + for name in "drvpaths-$SYSTEM" drvpaths; do + if gh run download "$run_id" --repo "$GITHUB_REPOSITORY" --name "$name" --dir /tmp/base-drvpaths; then + found=true + break + fi + done + fi + if [[ $found == true ]]; then + ./head/ci/version-diff/diff.sh "$SYSTEM" + else + echo "Baseline unavailable for \`${BASE_SHA:0:9}\`, version diff skipped (no successful merge queue run, or it expired)." >/tmp/diff.txt + fi + + - name: Upload diff artifact + uses: actions/upload-artifact@v7.0.2 + with: + name: diff-${{ inputs.system }} + path: /tmp/diff.txt + retention-days: 7 diff --git a/.github/workflows/qemu-image-build.yml b/.github/workflows/qemu-image-build.yml index 66b14105e0..9bc9a5783f 100644 --- a/.github/workflows/qemu-image-build.yml +++ b/.github/workflows/qemu-image-build.yml @@ -41,6 +41,7 @@ permissions: jobs: build: + name: 🦤17 ${{ inputs.arch == 'amd64' && '🐧x86' || '🐧arm' }} runs-on: ${{ inputs.arch == 'amd64' && 'blacksmith-16vcpu-ubuntu-2404' || 'arm-native-runner' }} env: # only builds pg17 atm diff --git a/.github/workflows/testinfra-ami-build.yml b/.github/workflows/testinfra-ami-build.yml index 018c2cf83a..4571a3c87b 100644 --- a/.github/workflows/testinfra-ami-build.yml +++ b/.github/workflows/testinfra-ami-build.yml @@ -2,6 +2,12 @@ name: Testinfra Integration Tests on: workflow_call: + inputs: + system: + description: Build only the AMIs for this Nix system (x86_64-linux or aarch64-linux); empty builds both + required: false + default: "" + type: string secrets: DEV_AWS_ROLE: description: "AWS role for dev environment" @@ -22,6 +28,7 @@ jobs: # counting as skipped. build only gets the AMIs whose ami-test-stamp is not in the binary cache yet, # and is skipped entirely when every stamp is cached. gen-matrix: + name: ☁️Matrix runs-on: blacksmith-2vcpu-ubuntu-2404 outputs: matrix: ${{ steps.gen-matrix.outputs.matrix }} @@ -44,6 +51,7 @@ jobs: env: CACHE_URL: https://nix-postgres-artifacts.s3.amazonaws.com GIT_SHA: ${{ github.sha }} + ONLY_SYSTEM: ${{ inputs.system }} PACKAGES_GIT_SHA: ${{ steps.resolve-git-sha.outputs.sha }} run: | set -euo pipefail @@ -61,6 +69,9 @@ jobs: for version in $versions; do for target in amd64:x86_64-linux:blacksmith-2vcpu-ubuntu-2404 arm64:aarch64-linux:blacksmith-2vcpu-ubuntu-2404-arm; do IFS=: read -r arch system runner <<<"$target" + if [[ -n $ONLY_SYSTEM && $system != "$ONLY_SYSTEM" ]]; then + continue + fi stamp=$(nix eval --raw ".#packages.$system.ami-test-stamp-$version") if [[ $check_cache == true ]] && nix path-info --store "$CACHE_URL" "$stamp" &>/dev/null; then echo "::notice::$version-$arch: already passed testinfra ($stamp), skipping" @@ -77,7 +88,8 @@ jobs: echo "matrix=$matrix" >>"$GITHUB_OUTPUT" echo "should_run=$should_run" >>"$GITHUB_OUTPUT" - build: + ami: + name: ☁️${{ matrix.postgres_version }} ${{ matrix.system == 'aarch64-linux' && '🐧arm' || '🐧x86' }} needs: gen-matrix if: needs.gen-matrix.outputs.should_run == 'true' strategy: @@ -203,7 +215,8 @@ jobs: run: ci/cleanup-ami-build-resources.sh --delete-amis "${{ matrix.postgres_version }}-${{ matrix.arch }}-${{ github.run_id }}" report-disk-usage: - needs: build + name: ☁️Disk Usage + needs: ami runs-on: blacksmith-2vcpu-ubuntu-2404 steps: - name: Download AMI disk usage diff --git a/nix/packages/github-matrix/github_matrix.py b/nix/packages/github-matrix/github_matrix.py index 11c07089db..0c089ca21c 100755 --- a/nix/packages/github-matrix/github_matrix.py +++ b/nix/packages/github-matrix/github_matrix.py @@ -67,8 +67,28 @@ class NixEvalError(TypedDict): error: str +def build_select_expr(flake_outputs: List[str], system: Optional[System]) -> str: + """Build the --select expression that picks which flake outputs to evaluate. + + With a system, only that system's part of each output is evaluated. + Attribute names stay the same either way, for example checks.x86_64-linux.foo. + """ + + if system is None: + attrs = f"inherit (outputs) {' '.join(flake_outputs)};" + else: + attrs = " ".join( + f"{output}.{system} = outputs.{output}.{system};" + for output in flake_outputs + ) + return f"outputs: {{ {attrs} }}" + + def build_nix_eval_command( - max_workers: int, max_memory_size: int, flake_outputs: List[str] + max_workers: int, + max_memory_size: int, + flake_outputs: List[str], + system: Optional[System] = None, ) -> List[str]: """Build the nix-eval-jobs command with appropriate flags.""" nix_eval_cmd = [ @@ -89,11 +109,40 @@ def build_nix_eval_command( "--workers", str(max_workers), "--select", - f"outputs: {{ inherit (outputs) {' '.join(flake_outputs)}; }}", + build_select_expr(flake_outputs, system), ] return nix_eval_cmd +def select_system_matrices( + packages_output: Dict[str, Dict[str, List[GitHubActionPackage]]], + checks_output: Dict[str, Dict[str, List[GitHubActionPackage]]], + system: System, +) -> Tuple[ + Dict[str, List[GitHubActionPackage]], + Dict[str, List[GitHubActionPackage]], + List[str], +]: + """Pick one system's packages and checks matrices from the per-system outputs. + + Also returns the other systems that have real jobs. + Jobs are grouped by their derivation's system, so an attribute under one system can hold a derivation for another. + Those jobs are not in the returned matrices, and no other system's eval sees them, so the caller should fail. + """ + key = system.replace("-", "_") + others: List[str] = sorted( + { + job["system"] + for output in (packages_output, checks_output) + for other, matrix in output.items() + if other != key + for job in matrix["include"] + if job["attr"] != "" + } + ) + return packages_output[key], checks_output[key], others + + def parse_nix_eval_line( line: str, drv_paths: Set[str] ) -> Result[Optional[NixEvalJobsOutput], NixEvalError]: @@ -301,6 +350,11 @@ def main() -> None: type=argparse.FileType("w"), help="Store eval json output to file and exit", ) + parser.add_argument( + "--system", + choices=get_args(System), + help="Evaluate only this system, and output that system's matrices directly instead of a map of all systems", + ) parser.add_argument( "flake_outputs", nargs="+", help="Nix flake outputs to evaluate" ) @@ -314,6 +368,7 @@ def main() -> None: args.nb_eval_jobs_workers, args.max_memory_size, args.flake_outputs, + args.system, ) nix_eval_output, warnings_list = run_nix_eval_jobs(cmd) if warnings_list: @@ -416,11 +471,27 @@ def clean_package_for_output(pkg: NixEvalJobsOutput) -> GitHubActionPackage: if errors_list: sys.exit(1) - else: - set_output("packages_matrix", json.dumps(gh_output["packages"])) - set_output("checks_matrix", json.dumps(gh_output["checks"])) - print("Generated GitHub Actions matrix:") - json.dumps(gh_output, indent=2) + elif args.system: + packages, checks, others = select_system_matrices( + packages_output, + checks_output, + args.system, + ) + if others: + # These jobs would never be built: they are not in this matrix, and other systems don't evaluate them. + others = ", ".join(others) + error( + f"Evaluated {args.system} but found jobs whose derivations are for {others}. " + "No eval builds them, so move them under their own system's outputs.", + title="Jobs for another system", + ) + sys.exit(1) + gh_output = {"packages": packages, "checks": checks} + + set_output("packages_matrix", json.dumps(gh_output["packages"])) + set_output("checks_matrix", json.dumps(gh_output["checks"])) + print("Generated GitHub Actions matrix:") + json.dumps(gh_output, indent=2) if __name__ == "__main__": diff --git a/nix/packages/github-matrix/tests/test_github_matrix.py b/nix/packages/github-matrix/tests/test_github_matrix.py index 811b432b53..fd84f28ab1 100644 --- a/nix/packages/github-matrix/tests/test_github_matrix.py +++ b/nix/packages/github-matrix/tests/test_github_matrix.py @@ -6,10 +6,12 @@ from github_matrix import ( NixEvalJobsOutput, + build_select_expr, get_runner_for_package, is_extension_pkg, is_virt_pkg, is_large_pkg, + select_system_matrices, sort_pkgs_by_closures, ) @@ -193,3 +195,58 @@ def test_dependency_order(self): result = sort_pkgs_by_closures([pkg1, pkg2]) assert result == [pkg1, pkg2] + + +class TestBuildSelectExpr: + def test_all_systems(self): + assert ( + build_select_expr(["checks", "legacyPackages"], None) + == "outputs: { inherit (outputs) checks legacyPackages; }" + ) + + def test_one_system(self): + assert build_select_expr(["checks", "legacyPackages"], "aarch64-darwin") == ( + "outputs: { checks.aarch64-darwin = outputs.checks.aarch64-darwin; " + "legacyPackages.aarch64-darwin = outputs.legacyPackages.aarch64-darwin; }" + ) + + +class TestSelectSystemMatrices: + @staticmethod + def job(attr, system): + return { + "attr": attr, + "name": attr or "no packages to build", + "system": system, + "runs_on": {"labels": ["ubuntu-latest"]}, + } + + def test_picks_the_system_and_ignores_placeholders(self): + packages = { + "x86_64_linux": { + "include": [self.job("legacyPackages.x86_64-linux.a", "x86_64-linux")] + }, + "aarch64_linux": {"include": [self.job("", "aarch64-linux")]}, + } + checks = { + "x86_64_linux": {"include": [self.job("", "x86_64-linux")]}, + "aarch64_linux": {"include": [self.job("", "aarch64-linux")]}, + } + pkgs, chks, others = select_system_matrices(packages, checks, "x86_64-linux") + assert pkgs == packages["x86_64_linux"] + assert chks == checks["x86_64_linux"] + assert others == [] + + def test_reports_jobs_for_other_systems(self): + packages = { + "x86_64_linux": {"include": [self.job("", "x86_64-linux")]}, + "aarch64_linux": { + "include": [self.job("legacyPackages.x86_64-linux.b", "aarch64-linux")] + }, + } + checks = { + "x86_64_linux": {"include": [self.job("", "x86_64-linux")]}, + "aarch64_linux": {"include": [self.job("", "aarch64-linux")]}, + } + _, _, others = select_system_matrices(packages, checks, "x86_64-linux") + assert others == ["aarch64-linux"]