name: Guard # Checks that run the pipeline's own code, on every pull request with no # path filter, so a change anywhere cannot skip them. on: push: branches: [main] pull_request: branches: [main] workflow_dispatch: permissions: contents: read concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: image-vars: runs-on: ubuntu-latest timeout-minutes: 5 steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: Self-test (a planted undefined variable must be caught) run: scripts/ci/check-image-vars.sh --self-test - name: Every *_IMAGE a script uses is defined run: scripts/ci/check-image-vars.sh # The one image check: no file names an image outside versions.env, and the # two files generated from it (conf/containers.config, docs/versions.md) # are up to date. Each script's self-test plants its faults first. images: runs-on: ubuntu-latest timeout-minutes: 10 steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: Self-test (a literal image in a script, module, workflow or doc, a process with no selector and a stale generated file must be caught) run: scripts/ci/check-images.sh --self-test - name: Self-test of the containers.config generator (a stale tag, a missing or stray selector, a module's own container and a wrong version must be caught) if: ${{ !cancelled() }} # runs even when a step above failed, so each result shows run: scripts/ci/gen-containers-config.sh --self-test - name: No file names an image outside versions.env; generated files are up to date if: ${{ !cancelled() }} # runs even when a step above failed, so each result shows run: scripts/ci/check-images.sh coupled-versions: runs-on: ubuntu-latest timeout-minutes: 5 steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: Self-test (a VEP cache, pypgx bundle, AnnotSV or Yleaf data version, GENCODE release or VerifyBamID panel that left its image, and a lone PCGR variable, must be caught) run: scripts/ci/check-coupled-versions.sh --self-test - name: Each data version in versions.env matches the image it belongs to if: ${{ !cancelled() }} # runs even when a step above failed, so each result shows run: scripts/ci/check-coupled-versions.sh fake-docker: runs-on: ubuntu-latest timeout-minutes: 15 steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: Self-test (a swallowed empty image, an unknown option and a failing case must be caught) run: scripts/ci/run-fake-docker-suite.sh --self-test - name: setup.sh, validate-setup.sh and run-all.sh against a fake docker run: scripts/ci/run-fake-docker-suite.sh helper-binaries: runs-on: ubuntu-latest timeout-minutes: 20 steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: Self-test (planted bgzip/tabix calls behind if !, time and VAR=, and an orad option orad does not list, must be caught) run: scripts/ci/check-container-helpers.sh --self-test # tests/test_exec_bits.sh (unit-tests) plants a helper without the bit. - name: Every bin/ helper the pipeline calls by name is executable run: scripts/ci/check-exec-bits.sh - name: Table of helper calls derived from scripts and modules if: ${{ !cancelled() }} # runs even when a step above failed, so each result shows run: scripts/ci/check-container-helpers.sh --list - name: Each helper binary exists in the image that calls it run: scripts/ci/check-container-helpers.sh - name: Every option step 01 passes to orad is in the pinned orad's --help if: ${{ !cancelled() }} # runs even when a step above failed, so each result shows run: scripts/ci/check-container-helpers.sh --orad # og for the unit tests (tests/og_binary.py): the tests of a ported tool # and the demo sample builder run og as a subprocess. Built once here, so # the three shards do not each spend minutes of their 10 on it. og: runs-on: ubuntu-latest timeout-minutes: 20 steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: Install the toolchain rust/rust-toolchain.toml pins working-directory: rust run: | channel=$(sed -n 's/^channel = "\(.*\)"$/\1/p' rust-toolchain.toml) rustup toolchain install "$channel" --profile minimal rustc --version - uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3 with: workspaces: rust - name: Build og working-directory: rust run: OG_TREE_HASH=$(./og.sh tree-hash) cargo build --release --locked -p og - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 with: name: og-unit-tests path: rust/target/release/og if-no-files-found: error retention-days: 1 # Three shards: one job ran every test file in about 9.5 of its 10 minutes, # so each new browser test pushed it over. File i runs in shard i % 3, so # every file runs in exactly one shard. unit-tests: needs: og runs-on: ubuntu-latest timeout-minutes: 10 strategy: fail-fast: false matrix: shard: [0, 1, 2] steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 with: name: og-unit-tests path: ${{ runner.temp }}/og - name: og for the tests (OG) run: | chmod 755 "$RUNNER_TEMP/og/og" echo "OG=${RUNNER_TEMP}/og/og" >> "$GITHUB_ENV" # Every tests/test_*.py runs with python3 and every tests/test_*.sh with # bash, found by glob, so a new test file needs no workflow edit. The # two planted failures prove the loop reports a failing test. - name: Run this shard's tests/test_*.py and tests/test_*.sh env: SHARD: ${{ matrix.shard }} SHARDS: 3 run: | # run_tests DIR [SHARD SHARDS]: run the test files of DIR, or only # those whose position in the sorted list is SHARD modulo SHARDS. run_tests() { local dir=$1 shard=${2:-0} shards=${3:-1} t rc i=0 n=0 fail=0 shopt -s nullglob for t in "$dir"/test_*.py "$dir"/test_*.sh; do i=$((i + 1)) [ $(( (i - 1) % shards )) -eq "$shard" ] || continue n=$((n + 1)) rc=0 echo "::group::${t}" case "$t" in *.py) python3 "$t" || rc=$? ;; *.sh) bash "$t" || rc=$? ;; esac echo "::endgroup::" if [ "$rc" -eq 0 ]; then echo "PASS ${t}"; else echo "FAIL ${t} (exit ${rc})"; fail=1; fi done if [ "$n" -eq 0 ]; then echo "ERROR: no test files in ${dir}"; return 1; fi echo "Ran ${n} of ${i} test files in ${dir}." return "$fail" } ctl=$(mktemp -d) mkdir "${ctl}/py" "${ctl}/sh" echo 'assert False, "planted failure"' > "${ctl}/py/test_planted.py" echo 'exit 1' > "${ctl}/sh/test_planted.sh" for d in "${ctl}/py" "${ctl}/sh"; do if run_tests "$d"; then echo "ERROR: a planted failing test in ${d} was reported as passing" exit 1 fi done echo "Control: both planted failures were reported." run_tests tests "$SHARD" "$SHARDS" # OwnGenome's Rust code (rust/, docs/rust.md), in a job of its own: # unit-tests is close to its 10 minutes. Format, lint, unit tests with a # planted failure that must go red, pycompat against CPython, then the two # musl builds as scripts/setup.sh --og makes them and the stale-binary # guard on the real binaries. rust: runs-on: ubuntu-latest timeout-minutes: 20 defaults: run: working-directory: rust steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: Install the toolchain rust/rust-toolchain.toml pins, with rustfmt and clippy run: | channel=$(sed -n 's/^channel = "\(.*\)"$/\1/p' rust-toolchain.toml) rustup toolchain install "$channel" --profile minimal -c rustfmt -c clippy rustc --version - uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3 with: workspaces: rust - name: rustfmt run: cargo fmt --all --check - name: clippy, warnings are errors if: ${{ !cancelled() }} # runs even when a step above failed, so each result shows run: cargo clippy --workspace --all-targets --all-features --locked -- -D warnings - name: Control (the planted failing test must fail, and be the test that failed) run: | log="${RUNNER_TEMP}/planted.log" if cargo test --locked -p pycompat --features planted-failure planted_failure > "$log" 2>&1; then cat "$log" echo "ERROR: the planted failing test passed: the test run would report a broken test as green" exit 1 fi grep -E 'planted_failure.*FAILED' "$log" || { cat "$log"; echo "ERROR: the run failed, but not on the planted test"; exit 1; } echo "Control: the planted test failed, as it must." - name: cargo test run: cargo test --workspace --locked - name: pycompat against CPython (python3 -I in PYTHON_IMAGE, 100000 cases per operation) if: ${{ !cancelled() }} # runs even when a step above failed, so each result shows run: | OG_TREE_HASH=$(./og.sh tree-hash) cargo build --release --locked -p og ../tests/rust/pycompat-diff.sh "${PWD}/target/release/og" 100000 - name: Both musl builds, as scripts/setup.sh --og makes them in OG_BUILDER run: | ../scripts/setup.sh --og ./og.sh check --required file ../bin/.og/og-linux-* ../bin/og version - name: The stale-binary guard refuses the real binaries once rust/ changes run: | echo "// edited" >> og/src/main.rs if out=$(./og.sh check); then echo "ERROR: an edited rust/ passed the check: ${out}"; exit 1; fi echo "Refused, as it must: ${out}" git checkout -- og/src/main.rs ./og.sh check --required # The tests of the og filters steps 04, 05 and 07 run, og chip's (step 49), and the step 25 # tests that compare og prs format with the folders they write by hand: # unit-tests has no og, so there they skip; here OG_REQUIRED turns a # skip into a failure. The step 05 tests run the real step with bin/og. - name: The og filter tests and step 05 with og working-directory: . env: OG: ${{ github.workspace }}/bin/og OG_REQUIRED: 1 run: | fail=0 for t in tests/test_annotsv_sv_inputs.py tests/test_pgx_refblock_fill.py tests/test_pgx_mito_merge.py \ tests/test_annotsv_sv_inputs.sh tests/test_annotsv_postfilter.sh tests/test_annotsv_benign_mane.sh \ tests/test_render_report.py tests/test_collect_summary.py tests/test_chip_report.py; do rc=0 echo "::group::${t}" case "$t" in *.py) python3 "$t" || rc=$? ;; *.sh) bash "$t" || rc=$? ;; esac echo "::endgroup::" if [ "$rc" -eq 0 ]; then echo "PASS ${t}"; else echo "FAIL ${t} (exit ${rc})"; fail=1; fi done exit "$fail" # main.nf runs the same check before any task: a stale og stops # `nextflow run` with the setup command. Without the check, this stub # run completes and the step fails. - uses: actions/setup-java@b843ebf9b913146b38da2eaa7aeddf76074ae1ad # v6.1.0 with: distribution: 'temurin' java-version: '17' - name: The Nextflow version versions.env pins id: nf working-directory: . run: | # shellcheck source=/dev/null . ./versions.env echo "version=${NEXTFLOW_VERSION:?NEXTFLOW_VERSION is not set in versions.env}" >> "$GITHUB_OUTPUT" # Not a Nextflow pin: the version comes from versions.env. Quoted so the # Renovate dry run does not count it as one. - uses: "nf-core/setup-nextflow@893c28b667aedeba26e37f296d260ccc5bc4d914" # v3.0.1 with: version: ${{ steps.nf.outputs.version }} - name: nextflow run stops on a stale og before any task working-directory: . run: | echo "// edited" >> rust/og/src/main.rs rc=0 out=$(timeout 600 nextflow run main.nf -profile test -stub -ansi-log false --outdir "${RUNNER_TEMP}/og-stale" 2>&1) || rc=$? git checkout -- rust/og/src/main.rs if [ "$rc" -eq 0 ] || [ "$rc" -eq 124 ] || [[ "$out" != *"og is stale:"*"run scripts/setup.sh --og"* ]] || [[ "$out" == *"Submitted process"* ]]; then echo "$out" echo "ERROR: nextflow run did not stop on a stale og before any task (exit ${rc})" exit 1 fi echo "Refused, as it must (exit ${rc}): $(grep 'og is stale' <<< "$out")" # The parity harness (tests/parity/README.md): every og port against the # Python it replaced, by meaning. First the harness's own self-test (each # planted kind of difference must be reported, by oracle-diff.sh, by # og dev parity-compare and by bin/og's shadow mode), then every case of # tests/parity/cases.tsv with the oracle in its production image, then # tests/test_fixitfelix.sh with og. parity: runs-on: ubuntu-latest timeout-minutes: 20 steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: Install the toolchain rust/rust-toolchain.toml pins working-directory: rust run: | channel=$(sed -n 's/^channel = "\(.*\)"$/\1/p' rust-toolchain.toml) rustup toolchain install "$channel" --profile minimal rustc --version - uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3 with: workspaces: rust - name: Build og working-directory: rust run: | OG_TREE_HASH=$(./og.sh tree-hash) cargo build --release --locked -p og echo "OG=${PWD}/target/release/og" >> "$GITHUB_ENV" - name: The harness's self-test (planted differences must each be reported) run: scripts/ci/oracle-diff.sh --self-test - name: og against the Python it replaced, every case of tests/parity/cases.tsv if: ${{ !cancelled() }} # runs even when the self-test failed, so each result shows run: scripts/ci/oracle-diff.sh - name: tests/test_fixitfelix.sh with og if: ${{ !cancelled() }} run: bash tests/test_fixitfelix.sh # The one check the ruleset requires for this workflow: it runs even when a # job above failed or was skipped, and fails unless every one succeeded. ci-ok: if: always() needs: [image-vars, images, coupled-versions, fake-docker, helper-binaries, og, unit-tests, rust, parity] runs-on: ubuntu-latest timeout-minutes: 5 steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: Every Guard job succeeded, and every job is listed in needs env: RESULTS: ${{ toJSON(needs) }} run: | echo "$RESULTS" | jq -r 'to_entries[] | "\(.key): \(.value.result)"' bad=$(echo "$RESULTS" | jq -r '[to_entries[] | select(.value.result != "success") | .key] | join(", ")') if [ -n "$bad" ]; then echo "FAIL: not successful: ${bad}" exit 1 fi # A job added above but not to needs would never block a merge. jobs=$(sed -n '/^jobs:/,$ s/^ \([A-Za-z0-9_-]*\):$/\1/p' .github/workflows/guard.yml | grep -vx ci-ok | sort) listed=$(echo "$RESULTS" | jq -r 'keys[]' | sort) if [ "$jobs" != "$listed" ]; then echo "FAIL: ci-ok needs must list every job in guard.yml" diff <(echo "$jobs") <(echo "$listed") || true exit 1 fi echo "OK: all $(echo "$RESULTS" | jq length) Guard jobs succeeded"