diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 6dfd0be5..73b0e1a2 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,9 +1,25 @@ -# Keeps the actions used by CI up to date. Cargo and the C++ SDKs are pinned on -# purpose (see crates/dstudio-app/Cargo.toml and engine/CMakeLists.txt), so they -# are updated by hand. +# Keeps the GitHub Actions used by the workflows current. They are pinned to commit hashes; +# Dependabot opens one grouped pull request a week that moves the hashes (and the version +# comments next to them). +# +# Cargo dependencies and the C++ SDKs are pinned on purpose (see crates/dstudio-app/Cargo.toml +# and engine/CMakeLists.txt), so version updates stay off (open-pull-requests-limit: 0) and +# they are updated by hand. For Cargo, security fixes still arrive as pull requests once +# "Dependabot security updates" is on in the repository settings, and the Security workflow +# checks Cargo.lock against the RustSec advisory database every week. Dependabot cannot see +# the C++ SDKs that engine/CMakeLists.txt fetches, so nothing watches those automatically: +# check their release notes and advisories by hand when updating them. version: 2 updates: - package-ecosystem: github-actions directory: / schedule: - interval: monthly + interval: weekly + groups: + actions: + patterns: ['*'] + - package-ecosystem: cargo + directory: / + schedule: + interval: weekly + open-pull-requests-limit: 0 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 63c9b5bd..ac68ab9b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -53,6 +53,7 @@ jobs: version: name: Check version runs-on: ubuntu-latest + timeout-minutes: 10 outputs: version: ${{ steps.v.outputs.version }} steps: @@ -84,17 +85,29 @@ jobs: echo "version=$version" >> "$GITHUB_OUTPUT" echo "Version: $version" - macos: - name: Package macOS (universal) + # The two architectures build side by side on their own runners (each is a full release + # build of the app and the engine, about 13 minutes); the macos job joins them with lipo. + macos-build: + name: Build macOS (${{ matrix.arch }}) needs: version + strategy: + matrix: + include: + - arch: aarch64 + triple: aarch64-apple-darwin + cmake_arch: arm64 + - arch: x86_64 + triple: x86_64-apple-darwin + cmake_arch: x86_64 runs-on: macos-15 + timeout-minutes: 60 steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false - - name: Rust toolchain (stable, both macOS targets) + - name: Rust toolchain (stable, ${{ matrix.triple }}) run: | - rustup toolchain install stable --profile minimal --no-self-update --target aarch64-apple-darwin --target x86_64-apple-darwin + rustup toolchain install stable --profile minimal --no-self-update --target ${{ matrix.triple }} rustup default stable - name: Install Ninja run: brew install ninja @@ -105,18 +118,53 @@ jobs: ~/.cargo/registry/cache ~/.cargo/git/db key: release-cargo-${{ runner.os }}-${{ hashFiles('Cargo.lock') }} - # The engine's C++ is built by build.rs (CMake). Each target gets its own build, so the - # x86_64 engine is cross-compiled on this Apple silicon runner. - - name: Build (Apple silicon) - env: - MACOSX_DEPLOYMENT_TARGET: '13.0' - run: cargo build --release --locked -p dstudio-app --target aarch64-apple-darwin - - name: Build (Intel) + # The engine's C++ is built by build.rs (CMake). The x86_64 engine is cross-compiled on + # this Apple silicon runner. + - name: Build env: MACOSX_DEPLOYMENT_TARGET: '13.0' - CMAKE_OSX_ARCHITECTURES: x86_64 - run: cargo build --release --locked -p dstudio-app --target x86_64-apple-darwin + CMAKE_OSX_ARCHITECTURES: ${{ matrix.cmake_arch }} + run: cargo build --release --locked -p dstudio-app --target ${{ matrix.triple }} + - name: Collect the app and the plugin scanner + run: | + set -euo pipefail + mkdir -p "build/macos-${{ matrix.arch }}" + cp "target/${{ matrix.triple }}/release/device-studio" "build/macos-${{ matrix.arch }}/" + scanners=(target/${{ matrix.triple }}/release/build/dstudio-engine-*/out/build/dstudio_plugin_scanner) + if [ "${#scanners[@]}" -ne 1 ] || [ ! -f "${scanners[0]}" ]; then + echo "expected one plugin scanner, found: ${scanners[*]}" >&2 + exit 1 + fi + cp "${scanners[0]}" "build/macos-${{ matrix.arch }}/" + lipo -info "build/macos-${{ matrix.arch }}"/* + - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: macos-build-${{ matrix.arch }} + path: build/macos-${{ matrix.arch }} + if-no-files-found: error + retention-days: 1 + + macos: + name: Package macOS (universal) + needs: [version, macos-build] + runs-on: macos-15 + timeout-minutes: 30 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 + with: + name: macos-build-aarch64 + path: build/macos-aarch64 + - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 + with: + name: macos-build-x86_64 + path: build/macos-x86_64 - name: Bundle the universal app + env: + DSTUDIO_MACOS_ARM_DIR: build/macos-aarch64 + DSTUDIO_MACOS_X86_DIR: build/macos-x86_64 run: | bash tools/release/package-macos.sh build/macos ditto -c -k --keepParent "build/macos/Device Studio.app" build/macos/DeviceStudio-app.zip @@ -151,6 +199,7 @@ jobs: needs: [version, macos] if: github.event_name == 'push' && github.ref_type == 'tag' runs-on: macos-15 + timeout-minutes: 60 environment: release env: HAS_SIGNING_CERTIFICATE: ${{ secrets.MACOS_CERTIFICATE != '' }} @@ -215,6 +264,7 @@ jobs: name: Package Windows (x64) needs: version runs-on: windows-2025 + timeout-minutes: 60 steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: @@ -286,6 +336,7 @@ jobs: - arch: aarch64 runner: ubuntu-24.04-arm runs-on: ${{ matrix.runner }} + timeout-minutes: 60 steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: @@ -339,8 +390,11 @@ jobs: needs: [version, macos-sign, windows, linux] if: github.event_name == 'push' && github.ref_type == 'tag' runs-on: ubuntu-latest + timeout-minutes: 15 permissions: contents: write # create the release and upload the packages + id-token: write # sign the build provenance (Sigstore, through GitHub's OIDC token) + attestations: write # store the provenance with the repository steps: - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 with: @@ -353,6 +407,12 @@ jobs: sha256sum -- * > "$RUNNER_TEMP/SHA256SUMS.txt" mv "$RUNNER_TEMP/SHA256SUMS.txt" SHA256SUMS.txt cat SHA256SUMS.txt + # SLSA build provenance for every package: anyone can check that a download was built + # by this workflow from this tag with `gh attestation verify --repo chrislaupama/device`. + - name: Attest build provenance + uses: actions/attest-build-provenance@4d101475d8b20a2381f78447822ac1eab6504dd8 # v4.2.2 + with: + subject-path: dist/* - name: Create the draft release env: GH_TOKEN: ${{ github.token }} diff --git a/.github/workflows/security.yml b/.github/workflows/security.yml new file mode 100644 index 00000000..cb8400e5 --- /dev/null +++ b/.github/workflows/security.yml @@ -0,0 +1,63 @@ +name: Security + +# Supply-chain checks that need no secrets and no external service beyond GitHub: +# +# Dependency review (pull requests): GitHub's dependency graph compares the pull request's +# Cargo.lock and workflow actions with the base and fails when the change adds a +# dependency with a known vulnerability of moderate severity or worse. +# RustSec advisories (weekly, and when Cargo.lock changes): `cargo audit` checks every +# crate in Cargo.lock against the RustSec advisory database and fails on a vulnerability. +# Unmaintained or yanked crates are listed as warnings. A new advisory can appear without +# any commit, which is why it also runs on a schedule. +# +# Neither is a required check. A failure on main or on the schedule shows in the Actions tab. + +on: + pull_request: + paths: + - 'Cargo.lock' + - '**/Cargo.toml' + - '.github/workflows/**' + push: + branches: [main] + paths: + - 'Cargo.lock' + - '.github/workflows/security.yml' + schedule: + - cron: '41 5 * * 1' + workflow_dispatch: + +permissions: + contents: read + +concurrency: + group: security-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + dependency-review: + name: Dependency review + if: github.event_name == 'pull_request' + runs-on: ubuntu-24.04 + timeout-minutes: 10 + steps: + - uses: actions/dependency-review-action@a1d282b36b6f3519aa1f3fc636f609c47dddb294 # v5.0.0 + with: + fail-on-severity: moderate + + rustsec: + name: RustSec advisories + runs-on: ubuntu-24.04 + timeout-minutes: 20 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - name: Rust toolchain (stable) + run: | + rustup toolchain install stable --profile minimal --no-self-update + rustup default stable + - name: Install cargo-audit + run: cargo install cargo-audit --locked --version 0.22.2 + - name: cargo audit + run: cargo audit --file Cargo.lock diff --git a/README.md b/README.md index 48fc4b05..30a55e39 100644 --- a/README.md +++ b/README.md @@ -229,10 +229,12 @@ interface end to end, from importing audio to checking that notes drawn in the p Pull requests with visual changes include before and after screenshots, and anything that could affect performance comes with benchmark results. -Three GitHub Actions workflows check every change: **CI** builds and tests the engine, the workspace and the app on +Four GitHub Actions workflows check every change: **CI** builds and tests the engine, the workspace and the app on macOS, Windows and Linux; **Performance** builds the benchmarks at the base commit and with the change and fails a pull request when any benchmark row needs more than 1 % more CPU instructions (timings on all three systems are -reported too); **Release** builds the installable packages and drafts a GitHub release for a `vX.Y.Z` tag. See +reported too); **Security** reviews new dependencies and checks `Cargo.lock` against the RustSec advisories every +week; **Release** builds the installable packages, attests their build provenance and drafts a GitHub release for a +`vX.Y.Z` tag. See [Continuous integration](docs/building.md#continuous-integration) for the details and how to run the performance comparison locally. diff --git a/docs/building.md b/docs/building.md index 49cc519b..76df4ca8 100644 --- a/docs/building.md +++ b/docs/building.md @@ -181,8 +181,8 @@ Pull requests run only what their changes can reach ([`tools/ci/changes.sh`](../tools/ci/changes.sh), tested by `tools/ci/test-changes.sh`): documentation alone builds nothing; Rust or UI changes skip the standalone engine build; engine tests or benchmarks alone skip -the Rust tests and the app; packaging and benchmark tooling have their own -workflows. Anything the script does not know (`Cargo.toml`, `Cargo.lock`, the +the Rust tests and the app; packaging, benchmark tooling and the Security +workflow have their own workflows. Anything the script does not know (`Cargo.toml`, `Cargo.lock`, the CI workflow, `tools/ci/`, a new folder) runs everything, and so do pushes to main and the nightly run. A job with nothing to do still runs and passes, so the required checks always report. @@ -212,6 +212,28 @@ The workflow never uses a self-hosted runner, has no secrets, gives its token read-only access and pins every action to a commit, so running it on a stranger's pull request is safe. +### Supply-chain checks + +[`.github/workflows/security.yml`](../.github/workflows/security.yml) runs on +pull requests that change `Cargo.lock`, a `Cargo.toml` or a workflow, on +pushes to main that change `Cargo.lock`, and every Monday: + +- **Dependency review** (pull requests): fails when the change adds a + dependency or action with a known vulnerability of moderate severity or + worse, from GitHub's advisory database. +- **RustSec advisories**: `cargo audit` checks every crate in `Cargo.lock` + against the RustSec database and fails on a vulnerability (unmaintained or + yanked crates are warnings). The weekly run catches advisories published + after a dependency was added. + +Every action in every workflow is pinned to a commit hash; Dependabot moves the +hashes in one grouped pull request a week. Cargo crates and the engine's C++ +SDKs are updated by hand. For Cargo crates, Dependabot opens security-fix pull +requests once "Dependabot security updates" is on in the repository settings +(Settings › Code security). Dependabot does not see the SDKs that +`engine/CMakeLists.txt` fetches, so their advisories are checked by hand when +they are updated. + ### Performance checks [`.github/workflows/perf.yml`](../.github/workflows/perf.yml) runs on pull @@ -262,10 +284,13 @@ installable packages: | Windows x64 | `DeviceStudio--windows-x64-setup.exe` (installer) and a portable `.zip` | | Linux x86_64, aarch64 | `DeviceStudio--linux-.tar.gz` (run `install.sh`) | -Each package carries the plugin scanner next to the app, where the app looks +The macOS app's two architectures build side by side on separate runners and +are joined with `lipo` in a third job. Each package carries the plugin scanner next to the app, where the app looks for it first, and is smoke-tested on its runner (installed, then started to render a screenshot). Pushing a tag `vX.Y.Z` builds them from `main` and -creates a **draft** GitHub release with generated notes; the tag must match the +creates a **draft** GitHub release with generated notes, a `SHA256SUMS.txt` and +a signed build provenance attestation for every package (check a download with +`gh attestation verify --repo chrislaupama/device`); the tag must match the `version` in the root `Cargo.toml`. A manual run (Actions › Release › Run workflow) or a pull request that changes the packaging builds the packages as run artifacts without releasing anything. diff --git a/tools/ci/changes.sh b/tools/ci/changes.sh index 47068b41..c82d1c3e 100755 --- a/tools/ci/changes.sh +++ b/tools/ci/changes.sh @@ -21,7 +21,7 @@ # crates/ (anything else) rust, app # tools/perf/, tools/release/, tools/art/, # tools/agents/, tools/macos-bundle.sh, -# .github/workflows/{perf,release}.yml, +# .github/workflows/{perf,release,security}.yml, # ui-spike/ nothing (their own workflows, or no CI) # # Test it with tools/ci/test-changes.sh. @@ -42,7 +42,7 @@ while IFS= read -r path || [ -n "$path" ]; do crates/*/tests/* | crates/*/benches/*) rust=true ;; crates/*) rust=true app=true ;; tools/perf/* | tools/release/* | tools/art/* | tools/agents/* | tools/macos-bundle.sh) ;; - .github/workflows/perf.yml | .github/workflows/release.yml | ui-spike/*) ;; + .github/workflows/perf.yml | .github/workflows/release.yml | .github/workflows/security.yml | ui-spike/*) ;; *) engine=true rust=true app=true ;; esac done diff --git a/tools/ci/test-changes.sh b/tools/ci/test-changes.sh index fabb862d..f08831a8 100755 --- a/tools/ci/test-changes.sh +++ b/tools/ci/test-changes.sh @@ -19,7 +19,7 @@ all="engine=true rust=true app=true" none="engine=false rust=false app=false" check "$none" README.md docs/building.md specs/003-midi/spec.md .agents/skills/x/SKILL.md LICENSE -check "$none" tools/perf/bench_gate.py tools/release/make-dmg.sh .github/workflows/release.yml ui-spike/src/main.rs +check "$none" tools/perf/bench_gate.py tools/release/make-dmg.sh .github/workflows/release.yml .github/workflows/security.yml ui-spike/src/main.rs check "engine=true rust=false app=false" engine/tests/test_pdc.cpp engine/bench/bench_main.cpp check "$all" engine/src/engine.cpp check "$all" engine/include/dstudio_engine.h README.md diff --git a/tools/release/package-macos.sh b/tools/release/package-macos.sh index 2d9059cb..fa30e84b 100755 --- a/tools/release/package-macos.sh +++ b/tools/release/package-macos.sh @@ -7,6 +7,9 @@ # cargo build --release --locked -p dstudio-app --target aarch64-apple-darwin # cargo build --release --locked -p dstudio-app --target x86_64-apple-darwin # (target dir: $CARGO_TARGET_DIR, default target/). +# Or, with the two builds made elsewhere (the release workflow builds each architecture on +# its own runner), set DSTUDIO_MACOS_ARM_DIR and DSTUDIO_MACOS_X86_DIR to folders that each +# hold that architecture's device-studio and dstudio_plugin_scanner. set -euo pipefail out="${1:?usage: package-macos.sh }" root="$(cd "$(dirname "$0")/../.." && pwd)" @@ -18,13 +21,27 @@ mkdir -p "$out" scanner_of() { # the scanner build.rs built for one target triple ls -t "$target/$1"/release/build/dstudio-engine-*/out/build/dstudio_plugin_scanner 2>/dev/null | head -1 } -arm_scanner="$(scanner_of aarch64-apple-darwin)" -x86_scanner="$(scanner_of x86_64-apple-darwin)" -[ -n "$arm_scanner" ] && [ -n "$x86_scanner" ] || { echo "plugin scanner not built for both architectures" >&2; exit 1; } +if [ -n "${DSTUDIO_MACOS_ARM_DIR:-}" ] || [ -n "${DSTUDIO_MACOS_X86_DIR:-}" ]; then + arm_app="${DSTUDIO_MACOS_ARM_DIR:?set both DSTUDIO_MACOS_ARM_DIR and DSTUDIO_MACOS_X86_DIR}/device-studio" + x86_app="${DSTUDIO_MACOS_X86_DIR:?set both DSTUDIO_MACOS_ARM_DIR and DSTUDIO_MACOS_X86_DIR}/device-studio" + arm_scanner="$DSTUDIO_MACOS_ARM_DIR/dstudio_plugin_scanner" + x86_scanner="$DSTUDIO_MACOS_X86_DIR/dstudio_plugin_scanner" + [ -f "$arm_scanner" ] || arm_scanner="" + [ -f "$x86_scanner" ] || x86_scanner="" +else + arm_app="$target/aarch64-apple-darwin/release/device-studio" + x86_app="$target/x86_64-apple-darwin/release/device-studio" + arm_scanner="$(scanner_of aarch64-apple-darwin)" + x86_scanner="$(scanner_of x86_64-apple-darwin)" +fi +if [ -z "$arm_scanner" ] || [ -z "$x86_scanner" ]; then + echo "plugin scanner not built for both architectures" >&2 + exit 1 +fi -lipo -create -output "$work/device-studio" \ - "$target/aarch64-apple-darwin/release/device-studio" "$target/x86_64-apple-darwin/release/device-studio" +lipo -create -output "$work/device-studio" "$arm_app" "$x86_app" lipo -create -output "$work/dstudio_plugin_scanner" "$arm_scanner" "$x86_scanner" +chmod +x "$work/device-studio" "$work/dstudio_plugin_scanner" lipo -info "$work/device-studio" "$work/dstudio_plugin_scanner" rm -rf "$out/Device Studio.app"