From 822d10528f5fc3d4b936e89ef65c8a91aac94cef Mon Sep 17 00:00:00 2001 From: Kevin Yue Date: Sun, 19 Jul 2026 17:35:16 +0800 Subject: [PATCH] ci: publish macOS release artifacts --- .github/workflows/build.yaml | 223 +++++++++++++++++ .github/workflows/publish-macos-appcast.yaml | 240 +++++++++++++++++++ scripts/gh-release.sh | 26 +- 3 files changed, 483 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/publish-macos-appcast.yaml diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 7f0d9c9..fb15eb7 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -10,6 +10,11 @@ on: description: 'gpgui branch to use for the snapshot release' required: true default: dev + build_macos: + description: 'Build signed and notarized Apple Silicon artifacts for the snapshot release' + required: true + default: false + type: boolean build_bsd: description: 'Build FreeBSD/OpenBSD packages for the snapshot release' required: true @@ -325,6 +330,205 @@ jobs: gpgui-source/*.bin.tar.xz gpgui-source/*.bin.tar.xz.sha256 + build-gpgui-macos: + if: ${{ startsWith(github.ref, 'refs/tags/') || (github.event_name == 'workflow_dispatch' && inputs.build_macos) }} + runs-on: macos-15 + environment: macos-release + name: build-gpgui (macOS, arm64) + outputs: + archive_name: ${{ steps.release.outputs.archive_name }} + steps: + - name: Verify runner architecture + run: test "$(uname -m)" = arm64 + + - uses: pnpm/action-setup@v5 + with: + version: 9.15.1 + + - name: Prepare workspace + run: rm -rf gpgui-source && mkdir gpgui-source + + - name: Checkout GlobalProtect-openconnect + uses: actions/checkout@v6 + with: + token: ${{ secrets.GH_PAT }} + repository: yuezk/GlobalProtect-openconnect + ref: ${{ github.event_name == 'workflow_dispatch' && inputs.gp_branch || github.ref }} + path: gpgui-source/gp + submodules: recursive + + - name: Checkout gpgui + uses: actions/checkout@v6 + with: + token: ${{ secrets.GH_PAT }} + repository: yuezk/gpgui + ref: ${{ github.event_name == 'workflow_dispatch' && inputs.gpgui_branch || github.ref_name }} + path: gpgui-source/gpgui + + - uses: actions/setup-node@v6 + with: + node-version: 22 + cache: pnpm + cache-dependency-path: gpgui-source/gpgui/app/pnpm-lock.yaml + + - name: Validate release versions + id: release + run: | + set -euo pipefail + + gp_version="$(sed -n 's/^version = "\([^"]*\)"/\1/p' gpgui-source/gp/Cargo.toml | head -1)" + gpgui_version="$(sed -n 's/^version = "\([^"]*\)"/\1/p' gpgui-source/gpgui/Cargo.toml | head -1)" + if [[ -z "$gp_version" || "$gp_version" != "$gpgui_version" ]]; then + echo "gp and gpgui versions must match: gp=$gp_version, gpgui=$gpgui_version" >&2 + exit 1 + fi + + build_number="${{ github.run_number }}.${{ github.run_attempt }}" + if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then + channel="snapshot" + release_tag="snapshot" + artifact_version="$gpgui_version-snapshot.$build_number" + feed_url="https://github.com/${{ github.repository }}/releases/download/snapshot/appcast.xml" + else + channel="stable" + release_tag="${{ github.ref_name }}" + artifact_version="$gpgui_version" + feed_url="https://github.com/${{ github.repository }}/releases/latest/download/appcast.xml" + if [[ "$release_tag" != "v$gpgui_version" ]]; then + echo "Release tag $release_tag does not match gpgui version $gpgui_version" >&2 + exit 1 + fi + fi + + archive_name="GP-Connect-$artifact_version-arm64.zip" + { + echo "MACOS_BUILD_NUMBER=$build_number" + echo "MACOS_ARTIFACT_VERSION=$artifact_version" + echo "SPARKLE_FEED_URL=$feed_url" + echo "RELEASE_TAG=$release_tag" + echo "UPDATE_CHANNEL=$channel" + } >> "$GITHUB_ENV" + echo "archive_name=$archive_name" >> "$GITHUB_OUTPUT" + + - name: Install build dependencies + run: | + brew install \ + autoconf \ + automake \ + dylibbundler \ + gettext \ + gmp \ + gnutls \ + libidn2 \ + libtool \ + libtasn1 \ + libunistring \ + lz4 \ + nettle \ + openssl@3 \ + p11-kit \ + pkgconf + + - name: Import signing identity + env: + MACOS_CERTIFICATE_P12: ${{ secrets.MACOS_CERTIFICATE_P12 }} + MACOS_CERTIFICATE_PASSWORD: ${{ secrets.MACOS_CERTIFICATE_PASSWORD }} + APPLE_NOTARY_KEY_P8: ${{ secrets.APPLE_NOTARY_KEY_P8 }} + APPLE_NOTARY_KEY_ID: ${{ secrets.APPLE_NOTARY_KEY_ID }} + APPLE_NOTARY_ISSUER_ID: ${{ secrets.APPLE_NOTARY_ISSUER_ID }} + run: | + set -euo pipefail + + for variable in \ + MACOS_CERTIFICATE_P12 \ + MACOS_CERTIFICATE_PASSWORD \ + APPLE_NOTARY_KEY_P8 \ + APPLE_NOTARY_KEY_ID \ + APPLE_NOTARY_ISSUER_ID; do + if [[ -z "${!variable:-}" ]]; then + echo "$variable is not configured" >&2 + exit 1 + fi + done + + keychain="$RUNNER_TEMP/gp-connect.keychain-db" + keychain_password="$(openssl rand -hex 24)" + certificate="$RUNNER_TEMP/developer-id.p12" + notary_key="$RUNNER_TEMP/AuthKey.p8" + notary_profile="gp-connect-ci" + + printf '%s' "$MACOS_CERTIFICATE_P12" | base64 -D > "$certificate" + printf '%s' "$APPLE_NOTARY_KEY_P8" > "$notary_key" + chmod 600 "$certificate" "$notary_key" + + security create-keychain -p "$keychain_password" "$keychain" + security set-keychain-settings -lut 21600 "$keychain" + security unlock-keychain -p "$keychain_password" "$keychain" + security import "$certificate" -k "$keychain" \ + -P "$MACOS_CERTIFICATE_PASSWORD" -A -t cert -f pkcs12 + security set-key-partition-list -S apple-tool:,apple: \ + -s -k "$keychain_password" "$keychain" + security list-keychains -d user -s "$keychain" login.keychain-db + + identity="$(security find-identity -v -p codesigning "$keychain" \ + | sed -n 's/.*"\(Developer ID Application:.*\)"/\1/p' | head -1)" + if [[ -z "$identity" ]]; then + echo "Developer ID Application identity was not found" >&2 + exit 1 + fi + + xcrun notarytool store-credentials "$notary_profile" \ + --key "$notary_key" \ + --key-id "$APPLE_NOTARY_KEY_ID" \ + --issuer "$APPLE_NOTARY_ISSUER_ID" \ + --keychain "$keychain" + + { + echo "CI_KEYCHAIN=$keychain" + echo "MACOS_SIGN_IDENTITY=$identity" + echo "APPLE_NOTARY_PROFILE=$notary_profile" + echo "APPLE_NOTARY_KEYCHAIN=$keychain" + } >> "$GITHUB_ENV" + + - name: Build signed and notarized application + env: + SPARKLE_PUBLIC_KEY: ${{ vars.SPARKLE_PUBLIC_KEY }} + run: | + set -euo pipefail + cd gpgui-source/gpgui + ./scripts/build-macos.sh dmg release + + - name: Prepare release assets + run: | + set -euo pipefail + + artifact_dir="gpgui-source/artifacts" + mkdir -p "$artifact_dir" + dmg_name="GP-Connect-$MACOS_ARTIFACT_VERSION-arm64.dmg" + archive_name="GP-Connect-$MACOS_ARTIFACT_VERSION-arm64.zip" + mv "gpgui-source/gpgui/target/release/bundle/dmg/GP Connect.dmg" \ + "$artifact_dir/$dmg_name" + mv "gpgui-source/gpgui/target/release/bundle/sparkle/$archive_name" \ + "$artifact_dir/$archive_name" + + for file in "$artifact_dir"/*; do + shasum -a 256 "$file" > "$file.sha256" + done + + - name: Upload macOS artifacts + uses: actions/upload-artifact@v7 + with: + name: artifact-gpgui-macos-arm64 + if-no-files-found: error + path: gpgui-source/artifacts/* + + - name: Remove signing keychain + if: ${{ always() }} + run: | + if [[ -n "${CI_KEYCHAIN:-}" && -f "$CI_KEYCHAIN" ]]; then + security delete-keychain "$CI_KEYCHAIN" + fi + setup-bsd-matrix: runs-on: ubuntu-latest outputs: @@ -558,6 +762,7 @@ jobs: - build-gp - build-docker-image - build-gpgui + - build-gpgui-macos - setup-bsd-matrix - build-gpgui-frontend - build-bsd @@ -567,6 +772,7 @@ jobs: env: NEEDS_JSON: ${{ toJson(needs) }} BSD_MATRIX_ENABLED: ${{ needs.setup-bsd-matrix.outputs.enabled }} + MACOS_BUILD_ENABLED: ${{ startsWith(github.ref, 'refs/tags/') || inputs.build_macos }} IS_TAG: ${{ startsWith(github.ref, 'refs/tags/') }} run: | python3 - <<'PY' @@ -576,6 +782,7 @@ jobs: needs = json.loads(os.environ["NEEDS_JSON"]) bsd_matrix_enabled = os.environ["BSD_MATRIX_ENABLED"] == "true" + macos_build_enabled = os.environ["MACOS_BUILD_ENABLED"] == "true" is_tag = os.environ["IS_TAG"] == "true" failed = [] @@ -587,6 +794,8 @@ jobs: continue elif name in {"build-gpgui-frontend", "build-bsd"} and result == "skipped" and not bsd_matrix_enabled: continue + elif name == "build-gpgui-macos" and result == "skipped" and not macos_build_enabled: + continue elif result == "skipped": failed.append(f"{name}: {result}") @@ -653,6 +862,20 @@ jobs: run: | cd gh-release/gp/scripts && ./gh-release.sh "$RELEASE_TAG" + publish-macos-appcast: + if: ${{ startsWith(github.ref, 'refs/tags/') || (github.event_name == 'workflow_dispatch' && inputs.build_macos) }} + permissions: + contents: write + needs: + - gh-release + - build-gpgui-macos + uses: ./.github/workflows/publish-macos-appcast.yaml + with: + channel: ${{ github.event_name == 'workflow_dispatch' && 'snapshot' || 'stable' }} + release_tag: ${{ github.event_name == 'workflow_dispatch' && 'snapshot' || github.ref_name }} + archive_name: ${{ needs.build-gpgui-macos.outputs.archive_name }} + secrets: inherit + publish-docker-image: needs: - build-docker-image diff --git a/.github/workflows/publish-macos-appcast.yaml b/.github/workflows/publish-macos-appcast.yaml new file mode 100644 index 0000000..5f292c3 --- /dev/null +++ b/.github/workflows/publish-macos-appcast.yaml @@ -0,0 +1,240 @@ +name: Publish macOS appcast + +on: + workflow_call: + inputs: + channel: + required: true + type: string + release_tag: + required: true + type: string + archive_name: + required: false + type: string + default: '' + workflow_dispatch: + inputs: + channel: + description: Update channel + required: true + type: choice + options: + - stable + - snapshot + release_tag: + description: Release containing the macOS update archive + required: true + type: string + archive_name: + description: Exact ZIP asset name; leave empty when the release has one macOS update archive + required: false + type: string + +concurrency: + group: macos-appcast-${{ inputs.channel }} + cancel-in-progress: false + +jobs: + publish: + runs-on: macos-15 + environment: macos-release + permissions: + contents: write + env: + REPOSITORY: ${{ github.repository }} + RELEASE_TAG: ${{ inputs.release_tag }} + CHANNEL: ${{ inputs.channel }} + REQUESTED_ARCHIVE: ${{ inputs.archive_name }} + SPARKLE_VERSION: 2.9.2 + SPARKLE_ARCHIVE_SHA256: b83e37436774556ed055e0244b297ef2c790e0737393bf65bf495fcbba6eed65 + steps: + - name: Validate inputs + env: + SPARKLE_PRIVATE_KEY: ${{ secrets.SPARKLE_PRIVATE_KEY }} + run: | + set -euo pipefail + + if [[ "$CHANNEL" != "stable" && "$CHANNEL" != "snapshot" ]]; then + echo "channel must be stable or snapshot" >&2 + exit 1 + fi + if [[ "$CHANNEL" == "snapshot" && "$RELEASE_TAG" != "snapshot" ]]; then + echo "The snapshot channel must publish to the snapshot release" >&2 + exit 1 + fi + if [[ "$CHANNEL" == "stable" && "$RELEASE_TAG" == "snapshot" ]]; then + echo "The stable channel cannot publish to the snapshot release" >&2 + exit 1 + fi + if [[ -z "$SPARKLE_PRIVATE_KEY" ]]; then + echo "SPARKLE_PRIVATE_KEY is not configured" >&2 + exit 1 + fi + + - name: Prepare Sparkle tools + run: | + set -euo pipefail + + archive="$RUNNER_TEMP/Sparkle.zip" + curl --fail --location --silent --show-error \ + "https://github.com/sparkle-project/Sparkle/releases/download/$SPARKLE_VERSION/Sparkle-for-Swift-Package-Manager.zip" \ + --output "$archive" + echo "$SPARKLE_ARCHIVE_SHA256 $archive" | shasum -a 256 --check + ditto -x -k "$archive" "$RUNNER_TEMP/sparkle" + test -x "$RUNNER_TEMP/sparkle/Sparkle/bin/generate_appcast" + + - name: Download update archive + id: archive + env: + GH_TOKEN: ${{ github.token }} + run: | + set -euo pipefail + + mkdir -p "$RUNNER_TEMP/updates" + archive_name="$REQUESTED_ARCHIVE" + if [[ -z "$archive_name" ]]; then + archives="$(gh release view "$RELEASE_TAG" --repo "$REPOSITORY" --json assets \ + --jq '.assets[].name | select(test("^GP-Connect-.*-arm64\\.zip$"))')" + archive_count="$(printf '%s\n' "$archives" | sed '/^$/d' | wc -l | tr -d ' ')" + if [[ "$archive_count" != "1" ]]; then + echo "Expected one macOS update archive on $RELEASE_TAG, found $archive_count" >&2 + printf '%s\n' "$archives" >&2 + exit 1 + fi + archive_name="$archives" + fi + + if [[ ! "$archive_name" =~ ^GP-Connect-[0-9A-Za-z._-]+-arm64\.zip$ ]]; then + echo "Invalid macOS update archive name: $archive_name" >&2 + exit 1 + fi + + gh release download "$RELEASE_TAG" --repo "$REPOSITORY" \ + --pattern "$archive_name" --dir "$RUNNER_TEMP/updates" + echo "name=$archive_name" >> "$GITHUB_OUTPUT" + echo "path=$RUNNER_TEMP/updates/$archive_name" >> "$GITHUB_OUTPUT" + + - name: Verify update archive + id: bundle + env: + ARCHIVE_PATH: ${{ steps.archive.outputs.path }} + run: | + set -euo pipefail + + extract_dir="$RUNNER_TEMP/extracted" + ditto -x -k "$ARCHIVE_PATH" "$extract_dir" + app="$extract_dir/GP Connect.app" + test -d "$app" + codesign --verify --deep --strict --verbose=2 "$app" + xcrun stapler validate "$app" + + signing_info="$(codesign -d --verbose=4 "$app" 2>&1)" + grep -q '^Authority=Developer ID Application:' <<<"$signing_info" + grep -q '^CodeDirectory .*flags=.*runtime' <<<"$signing_info" + + identifier="$(sed -n 's/^Identifier=//p' <<<"$signing_info")" + if [[ "$identifier" != "com.yuezk.gpgui" ]]; then + echo "Unexpected bundle identifier: $identifier" >&2 + exit 1 + fi + file "$app/Contents/MacOS/gpgui" | grep -q 'arm64' + + feed_url="$(plutil -extract SUFeedURL raw "$app/Contents/Info.plist")" + expected_feed="https://github.com/$REPOSITORY/releases/latest/download/appcast.xml" + if [[ "$CHANNEL" == "snapshot" ]]; then + expected_feed="https://github.com/$REPOSITORY/releases/download/snapshot/appcast.xml" + fi + if [[ "$feed_url" != "$expected_feed" ]]; then + echo "Unexpected Sparkle feed URL: $feed_url" >&2 + exit 1 + fi + + bundle_version="$(plutil -extract CFBundleVersion raw "$app/Contents/Info.plist")" + short_version="$(plutil -extract CFBundleShortVersionString raw "$app/Contents/Info.plist")" + if [[ ! "$bundle_version" =~ ^[0-9]+(\.[0-9]+){0,2}$ ]]; then + echo "Invalid bundle version: $bundle_version" >&2 + exit 1 + fi + echo "version=$bundle_version" >> "$GITHUB_OUTPUT" + echo "short_version=$short_version" >> "$GITHUB_OUTPUT" + + - name: Prepare release notes + env: + ARCHIVE_NAME: ${{ steps.archive.outputs.name }} + GH_TOKEN: ${{ github.token }} + run: | + set -euo pipefail + + notes="$RUNNER_TEMP/updates/${ARCHIVE_NAME%.zip}.md" + gh release view "$RELEASE_TAG" --repo "$REPOSITORY" --json body --jq '.body // ""' > "$notes" + if [[ ! -s "$notes" ]]; then + printf 'GP Connect %s\n' '${{ steps.bundle.outputs.short_version }}' > "$notes" + fi + + - name: Generate appcast + env: + ARCHIVE_NAME: ${{ steps.archive.outputs.name }} + SPARKLE_PRIVATE_KEY: ${{ secrets.SPARKLE_PRIVATE_KEY }} + run: | + set -euo pipefail + + embedded_public_key="$(plutil -extract SUPublicEDKey raw \ + "$RUNNER_TEMP/extracted/GP Connect.app/Contents/Info.plist")" + derived_public_key="$(swift -e ' + import Foundation + import CryptoKit + let encoded = ProcessInfo.processInfo.environment["SPARKLE_PRIVATE_KEY"]! + .trimmingCharacters(in: .whitespacesAndNewlines) + let privateKey = try Curve25519.Signing.PrivateKey( + rawRepresentation: Data(base64Encoded: encoded)!) + print(privateKey.publicKey.rawRepresentation.base64EncodedString()) + ')" + if [[ "$derived_public_key" != "$embedded_public_key" ]]; then + echo "Sparkle private key does not match the public key embedded in the application" >&2 + exit 1 + fi + + download_prefix="https://github.com/$REPOSITORY/releases/download/$RELEASE_TAG/" + printf '%s' "$SPARKLE_PRIVATE_KEY" | \ + "$RUNNER_TEMP/sparkle/Sparkle/bin/generate_appcast" \ + --download-url-prefix "$download_prefix" \ + --maximum-deltas 0 \ + --embed-release-notes \ + --ed-key-file - \ + "$RUNNER_TEMP/updates" + + appcast="$RUNNER_TEMP/updates/appcast.xml" + test -s "$appcast" + grep -Fq "sparkle:version>${{ steps.bundle.outputs.version }}<" "$appcast" + grep -Fq "sparkle:shortVersionString>${{ steps.bundle.outputs.short_version }}<" "$appcast" + grep -Fq "url=\"$download_prefix$ARCHIVE_NAME\"" "$appcast" + grep -q 'sparkle:edSignature=' "$appcast" + + - name: Publish appcast + env: + GH_TOKEN: ${{ github.token }} + run: | + set -euo pipefail + + gh release upload "$RELEASE_TAG" "$RUNNER_TEMP/updates/appcast.xml" \ + --repo "$REPOSITORY" --clobber + + - name: Verify published appcast + run: | + set -euo pipefail + + if [[ "$CHANNEL" == "stable" ]]; then + feed_url="https://github.com/$REPOSITORY/releases/latest/download/appcast.xml" + else + feed_url="https://github.com/$REPOSITORY/releases/download/$RELEASE_TAG/appcast.xml" + fi + for _ in 1 2 3 4 5 6 7 8 9 10; do + published_appcast="$(curl --fail --location --silent --show-error "$feed_url" || true)" + if grep -Fq "sparkle:version>${{ steps.bundle.outputs.version }}<" <<<"$published_appcast"; then + exit 0 + fi + sleep 3 + done + echo "Published appcast did not become available at $feed_url" >&2 + exit 1 diff --git a/scripts/gh-release.sh b/scripts/gh-release.sh index e31c423..85891f5 100755 --- a/scripts/gh-release.sh +++ b/scripts/gh-release.sh @@ -30,18 +30,32 @@ release_assets() { "$SCRIPT_DIR/release-assets.sh" "$TAG" } -# For snapshot release, we don't create a release, just clear the existing assets and upload new ones. -# This is to avoid notification spam. +# Update the existing snapshot release in place to avoid notification spam. +# Preserve its macOS update assets when the current run does not replace them. release_snapshot() { - while IFS= read -r asset; do - if [ -n "$asset" ]; then - gh -R "$REPO" release delete-asset "$TAG" "$asset" --yes + mapfile -t files < <(release_assets) + local includes_macos=false + local file + for file in "${files[@]}"; do + if [[ "$(basename "$file")" == GP-Connect-*-arm64.* ]]; then + includes_macos=true + break fi + done + + while IFS= read -r asset; do + if [[ -z "$asset" ]]; then + continue + fi + if [[ "$includes_macos" == "false" && \ + ( "$asset" == "appcast.xml" || "$asset" == GP-Connect-*-arm64.* ) ]]; then + continue + fi + gh -R "$REPO" release delete-asset "$TAG" "$asset" --yes done < <(gh -R "$REPO" release view "$TAG" --json assets --jq '.assets[].name') echo "Uploading new assets..." # Upload all artifacts for snapshot release because we don't need to guarantee stability. - mapfile -t files < <(release_assets) upload_files "${files[@]}" }