name: FSEvents helper release on: push: tags: ['fsevents-v*'] workflow_dispatch: inputs: version: description: Version to build. A dispatched run is a dry run and publishes nothing. required: true default: 0.0.0 permissions: contents: read concurrency: group: fsevents-release cancel-in-progress: false jobs: test: runs-on: macos-15 timeout-minutes: 20 steps: - uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5 with: persist-credentials: false - uses: ./.github/actions/setup-stim with: build: 'false' - name: Helper tests run: pnpm run test:integration packages/stim-cli/src/__tests__/fsevents-helper.integration.test.ts trust: runs-on: ubuntu-latest timeout-minutes: 5 outputs: version: ${{ steps.resolve.outputs.version }} signed: ${{ steps.resolve.outputs.signed }} steps: - uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5 with: fetch-depth: 0 persist-credentials: false - name: Resolve the version and whether this run may sign id: resolve env: INPUT_VERSION: ${{ inputs.version }} run: | if [ "$GITHUB_EVENT_NAME" = push ]; then version="${GITHUB_REF_NAME#fsevents-v}" git fetch --no-tags origin main if ! git merge-base --is-ancestor "$GITHUB_SHA" FETCH_HEAD; then echo "::error::$GITHUB_REF_NAME is not on main. Tag a commit from main." exit 1 fi signed=true else version="$INPUT_VERSION" signed=false if [ "$GITHUB_REF" = refs/heads/main ]; then signed=true; fi fi if ! [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$ ]]; then echo "::error::The version is not a semver version such as 1.2.3 or 1.2.3-rc.1" exit 1 fi { echo "version=$version" echo "signed=$signed" } >> "$GITHUB_OUTPUT" dry-run: needs: [test, trust] if: needs.trust.outputs.signed != 'true' runs-on: macos-15 timeout-minutes: 20 env: VERSION: ${{ needs.trust.outputs.version }} steps: - uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5 with: persist-credentials: false - name: Build, signed ad hoc run: packages/stim-cli/native/fsevents/release.sh "$VERSION" - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 with: name: stim-fsevents-${{ env.VERSION }}-adhoc path: | packages/stim-cli/native/fsevents/build/release/stim-fsevents-*.zip packages/stim-cli/native/fsevents/build/release/SHA256SUMS if-no-files-found: error release: needs: [test, trust] if: needs.trust.outputs.signed == 'true' runs-on: macos-15 environment: release timeout-minutes: 60 permissions: contents: write env: GH_REPO: ${{ github.repository }} VERSION: ${{ needs.trust.outputs.version }} steps: - uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5 with: persist-credentials: false - name: Select Xcode run: sudo xcode-select -s /Applications/Xcode_26.3.app - name: Import the Developer ID certificate env: CERT_P12_BASE64: ${{ secrets.DESKTOP_CERT_P12_BASE64 }} CERT_PASSWORD: ${{ secrets.DESKTOP_CERT_PASSWORD }} run: | if [ -z "$CERT_P12_BASE64" ] && [ -z "$CERT_PASSWORD" ]; then echo "::notice::DESKTOP_CERT_P12_BASE64 and DESKTOP_CERT_PASSWORD are not set; the helper is signed ad hoc." exit 0 fi if [ -z "$CERT_P12_BASE64" ] || [ -z "$CERT_PASSWORD" ]; then echo "::error::Set both DESKTOP_CERT_P12_BASE64 and DESKTOP_CERT_PASSWORD, or neither." exit 1 fi keychain="$RUNNER_TEMP/fsevents-signing.keychain-db" keychain_password=$(openssl rand -base64 32) security create-keychain -p "$keychain_password" "$keychain" echo "FSEVENTS_KEYCHAIN=$keychain" >> "$GITHUB_ENV" security set-keychain-settings -lut 21600 "$keychain" security unlock-keychain -p "$keychain_password" "$keychain" printf '%s' "$CERT_P12_BASE64" | base64 --decode > "$RUNNER_TEMP/fsevents-cert.p12" security import "$RUNNER_TEMP/fsevents-cert.p12" -k "$keychain" -P "$CERT_PASSWORD" -T /usr/bin/codesign rm -f "$RUNNER_TEMP/fsevents-cert.p12" security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k "$keychain_password" "$keychain" > /dev/null security list-keychains -d user -s "$keychain" $(security list-keychains -d user | tr -d '"') identity=$(security find-identity -v -p codesigning "$keychain" | awk '/"Developer ID Application: / { print $2; exit }') if [ -z "$identity" ]; then echo "::error::DESKTOP_CERT_P12_BASE64 holds no valid Developer ID Application identity." exit 1 fi echo "FSEVENTS_SIGNING_IDENTITY=$identity" >> "$GITHUB_ENV" - name: Write the App Store Connect API key env: KEY_P8_BASE64: ${{ secrets.ASC_KEY_P8_BASE64 }} KEY_ID: ${{ secrets.ASC_KEY_ID }} ISSUER_ID: ${{ secrets.ASC_ISSUER_ID }} run: | if [ -z "$KEY_P8_BASE64" ] && [ -z "$KEY_ID" ] && [ -z "$ISSUER_ID" ]; then echo "::notice::ASC_KEY_P8_BASE64, ASC_KEY_ID and ASC_ISSUER_ID are not set; the helper is not notarized." exit 0 fi if [ -z "$KEY_P8_BASE64" ] || [ -z "$KEY_ID" ] || [ -z "$ISSUER_ID" ]; then echo "::error::Set all of ASC_KEY_P8_BASE64, ASC_KEY_ID and ASC_ISSUER_ID, or none." exit 1 fi dir="$RUNNER_TEMP/asc" mkdir -p "$dir" chmod 700 "$dir" printf '%s' "$KEY_P8_BASE64" | base64 --decode > "$dir/AuthKey_$KEY_ID.p8" chmod 600 "$dir/AuthKey_$KEY_ID.p8" { echo "ASC_KEY_PATH=$dir/AuthKey_$KEY_ID.p8" echo "ASC_KEY_ID=$KEY_ID" echo "ASC_ISSUER_ID=$ISSUER_ID" } >> "$GITHUB_ENV" - name: Build, sign and notarize run: packages/stim-cli/native/fsevents/release.sh "$VERSION" - name: Check the signature the pin requires if: env.FSEVENTS_SIGNING_IDENTITY != '' run: | helper=packages/stim-cli/native/fsevents/build/unzipped/stim-fsevents codesign --verify --strict \ -R='identifier "dev.stim.fsevents" and anchor apple generic and certificate 1[field.1.2.840.113635.100.6.2.6] exists and certificate leaf[field.1.2.840.113635.100.6.1.13] exists and certificate leaf[subject.OU] = "R7E8P23K3N"' \ "$helper" for arch in arm64 x86_64; do lipo "$helper" -verify_arch "$arch" if ! codesign -d --verbose=2 --arch "$arch" "$helper" 2>&1 | grep -Eq '^CodeDirectory .*flags=0x[0-9a-f]+\([^)]*runtime'; then echo "::error::The $arch slice is not signed with the hardened runtime." exit 1 fi done - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 with: name: stim-fsevents-${{ env.VERSION }} path: | packages/stim-cli/native/fsevents/build/release/stim-fsevents-*.zip packages/stim-cli/native/fsevents/build/release/SHA256SUMS if-no-files-found: error - name: Refuse to publish a build that is not notarized if: github.event_name == 'push' run: | if [ -z "${FSEVENTS_SIGNING_IDENTITY:-}" ] || [ -z "${ASC_KEY_PATH:-}" ]; then echo "::error::A fsevents-v tag publishes only a Developer ID signed, notarized build. Set the signing and App Store Connect secrets, then re-run this job." exit 1 fi - name: Create the GitHub release if: github.event_name == 'push' env: GH_TOKEN: ${{ github.token }} run: | out=packages/stim-cli/native/fsevents/build/release if gh release view "$GITHUB_REF_NAME" > /dev/null 2>&1; then echo "::error::$GITHUB_REF_NAME already has a release. Never replace a published helper; if a draft was left by a run that stopped before publishing, delete that draft and re-run this job." exit 1 fi flags="--latest=false" case "$VERSION" in *-*) flags="$flags --prerelease" ;; esac gh release create "$GITHUB_REF_NAME" "$out/stim-fsevents-$VERSION.zip" "$out/SHA256SUMS" \ --draft --verify-tag $flags --title "Stim FSEvents helper $VERSION" \ --notes "The signed macOS helper that stimd runs to learn which checkouts changed. \`SHA256SUMS\` lists the checksums of the zip and of the \`stim-fsevents\` binary inside it, which stim pins." gh release edit "$GITHUB_REF_NAME" --draft=false --latest=false cat "$out/SHA256SUMS" - name: Remove the signing keychain and API key if: always() run: | if [ -n "${FSEVENTS_KEYCHAIN:-}" ]; then security delete-keychain "$FSEVENTS_KEYCHAIN" || true; fi rm -rf "$RUNNER_TEMP/asc" "$RUNNER_TEMP/fsevents-cert.p12"