name: Release # Push a tag like v0.9.0 to build and publish a release. The tag must match # the workspace version in Cargo.toml. on: push: tags: ["v*"] workflow_dispatch: inputs: tag: description: "Existing tag to (re)build, e.g. v0.9.0" required: true # Every job uploads to the release, so every job needs to write. The token # reaches only the steps that name it: no checkout keeps it, and every # action is pinned to a commit, since a tag can be moved under a release # that signs with the secrets below. permissions: contents: write env: CARGO_TERM_COLOR: always jobs: release: name: Check the tag and draft the release runs-on: ubuntu-24.04 outputs: tag: ${{ steps.version.outputs.tag }} version: ${{ steps.version.outputs.version }} steps: - uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5.1.0 with: ref: ${{ inputs.tag || github.ref }} persist-credentials: false - name: Version id: version # Through the environment, not spliced into the script: a tag typed # into the dispatch form is text, never shell. env: TAG: ${{ inputs.tag || github.ref_name }} run: | tag="$TAG" version=$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -1) if [ "$tag" != "v$version" ]; then echo "tag $tag does not match Cargo.toml version $version" >&2 exit 1 fi echo "tag=$tag" >> "$GITHUB_OUTPUT" echo "version=$version" >> "$GITHUB_OUTPUT" # A draft, so nobody downloads from a release still missing half its # builds; `publish` below makes it public once every build is in. - name: Draft env: GH_TOKEN: ${{ github.token }} TAG: ${{ steps.version.outputs.tag }} run: | if ! gh release view "$TAG" >/dev/null 2>&1; then gh release create "$TAG" --draft --verify-tag \ --title "disktree ${TAG#v}" --generate-notes fi linux: name: Build (Linux ${{ matrix.arch }}) needs: release strategy: matrix: include: # The oldest supported runners: their glibc is what the binary # needs at least, so building there runs on the most systems. - { runner: ubuntu-22.04, arch: x86_64 } - { runner: ubuntu-22.04-arm, arch: aarch64 } runs-on: ${{ matrix.runner }} steps: - uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5.1.0 with: ref: ${{ inputs.tag || github.ref }} persist-credentials: false - name: System libraries run: | sudo apt-get update sudo apt-get install -y --no-install-recommends \ pkg-config libxkbcommon-dev libxkbcommon-x11-dev libwayland-dev \ libx11-xcb-dev libxcb1-dev libfontconfig-dev libfreetype-dev \ libvulkan-dev libasound2-dev libssl-dev libzstd-dev - uses: dtolnay/rust-toolchain@683b588c487a69d01f6c6ddf40f036ff682cc2c8 # master with: toolchain: "1.97" - uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3 - name: Test run: cargo xtask test - name: Build run: | rustup target add x86_64-unknown-linux-musl aarch64-unknown-linux-musl cargo xtask portable - name: Package id: package env: VERSION: ${{ needs.release.outputs.version }} ARCH: ${{ matrix.arch }} run: | name="disktree-$VERSION-$ARCH-linux" cli_bin="target/$ARCH-unknown-linux-musl/release/disktree-cli" mkdir -p "dist/$name" # portable strips before appending; stripping again loses helpers. cp target/portable/disktree "dist/$name/" cp "$cli_bin" "dist/$name/disktree-cli" cp packaging/install.sh packaging/disktree.desktop.in \ assets/disktree.svg README.md LICENSE "dist/$name/" echo "$VERSION" > "dist/$name/VERSION" tar -C dist -czf "dist/$name.tar.gz" "$name" (cd dist && sha256sum "$name.tar.gz" > "$name.tar.gz.sha256") cli_asset="disktree-cli-linux-$ARCH" cp "$cli_bin" "dist/$cli_asset" (cd dist && sha256sum "$cli_asset" > "$cli_asset.sha256") echo "archive=dist/$name.tar.gz" >> "$GITHUB_OUTPUT" echo "cli=dist/$cli_asset" >> "$GITHUB_OUTPUT" - name: Upload env: GH_TOKEN: ${{ github.token }} TAG: ${{ needs.release.outputs.tag }} ARCHIVE: ${{ steps.package.outputs.archive }} CLI: ${{ steps.package.outputs.cli }} run: | gh release upload "$TAG" \ "$ARCHIVE" "$ARCHIVE.sha256" \ "$CLI" "$CLI.sha256" --clobber macos: name: Build (macOS ${{ matrix.arch }}) needs: release strategy: matrix: include: # `xtask bundle` names the zip after the machine it runs on, so # each architecture builds on its own. - { runner: macos-15, arch: aarch64 } - { runner: macos-15-intel, arch: x86_64 } runs-on: ${{ matrix.runner }} env: # Signing and notarizing happen only when the repository has these # secrets; without them the app is signed ad hoc, and a downloaded # copy needs "Open Anyway" in System Settings once. # MACOS_CERTIFICATE base64 of the Developer ID .p12 # MACOS_CERTIFICATE_PASSWORD its password # MACOS_SIGN_IDENTITY "Developer ID Application: Name (TEAMID)" # NOTARY_KEY_P8 base64 of an App Store Connect API key # NOTARY_KEY_ID, NOTARY_ISSUER that key's ID and issuer # Only whether there is a certificate is known to the whole job. The # secrets themselves go to the two steps that use them, not to the # tests and every dependency's build script before those. HAS_CERTIFICATE: ${{ secrets.MACOS_CERTIFICATE != '' }} steps: - uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5.1.0 with: ref: ${{ inputs.tag || github.ref }} persist-credentials: false - uses: dtolnay/rust-toolchain@683b588c487a69d01f6c6ddf40f036ff682cc2c8 # master with: toolchain: "1.97" - uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3 - name: Test run: cargo xtask test # A keychain of its own for the certificate, deleted with the runner. - name: Signing certificate if: env.HAS_CERTIFICATE == 'true' env: MACOS_CERTIFICATE: ${{ secrets.MACOS_CERTIFICATE }} MACOS_CERTIFICATE_PASSWORD: ${{ secrets.MACOS_CERTIFICATE_PASSWORD }} run: | keychain="$RUNNER_TEMP/signing.keychain-db" password=$(uuidgen) echo "$MACOS_CERTIFICATE" | base64 --decode > "$RUNNER_TEMP/cert.p12" security create-keychain -p "$password" "$keychain" security set-keychain-settings -lut 3600 "$keychain" security unlock-keychain -p "$password" "$keychain" security import "$RUNNER_TEMP/cert.p12" -k "$keychain" \ -P "$MACOS_CERTIFICATE_PASSWORD" -T /usr/bin/codesign security set-key-partition-list -S apple-tool:,apple: \ -s -k "$password" "$keychain" security list-keychains -d user -s "$keychain" \ $(security list-keychains -d user | tr -d '"') rm "$RUNNER_TEMP/cert.p12" - name: Bundle env: MACOS_SIGN_IDENTITY: ${{ secrets.MACOS_SIGN_IDENTITY }} NOTARY_KEY_P8: ${{ secrets.NOTARY_KEY_P8 }} NOTARY_KEY_ID: ${{ secrets.NOTARY_KEY_ID }} NOTARY_ISSUER: ${{ secrets.NOTARY_ISSUER }} run: | args=() if [ "$HAS_CERTIFICATE" = true ]; then args+=(--sign "$MACOS_SIGN_IDENTITY") if [ -n "$NOTARY_KEY_P8" ]; then echo "$NOTARY_KEY_P8" | base64 --decode \ > "$RUNNER_TEMP/AuthKey.p8" export NOTARY_KEY="$RUNNER_TEMP/AuthKey.p8" args+=(--notarize) fi fi cargo xtask bundle "${args[@]}" cargo build --release --locked -p disktree-cli - name: Upload env: GH_TOKEN: ${{ github.token }} TAG: ${{ needs.release.outputs.tag }} VERSION: ${{ needs.release.outputs.version }} ARCH: ${{ matrix.arch }} run: | zip="target/bundle/disktree-$VERSION-$ARCH-macos.zip" (cd "$(dirname "$zip")" && shasum -a 256 "$(basename "$zip")" \ > "$(basename "$zip").sha256") mkdir -p dist cli="dist/disktree-cli-macos-$ARCH" cp target/release/disktree-cli "$cli" (cd dist && shasum -a 256 "$(basename "$cli")" \ > "$(basename "$cli").sha256") gh release upload "$TAG" \ "$zip" "$zip.sha256" \ "$cli" "$cli.sha256" --clobber windows: name: Build (Windows ${{ matrix.arch }}) needs: release strategy: matrix: include: - { runner: windows-2025, arch: x86_64 } - { runner: windows-11-arm, arch: aarch64 } runs-on: ${{ matrix.runner }} env: # The C runtime linked in, so disktree.exe also runs where the Visual # C++ runtime was never installed. For the tests too, so both steps # share one build. RUSTFLAGS: -C target-feature=+crt-static steps: - run: git config --global core.autocrlf false - uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5.1.0 with: ref: ${{ inputs.tag || github.ref }} persist-credentials: false - uses: dtolnay/rust-toolchain@683b588c487a69d01f6c6ddf40f036ff682cc2c8 # master with: toolchain: "1.97" - uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3 - name: Test run: cargo xtask test - name: Build run: cargo build --release --locked -p disktree-app -p disktree-cli - name: Package id: package shell: pwsh env: VERSION: ${{ needs.release.outputs.version }} ARCH: ${{ matrix.arch }} run: | $name = "disktree-$env:VERSION-$env:ARCH-windows" New-Item -ItemType Directory -Force "dist/$name" | Out-Null Copy-Item target/release/disktree.exe, target/release/disktree-cli.exe, README.md, LICENSE "dist/$name/" Compress-Archive -Path "dist/$name" -DestinationPath "dist/$name.zip" $hash = (Get-FileHash "dist/$name.zip" -Algorithm SHA256).Hash.ToLower() # The format `sha256sum -c` reads, with a Unix line ending. [IO.File]::WriteAllText("dist/$name.zip.sha256", "$hash $name.zip`n") $cli = "disktree-cli-windows-$env:ARCH.exe" Copy-Item target/release/disktree-cli.exe "dist/$cli" $cliHash = (Get-FileHash "dist/$cli" -Algorithm SHA256).Hash.ToLower() [IO.File]::WriteAllText("dist/$cli.sha256", "$cliHash $cli`n") "archive=dist/$name.zip" >> $env:GITHUB_OUTPUT "cli=dist/$cli" >> $env:GITHUB_OUTPUT - name: Install Inno Setup shell: pwsh run: packaging/windows/install-inno.ps1 -Dir "$env:RUNNER_TEMP\inno" - name: Installer id: installer shell: pwsh env: VERSION: ${{ needs.release.outputs.version }} ARCH: ${{ matrix.arch }} run: | ISCC.exe /Q "/DAppVersion=$env:VERSION" "/DArch=$env:ARCH" ` packaging/windows/disktree.iss if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } $name = "disktree-$env:VERSION-$env:ARCH-windows-setup.exe" $hash = (Get-FileHash "target/bundle/$name" -Algorithm SHA256).Hash.ToLower() [IO.File]::WriteAllText("target/bundle/$name.sha256", "$hash $name`n") "setup=target/bundle/$name" >> $env:GITHUB_OUTPUT - name: Upload shell: bash env: GH_TOKEN: ${{ github.token }} TAG: ${{ needs.release.outputs.tag }} ARCHIVE: ${{ steps.package.outputs.archive }} CLI: ${{ steps.package.outputs.cli }} SETUP: ${{ steps.installer.outputs.setup }} run: | gh release upload "$TAG" \ "$ARCHIVE" "$ARCHIVE.sha256" \ "$CLI" "$CLI.sha256" \ "$SETUP" "$SETUP.sha256" --clobber publish: name: Publish needs: [release, linux, macos, windows] runs-on: ubuntu-24.04 steps: - name: Publish env: GH_TOKEN: ${{ github.token }} TAG: ${{ needs.release.outputs.tag }} run: gh release edit "$TAG" --repo "$GITHUB_REPOSITORY" --draft=false --latest