| name: zfs-precheck | |
| # Quick checks of a PR's structure, run on one VM ahead of the full test | |
| # matrix. For now the one check is "failing test, then fix": | |
| # | |
| # Verify PRs that add a test demonstrating a bug in one commit and fix the | |
| # bug in a later commit. Each such test commit is built on its own and its | |
| # tests must fail (or crash); the PR head is built and the same tests must | |
| # pass. PRs without this pattern finish after the detect job. | |
| # | |
| # A test commit changes only files under tests/ and adds or modifies a test | |
| # script; see scripts/failfirst-detect.py. | |
| on: | |
| push: | |
| pull_request: | |
| workflow_dispatch: | |
| inputs: | |
| base: | |
| type: string | |
| required: false | |
| default: "" | |
| description: "(optional) Commit or branch the change is based on (default: merge base with openzfs/zfs master)" | |
| os: | |
| type: string | |
| required: false | |
| default: "" | |
| description: "(optional) OS to test on (default: ubuntu24)" | |
| concurrency: | |
| group: >- | |
| ${{ github.workflow }}-${{ github.head_ref || | |
| (github.event_name == 'push' && github.ref) || github.run_id }} | |
| cancel-in-progress: true | |
| env: | |
| HEAD_SHA: ${{ github.event.pull_request.head.sha || github.sha }} | |
| jobs: | |
| detect: | |
| name: Detect | |
| if: github.event_name != 'push' || github.repository != 'openzfs/zfs' | |
| runs-on: ubuntu-24.04 | |
| outputs: | |
| found: ${{ steps.detect.outputs.found }} | |
| labels: ${{ steps.detect.outputs.labels }} | |
| jobs: ${{ steps.detect.outputs.jobs }} | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| ref: ${{ env.HEAD_SHA }} | |
| fetch-depth: 0 | |
| - name: Find test commits | |
| id: detect | |
| env: | |
| PR_BASE: ${{ github.event.pull_request.base.sha }} | |
| INPUT_BASE: ${{ github.event.inputs.base }} | |
| UPSTREAM: ${{ vars.FAILFIRST_UPSTREAM || 'https://github.com/openzfs/zfs' }} | |
| run: | | |
| if [ -n "$PR_BASE" ]; then | |
| base="$PR_BASE" | |
| elif [ -n "$INPUT_BASE" ]; then | |
| base=$(git rev-parse --verify -q "$INPUT_BASE^{commit}" || | |
| git rev-parse --verify "origin/$INPUT_BASE^{commit}") | |
| else | |
| git fetch -q "$UPSTREAM" master | |
| base=FETCH_HEAD | |
| fi | |
| base=$(git merge-base "$base" "$HEAD_SHA") | |
| echo "Commits in $base..$HEAD_SHA" | |
| python3 .github/workflows/scripts/failfirst-detect.py \ | |
| "$base" "$HEAD_SHA" > /tmp/detect.json | |
| jq . /tmp/detect.json | |
| echo "found=$(jq -r .found /tmp/detect.json)" >> $GITHUB_OUTPUT | |
| echo "labels=$(jq -c .labels /tmp/detect.json)" >> $GITHUB_OUTPUT | |
| echo "jobs=$(jq -c .jobs /tmp/detect.json)" >> $GITHUB_OUTPUT | |
| jq -r .summary /tmp/detect.json >> $GITHUB_STEP_SUMMARY | |
| verify: | |
| # A static name: GitHub doesn't evaluate a name that uses the matrix | |
| # when the job is skipped, and appends the matrix value (the label) to | |
| # this one. | |
| name: Verify | |
| needs: [ detect ] | |
| if: needs.detect.outputs.found == 'true' | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| label: ${{ fromJson(needs.detect.outputs.labels) }} | |
| runs-on: ubuntu-24.04 | |
| env: | |
| OS: ${{ github.event.inputs.os || vars.FAILFIRST_OS || 'ubuntu24' }} | |
| ROLE: ${{ fromJson(needs.detect.outputs.jobs)[matrix.label].role }} | |
| REF: ${{ fromJson(needs.detect.outputs.jobs)[matrix.label].ref }} | |
| EXPECT: ${{ fromJson(needs.detect.outputs.jobs)[matrix.label].expect }} | |
| TITLE: ${{ fromJson(needs.detect.outputs.jobs)[matrix.label].title }} | |
| TESTS: ${{ fromJson(needs.detect.outputs.jobs)[matrix.label].tests }} | |
| TIMEOUT: ${{ fromJson(needs.detect.outputs.jobs)[matrix.label].timeout }} | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| ref: ${{ env.HEAD_SHA }} | |
| fetch-depth: 0 | |
| - name: Check out test commit | |
| if: env.ROLE == 'test' | |
| run: | | |
| # Build the test commit, but with the CI scripts of the PR head. | |
| git checkout -q --detach "$REF" | |
| git checkout -q "$HEAD_SHA" -- .github | |
| git log -1 --format='Building %h %s' | |
| - name: Setup QEMU | |
| timeout-minutes: 60 | |
| run: .github/workflows/scripts/qemu-1-setup.sh | |
| - name: Start build machine | |
| timeout-minutes: 10 | |
| run: .github/workflows/scripts/qemu-2-start.sh $OS | |
| - name: Install dependencies | |
| timeout-minutes: 60 | |
| run: .github/workflows/scripts/qemu-3-deps.sh --poweroff $OS | |
| - name: Build modules | |
| timeout-minutes: 30 | |
| run: .github/workflows/scripts/qemu-4-build.sh --poweroff --enable-debug $OS | |
| - name: Setup testing machine | |
| timeout-minutes: 5 | |
| run: | | |
| # One VM is enough to run a handful of tests. | |
| sed -i 's/^VMs=.*/VMs="1"/' /var/tmp/env.txt | |
| .github/workflows/scripts/qemu-5-setup.sh | |
| - name: Run tests | |
| # scales with the number of tests; see failfirst-detect.py | |
| timeout-minutes: ${{ fromJson(env.TIMEOUT) }} | |
| run: | | |
| read -ra tests <<< "$TESTS" | |
| .github/workflows/scripts/failfirst-tests.sh "$EXPECT" "$TITLE" \ | |
| "${tests[@]}" | |
| - name: Prepare artifacts | |
| if: always() | |
| run: | | |
| source /var/tmp/env.txt || exit 0 | |
| scp zfs@vm1:"/var/tmp/*.txt" $RESPATH/vm1 2>/dev/null || true | |
| mkdir -p /tmp/failfirst-result | |
| cp $RESPATH/failfirst/summary.md \ | |
| "/tmp/failfirst-result/$ROLE-$REF.md" || true | |
| sudo tar cjf /tmp/failfirst-logs.tar.bz2 -C $(dirname $RESPATH) \ | |
| $(basename $RESPATH) || true | |
| - uses: actions/upload-artifact@v7 | |
| if: always() | |
| with: | |
| name: failfirst-logs-${{ env.ROLE }}-${{ env.REF }} | |
| path: /tmp/failfirst-logs.tar.bz2 | |
| archive: false | |
| if-no-files-found: ignore | |
| - uses: actions/upload-artifact@v7 | |
| if: always() | |
| with: | |
| name: failfirst-result-${{ env.ROLE }}-${{ env.REF }} | |
| path: /tmp/failfirst-result | |
| if-no-files-found: ignore | |
| verdict: | |
| name: Verdict | |
| needs: [ detect, verify ] | |
| if: always() && needs.detect.result == 'success' | |
| runs-on: ubuntu-24.04 | |
| steps: | |
| - uses: actions/download-artifact@v8 | |
| if: needs.detect.outputs.found == 'true' | |
| with: | |
| pattern: failfirst-result-* | |
| merge-multiple: true | |
| path: results | |
| - name: Summary | |
| env: | |
| FOUND: ${{ needs.detect.outputs.found }} | |
| VERIFY: ${{ needs.verify.result }} | |
| run: | | |
| if [ "$FOUND" != "true" ]; then | |
| echo "No failing test -> fix commit pairs to verify." \ | |
| | tee -a $GITHUB_STEP_SUMMARY | |
| exit 0 | |
| fi | |
| # test commits first, then the head | |
| for f in results/test-*.md results/head-*.md; do | |
| if [ -f "$f" ]; then cat "$f"; fi | |
| done >> $GITHUB_STEP_SUMMARY | |
| if [ "$VERIFY" != "success" ]; then | |
| echo "::error::Verification $VERIFY; see the jobs above." | |
| exit 1 | |
| fi | |
| echo "All test commits fail without their fix and pass with it." \ | |
| | tee -a $GITHUB_STEP_SUMMARY |