diff --git a/.github/actions/nix/action.yaml b/.github/actions/nix/action.yaml index c342eb47..0e80a8d3 100644 --- a/.github/actions/nix/action.yaml +++ b/.github/actions/nix/action.yaml @@ -5,6 +5,9 @@ inputs: kvm: description: Make /dev/kvm usable and tell nix that this machine can run NixOS tests default: "false" + cache: + description: Restore the nix store from the cache, and save it when the job ends + default: "true" runs: using: composite @@ -37,7 +40,11 @@ runs: extra_nix_config: | system-features = nixos-test benchmark big-parallel ${{ inputs.kvm == 'true' && 'kvm' || '' }} - - uses: nix-community/cache-nix-action@v7 + # The key is flake.lock, so a job that builds against another nixpkgs (the canary) turns the + # cache off: what it restored would be of no use to it, and what it saved would replace the + # store of the jobs that do use this lock. + - if: inputs.cache == 'true' + uses: nix-community/cache-nix-action@v7 with: primary-key: nix-${{ runner.os }}-${{ hashFiles('flake.lock', '**/Cargo.lock') }} restore-prefixes-first-match: nix-${{ runner.os }}- diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index ffb4a22d..7b35cd2a 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -110,3 +110,99 @@ jobs: name: vm-${{ matrix.suite }}-${{ github.sha }} path: out/ retention-days: 7 + + # The flake follows the tip of nixpkgs-unstable, so KWin and Plasma change under it whenever + # flake.lock moves. Every week, and on a manual run, this job moves nixpkgs to the tip in a copy + # of the checkout and builds every check against it, the VM suites of both tiers included, one + # after the other on one machine, so that komorebi and the guests are built once. When a check + # fails, it opens an issue, or comments on the one that is open. Nothing is pushed: the new lock + # exists only in the copy. + canary: + if: >- + github.repository == 'LGUG2Z/komorebi-for-kde' && + (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') + runs-on: ubuntu-24.04 + timeout-minutes: 360 + permissions: + contents: read + issues: write + steps: + - uses: actions/checkout@v7 + with: + persist-credentials: false + - uses: ./.github/actions/nix + with: + kvm: "true" + cache: "false" + - name: Move nixpkgs to the tip in a copy of the checkout + run: | + cp -a . "$RUNNER_TEMP/canary" + cd "$RUNNER_TEMP/canary" + locked=$(nix eval --raw --inputs-from . nixpkgs#kdePackages.kwin.version) + nix flake update nixpkgs + rev=$(jq -r .nodes.nixpkgs.locked.rev flake.lock) + echo "NIXPKGS_REV=$rev" >>"$GITHUB_ENV" + tip=$(nix eval --raw --inputs-from . nixpkgs#kdePackages.kwin.version) + echo "KWIN=$tip (flake.lock has $locked)" >>"$GITHUB_ENV" + - id: build + name: Build every check against it + working-directory: ${{ runner.temp }}/canary + run: | + failed="$RUNNER_TEMP/canary-failed" + : >"$failed" + # the checks that need no virtual machine, as the lint job lists them, then the suites + # of both tiers, as the discover job lists them + checks=$(nix eval --json .#checks.x86_64-linux --apply builtins.attrNames | + jq -r '(.[] | select(startswith("vm-") | not)), "vm-lib"') + suites=$(nix eval --json .#legacyPackages.x86_64-linux.vmTiers | + jq -r '(.fast // []) + (.slow // []) | .[] | "vm-" + .') + for check in $checks $suites; do + echo "::group::$check" + nix build -L --no-link ".#checks.x86_64-linux.$check" || echo "$check" >>"$failed" + echo "::endgroup::" + done + test ! -s "$failed" + - name: Report + if: always() + env: + BUILD: ${{ steps.build.outcome }} + RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} + run: | + failed="$RUNNER_TEMP/canary-failed" + { + echo "- commit: $GITHUB_SHA" + if [ -n "${NIXPKGS_REV:-}" ]; then + echo "- nixpkgs-unstable:" \ + "[\`${NIXPKGS_REV:0:12}\`](https://github.com/NixOS/nixpkgs/commit/$NIXPKGS_REV)${KWIN:+, with KWin $KWIN}" + else + echo "- nixpkgs-unstable: the update of flake.lock failed" + fi + echo + if [ -s "$failed" ]; then + echo "These failed:" + echo + while read -r check; do echo "- \`$check\`"; done <"$failed" + elif [ "$BUILD" = success ]; then + echo "Every check passed." + else + echo "The job failed before it could build the checks." + fi + echo + echo "The logs are in [the run]($RUN_URL)." + } >"$RUNNER_TEMP/canary.md" + cat "$RUNNER_TEMP/canary.md" >>"$GITHUB_STEP_SUMMARY" + - name: Open or update the canary issue + if: failure() + env: + GH_TOKEN: ${{ github.token }} + run: | + title="Canary: a check fails against the tip of nixpkgs-unstable" + number=$(gh issue list --repo "$GITHUB_REPOSITORY" --state open --limit 1000 \ + --json number,title | + jq -r --arg title "$title" 'map(select(.title == $title)) | first | .number // empty') + if [ -n "$number" ]; then + gh issue comment "$number" --repo "$GITHUB_REPOSITORY" --body-file "$RUNNER_TEMP/canary.md" + else + gh issue create --repo "$GITHUB_REPOSITORY" --title "$title" \ + --body-file "$RUNNER_TEMP/canary.md" + fi diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c4d97c2a..95afe818 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -38,7 +38,8 @@ formatter is a nightly one. `just check` runs everything a change has to pass before it is pushed: the formatting check, clippy with warnings denied, the tests, rustdoc with warnings -denied, and the checks of the bridge. `just fmt` formats the Rust sources, and `nix fmt` every file +denied, the checks of the bridge, and `just lint`: the macros the code does not +use, and actionlint (with shellcheck) over the workflows. `just fmt` formats the Rust sources, and `nix fmt` every file type the repository has. `nix flake check` builds the same checks, plus `cargo deny`, as derivations; on Linux it also boots every VM test, which needs KVM. @@ -115,13 +116,25 @@ nix build .#checks.x86_64-linux.kwin-effect-geometry-change-komorebi-install [`ci.yaml`](.github/workflows/ci.yaml) runs on every pull request and on every push to `master`, `feature/*` and `hotfix/*`, in this repository only. The -`lint` job builds every check that needs no virtual machine and runs the -repository's own lint rules, `cargo-deny` checks licenses and advisories, and +`lint` job builds every check that needs no virtual machine and runs +`just lint`, `cargo-deny` checks licenses and advisories, and the VM tests run on KVM in two jobs: `vm-fast` on every pull request and `vm-slow` on `master`, every week, and on pull requests labeled `ci:vm-slow`. A weekly [workflow](.github/workflows/update-flake-lock.yaml) opens a pull request that moves `flake.lock`, and the same jobs run on it. +The flake follows the tip of nixpkgs-unstable, so KWin and Plasma change +whenever `flake.lock` moves. The `canary` job of `ci.yaml` runs every week, and +when the workflow is started by hand: it runs `nix flake update nixpkgs` in a +copy of the checkout and builds every check against the result, the VM suites +of both tiers included. When a check fails, it opens an issue titled "Canary: a +check fails against the tip of nixpkgs-unstable" with the failed checks, the +nixpkgs revision and its KWin version, or comments on that issue if it is +still open. The job changes nothing in the repository. To reproduce a failure, +run `nix flake update nixpkgs` in a checkout and build the check the issue +names (`just vm NAME` for a VM suite). The fix goes in a commit of its own; +nixpkgs is not pinned back. + ## Commits Commit messages follow the diff --git a/docs/dev/DESIGN.md b/docs/dev/DESIGN.md index 8a1815e5..306566d5 100644 --- a/docs/dev/DESIGN.md +++ b/docs/dev/DESIGN.md @@ -783,3 +783,13 @@ daemon that stops on its own unregisters its keys, but one that crashes or is ki and the next start may never come. So the NixOS module's unit runs `komorebic hotkeys release` after the daemon stops, however it stops (`ExecStopPost`), and a start takes over what is still registered. + +## Why does a weekly job build against the tip of nixpkgs? + +Because KWin and Plasma come from nixpkgs, and the flake follows the tip of nixpkgs-unstable +rather than a release branch, so a new KWin or Plasma arrives whenever `flake.lock` moves. +Only the VM tests can notice what a new KWin changes, and the pull request that moves the +lock every week runs the slow tier only when it is labeled. The canary job builds every +check, both VM tiers included, against the tip every week, without changing the repository, +and opens an issue when one fails, so that a break is known before the lock moves to it. A +break is fixed in a commit of its own rather than by pinning nixpkgs back. diff --git a/docs/dev/vm-tests.md b/docs/dev/vm-tests.md index aa71f603..f5fef97b 100644 --- a/docs/dev/vm-tests.md +++ b/docs/dev/vm-tests.md @@ -10,6 +10,7 @@ they are laid out, how to run them, and how to add one. | Where | How | Accelerator | |---|---|---| | CI, `x86_64-linux` | `nix build -L .#checks.x86_64-linux.vm-NAME` | KVM | +| CI, `x86_64-linux`, the weekly canary | the same, with nixpkgs moved to the tip of nixpkgs-unstable | KVM | | A Linux machine with KVM | `just vm NAME` | KVM | | A Mac | `just vm NAME`, which runs `scripts/vm-mac` | HVF | | A Linux machine with no KVM | `nix build -L .#legacyPackages.SYSTEM.vmTcg.NAME` | TCG | @@ -22,6 +23,14 @@ failed run can be uploaded as an artifact. KVM on GitHub-hosted runners is documented for public repositories; the first step of each VM job checks that `/dev/kvm` is writable and fails there if it is not. +The `canary` job runs both tiers once more every week, against the tip of +nixpkgs-unstable instead of the nixpkgs `flake.lock` pins: it runs +`nix flake update nixpkgs` in a copy of the checkout, builds every check there, +the suites one after the other on one machine, and opens an issue when one +fails ([`CONTRIBUTING.md`](../../CONTRIBUTING.md#continuous-integration)). It is +how a new KWin or Plasma that breaks a suite is found before the lock moves to +it. + TCG is software emulation. It is slow enough that only short suites are worth running that way, and the library's `scale` argument (below) is 8 for it. @@ -265,7 +274,7 @@ The script prints where the artifacts (screenshots, logs) are, under [`suites/kwin-events`](../../nix/tests/vm/suites/kwin-events) for a test that runs the daemon. 2. Pick the tier. `fast` suites are the pull request gate and should take - minutes. `slow` suites run on `master` and every night. + minutes. `slow` suites run on `master` and every week. 3. Run it: `just vm NAME`. 4. If the test covers behavior the daemon has, write the Rust test that covers the same behavior against the fake desktop in the same commit, and say in diff --git a/justfile b/justfile index daf1d00a..8c58cbb8 100644 --- a/justfile +++ b/justfile @@ -17,11 +17,13 @@ check-js: cd komorebi/src/kwin && tsc -p tsconfig.json node --test komorebi/src/kwin/bridge.test.js -# the macros the codebase has agreed not to use +# the macros the codebase has agreed not to use, and the workflows, which actionlint checks (with +# shellcheck over their scripts), both from the nixpkgs flake.lock pins lint: test -z "$(rg 'eyre!' --type rust .)" || (echo "eyre! macro not allowed"; false) test -z "$(rg 'dbg!' --type rust .)" || (echo "dbg! macro not allowed"; false) test -z "$(rg 'println!' --type rust ./komorebi/src)" || (echo "println! macro not allowed"; false) + nix shell --inputs-from . nixpkgs#actionlint nixpkgs#shellcheck --command actionlint .github/workflows/*.yaml # the JSON Schemas of komorebi.json and of applications.json, from the Rust types jsonschema: