name: Release on: push: tags: - "v*" workflow_dispatch: # Build the installers when something they depend on changes. Only a tag publishes anything. pull_request: paths: - .github/workflows/release.yml - Cargo.toml - Cargo.lock - assets/icons/** permissions: contents: read jobs: build: strategy: fail-fast: false matrix: include: - platform: macos-latest # Apple Silicon - platform: ubuntu-latest - platform: windows-latest runs-on: ${{ matrix.platform }} timeout-minutes: 120 steps: - uses: actions/checkout@v7 - name: install Linux system dependencies if: matrix.platform == 'ubuntu-latest' run: | sudo apt-get update sudo apt-get install -y libxkbcommon-dev libwayland-dev # rustup reads the version from rust-toolchain.toml. - name: install the Rust toolchain run: rustup show active-toolchain || rustup toolchain install - uses: Swatinem/rust-cache@v2 - name: install cargo-bundle if: matrix.platform != 'windows-latest' run: cargo install cargo-bundle --locked # rcodesign signs from the .p12 without a keychain, and notarizes and staples in one step. - name: install rcodesign if: matrix.platform == 'macos-latest' run: | name=apple-codesign-0.29.0-aarch64-apple-darwin curl -fsSL -o "$RUNNER_TEMP/rcodesign.tar.gz" \ "https://github.com/indygreg/apple-platform-rs/releases/download/apple-codesign%2F0.29.0/$name.tar.gz" echo "d1a532150adaf90048260d76359261aa716abafc45c53c5dc18845029184334a $RUNNER_TEMP/rcodesign.tar.gz" | shasum -a 256 -c tar -xzf "$RUNNER_TEMP/rcodesign.tar.gz" -C "$RUNNER_TEMP" echo "$RUNNER_TEMP/$name" >> "$GITHUB_PATH" # Each installer gets a checksum, which the in-app updater requires. It catches a corrupt # download. It comes from the same release, so it can't catch a tampered one. # # A release must be signed with the Developer ID and notarized, so Gatekeeper opens it. A build # without the secrets (a pull request, Dependabot, forks) is ad-hoc signed instead, which only a tag refuses. # The app is stapled before it goes in the disk image, so a copy dragged out of it opens # offline too. Then the disk image itself is, so opening it doesn't warn either. - name: build the macOS app if: matrix.platform == 'macos-latest' run: cargo bundle --release # The only step with the signing secrets: it never compiles anything. - name: sign and notarize the macOS disk image if: matrix.platform == 'macos-latest' env: MACOS_CERTIFICATE: ${{ github.event_name != 'pull_request' && secrets.DEVELOPER_ID_P12 || '' }} MACOS_CERTIFICATE_PASSWORD: ${{ github.event_name != 'pull_request' && secrets.DEVELOPER_ID_P12_PASSWORD || '' }} ASC_KEY_ID: ${{ github.event_name != 'pull_request' && secrets.ASC_KEY_ID || '' }} ASC_ISSUER_ID: ${{ github.event_name != 'pull_request' && secrets.ASC_ISSUER_ID || '' }} ASC_KEY_P8: ${{ github.event_name != 'pull_request' && secrets.ASC_KEY_P8 || '' }} run: | if [ -n "$MACOS_CERTIFICATE" ] && [ -n "$MACOS_CERTIFICATE_PASSWORD" ] && [ -n "$ASC_KEY_P8" ]; then sign=true elif [[ "$GITHUB_REF" == refs/tags/* ]]; then echo "::error::a release needs the signing and notarization secrets" exit 1 else echo "::notice::no signing secrets, so this disk image is ad-hoc signed and Gatekeeper will block it" fi app="target/release/bundle/osx/Stahl Capital.app" dmg=stahl-capital-macos-arm64.dmg if [ "$sign" != true ]; then codesign --force --deep --sign - "$app" hdiutil create -volname "Stahl Capital" -srcfolder "$app" -ov -format UDZO "$dmg" else echo "$MACOS_CERTIFICATE" | base64 --decode > "$RUNNER_TEMP/certificate.p12" # The same App Store Connect key TestFlight uses, in the JSON form rcodesign reads. printf '%s' "$ASC_KEY_P8" > "$RUNNER_TEMP/AuthKey.p8" rcodesign encode-app-store-connect-api-key -o "$RUNNER_TEMP/api-key.json" \ "$ASC_ISSUER_ID" "$ASC_KEY_ID" "$RUNNER_TEMP/AuthKey.p8" rm -f "$RUNNER_TEMP/AuthKey.p8" # --for-notarization turns on the hardened runtime, which the app needs no exceptions to. sign() { rcodesign sign --for-notarization --p12-file "$RUNNER_TEMP/certificate.p12" \ --p12-password-file <(printf '%s' "$MACOS_CERTIFICATE_PASSWORD") "$1" } # Fails, with Apple's log, unless Apple accepts it. notarize() { rcodesign notary-submit --api-key-file "$RUNNER_TEMP/api-key.json" --max-wait-seconds 1800 --staple "$1" } sign "$app" notarize "$app" hdiutil create -volname "Stahl Capital" -srcfolder "$app" -ov -format UDZO "$dmg" sign "$dmg" notarize "$dmg" # Apple's own tools on rcodesign's work: what Gatekeeper will decide on someone else's # Mac. A runner may have it switched off, which spctl would accept, so check the tickets. xcrun stapler validate "$app" xcrun stapler validate "$dmg" spctl --assess --type execute --verbose=2 "$app" spctl --assess --type open --context context:primary-signature --verbose=2 "$dmg" fi shasum -a 256 "$dmg" > "$dmg.sha256" - name: delete the signing material if: always() && matrix.platform == 'macos-latest' run: rm -f "$RUNNER_TEMP/certificate.p12" "$RUNNER_TEMP/api-key.json" "$RUNNER_TEMP/AuthKey.p8" - name: build the Debian package if: matrix.platform == 'ubuntu-latest' run: | cargo bundle --release --format deb cp target/release/bundle/deb/*.deb . for deb in *.deb; do sha256sum "$deb" > "$deb.sha256"; done - name: build the Windows archive if: matrix.platform == 'windows-latest' shell: pwsh run: | cargo build --release Compress-Archive -Path target/release/stahl.exe -DestinationPath stahl-capital-windows-x64.zip $hash = (Get-FileHash stahl-capital-windows-x64.zip -Algorithm SHA256).Hash.ToLower() "$hash stahl-capital-windows-x64.zip" | Out-File -Encoding ascii stahl-capital-windows-x64.zip.sha256 - uses: actions/upload-artifact@v7 with: name: installer-${{ matrix.platform }} path: | *.dmg *.deb *.zip *.sha256 if-no-files-found: error # One job after all the builds, so a failed build can't publish a release with installers missing. # It runs on PRs too, so everything but the publishing itself is tested before a tag needs it. release: needs: build runs-on: ubuntu-latest permissions: contents: write steps: - uses: actions/checkout@v7 - name: check the tag matches Cargo.toml if: startsWith(github.ref, 'refs/tags/') run: | version=$(grep -m1 '^version' Cargo.toml | cut -d'"' -f2) if [ "$GITHUB_REF_NAME" != "v$version" ]; then echo "::error::tag $GITHUB_REF_NAME doesn't match version $version in Cargo.toml" exit 1 fi - uses: actions/download-artifact@v8 with: pattern: installer-* path: installers merge-multiple: true - name: check every installer is there run: | ls -l installers ls installers/*.dmg installers/*.deb installers/*.zip - uses: softprops/action-gh-release@v3 if: startsWith(github.ref, 'refs/tags/') with: name: "Stahl Capital ${{ github.ref_name }}" generate_release_notes: true fail_on_unmatched_files: true files: installers/*