From 569fd66dfbd00d87c1fef4a738daa988eb3dce6c Mon Sep 17 00:00:00 2001 From: yougotwill Date: Wed, 5 Mar 2025 20:16:24 +1100 Subject: [PATCH] feat: setup release metadata correctly for mac builds combine latest-mac.yml files from both architectures in order for our aut update to work correctly --- .github/workflows/build-binaries.yml | 96 ++++++++++++++++++++++-- actions/upload_prod_artefacts/action.yml | 2 +- build/setup-mac-release-arch.sh | 18 +++++ build/setup-mac-release-combine.sh | 27 +++++++ 4 files changed, 135 insertions(+), 8 deletions(-) create mode 100644 build/setup-mac-release-arch.sh create mode 100644 build/setup-mac-release-combine.sh diff --git a/.github/workflows/build-binaries.yml b/.github/workflows/build-binaries.yml index 75e3dbfe6..a931f57a5 100644 --- a/.github/workflows/build-binaries.yml +++ b/.github/workflows/build-binaries.yml @@ -119,7 +119,7 @@ jobs: run: yarn build-release-publish # No other args needed for windows publish # We want both arm64 and intel mac builds, and according to this https://docs.github.com/en/actions/using-github-hosted-runners/using-github-hosted-runners/about-github-hosted-runners#supported-runners-and-hardware-resources macos-14 and above is always arm64 and macos-13 is the last intel runner - # Note x64 builds made on an arm64 host will not bundle the native modules correctly https://github.com/electron-userland/electron-builder/issues/8646 + # NOTE x64 builds made on an arm64 host will not bundle the native modules correctly https://github.com/electron-userland/electron-builder/issues/8646 build_mac_arm64: runs-on: macos-14 env: @@ -144,14 +144,14 @@ jobs: - name: Unit Test run: yarn test - - name: Build but do not publish ${{ runner.arch }} + - name: Build but do not publish # we want this to run always, except on "push" to "master" if: ${{ env.SHOULD_PUBLISH == 'false' && env.SHOULD_PUBLISH_ALPHA == 'false' }} run: | source ./build/setup-mac-certificate.sh yarn build-release --config.mac.bundleVersion=${{ github.ref }} - - name: Upload artefacts ${{ runner.arch }} + - name: Upload artefacts # we want this to run always, except on "push" to "master" if: ${{ env.SHOULD_PUBLISH == 'false' && env.SHOULD_PUBLISH_ALPHA == 'false' }} uses: ./actions/upload_prod_artefacts @@ -159,13 +159,27 @@ jobs: upload_prefix: mac-arm64 multiarch_build: 'true' - - name: Build & publish ${{ runner.arch }} + - name: Build & publish # we want this to run only when on "push" to "master" if: ${{ env.SHOULD_PUBLISH == 'true' || env.SHOULD_PUBLISH_ALPHA == 'true' }} run: | source ./build/setup-mac-certificate.sh yarn build-release-publish --config.mac.bundleVersion=${{ github.ref }} + - name: Setup release metadata + # we want this to run only when on "push" to "master" + if: ${{ env.SHOULD_PUBLISH == 'true' || env.SHOULD_PUBLISH_ALPHA == 'true' }} + run: | + source ./build/setup-mac-release-arch.sh + + - name: Upload release metadata + # we want this to run only when on "push" to "master" + if: ${{ env.SHOULD_PUBLISH == 'true' || env.SHOULD_PUBLISH_ALPHA == 'true' }} + uses: actions/upload-artifact@v4 + with: + name: latest-mac-arm64.yml + path: dist/latest-mac-arm64.yml + build_mac_x64: runs-on: macos-13 env: @@ -190,14 +204,14 @@ jobs: - name: Unit Test run: yarn test - - name: Build but do not publish ${{ runner.arch }} + - name: Build but do not publish # we want this to run always, except on "push" to "master" if: ${{ env.SHOULD_PUBLISH == 'false' && env.SHOULD_PUBLISH_ALPHA == 'false' }} run: | source ./build/setup-mac-certificate.sh yarn build-release --config.mac.bundleVersion=${{ github.ref }} - - name: Upload artefacts ${{ runner.arch }} + - name: Upload artefacts # we want this to run always, except on "push" to "master" if: ${{ env.SHOULD_PUBLISH == 'false' && env.SHOULD_PUBLISH_ALPHA == 'false' }} uses: ./actions/upload_prod_artefacts @@ -205,9 +219,77 @@ jobs: upload_prefix: mac-x64 multiarch_build: 'true' - - name: Build & publish ${{ runner.arch }} + - name: Build & publish # we want this to run only when on "push" to "master" if: ${{ env.SHOULD_PUBLISH == 'true' || env.SHOULD_PUBLISH_ALPHA == 'true' }} run: | source ./build/setup-mac-certificate.sh yarn build-release-publish --config.mac.bundleVersion=${{ github.ref }} + + - name: Setup release metadata + # we want this to run only when on "push" to "master" + if: ${{ env.SHOULD_PUBLISH == 'true' || env.SHOULD_PUBLISH_ALPHA == 'true' }} + run: | + source ./build/setup-mac-release-arch.sh + + - name: Upload release metadata + # we want this to run only when on "push" to "master" + if: ${{ env.SHOULD_PUBLISH == 'true' || env.SHOULD_PUBLISH_ALPHA == 'true' }} + uses: actions/upload-artifact@v4 + with: + name: latest-mac-x64.yml + path: dist/latest-mac-x64.yml + + post_build_mac: + needs: [build_mac_arm64, build_mac_x64] + runs-on: ubuntu-22.04 + steps: + - name: Checkout git repo + # we want this to run only when on "push" to "master" + if: ${{ env.SHOULD_PUBLISH == 'true' || env.SHOULD_PUBLISH_ALPHA == 'true' }} + uses: actions/checkout@v4 + + - name: Get version tag from package.json + id: get_version + # we want this to run only when on "push" to "master" + if: ${{ env.SHOULD_PUBLISH == 'true' || env.SHOULD_PUBLISH_ALPHA == 'true' }} + run: | + version=$(node -p "require('./package.json').version") + echo "VERSION_TAG=$version" >> "$GITHUB_OUTPUT" + + - name: Download release metadata + # we want this to run only when on "push" to "master" + if: ${{ env.SHOULD_PUBLISH == 'true' || env.SHOULD_PUBLISH_ALPHA == 'true' }} + uses: actions/download-artifact@v4 + with: + path: dist + pattern: latest-mac-* + merge-multiple: true + + - name: Combine release metadata + # we want this to run only when on "push" to "master" + if: ${{ env.SHOULD_PUBLISH == 'true' || env.SHOULD_PUBLISH_ALPHA == 'true' }} + run: | + source ./build/setup-mac-release-combine.sh + + - name: Upload release metadata + # we want this to run only when on "push" to "master" + if: ${{ env.SHOULD_PUBLISH == 'true' || env.SHOULD_PUBLISH_ALPHA == 'true' }} + uses: actions/upload-artifact@v4 + with: + name: latest-mac.yml + path: dist/latest-mac.yml + + - name: Upload changes to draft release + # we want this to run only when on "push" to "master" + if: ${{ env.SHOULD_PUBLISH == 'true' || env.SHOULD_PUBLISH_ALPHA == 'true' }} + uses: ncipollo/release-action@v1 + with: + tag: v${{ steps.get_version.outputs.VERSION_TAG }} + draft: true + name: "Draft" + artifacts: "dist/latest-mac.yml" + allowUpdates: true + omitNameDuringUpdate: true + replacesArtifacts: true + updateOnlyUnreleased: true diff --git a/actions/upload_prod_artefacts/action.yml b/actions/upload_prod_artefacts/action.yml index c12a3b141..1c02c4bcf 100644 --- a/actions/upload_prod_artefacts/action.yml +++ b/actions/upload_prod_artefacts/action.yml @@ -48,4 +48,4 @@ runs: uses: actions/upload-artifact@v4 with: name: ${{ inputs.upload_prefix }}-production - path: release/production-${{ inputs.upload_prefix }} + path: release diff --git a/build/setup-mac-release-arch.sh b/build/setup-mac-release-arch.sh new file mode 100644 index 000000000..48cf08909 --- /dev/null +++ b/build/setup-mac-release-arch.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +set -e + +RELEASE_DIR="./dist" +ARCH=$(uname -m) +echo "Setup release metadata for $ARCH architecture" + +if [[ "$ARCH" == "arm64" ]]; then + ls -t $RELEASE_DIR/latest-mac.yml | head -n 1 | xargs -I {} mv {} $RELEASE_DIR/latest-mac-$ARCH.yml + echo "Created latest-mac-$ARCH.yml" +elif [[ "$ARCH" == "x86_64" ]]; then + ls -t $RELEASE_DIR/latest-mac.yml | head -n 1 | xargs -I {} mv {} $RELEASE_DIR/latest-mac-x64.yml + echo "Created latest-mac-x64.yml" +else + echo "Unknown architecture: $ARCH" + exit 1 +fi diff --git a/build/setup-mac-release-combine.sh b/build/setup-mac-release-combine.sh new file mode 100644 index 000000000..6e0046485 --- /dev/null +++ b/build/setup-mac-release-combine.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash + +set -e + +RELEASE_DIR="./dist" +ARM64_FILE="$RELEASE_DIR/latest-mac-arm64.yml" +X64_FILE="$RELEASE_DIR/latest-mac-x64.yml" +OUTPUT_FILE="$RELEASE_DIR/latest-mac.yml" + +echo "Combined release metadata from both architectures" + +echo "version: $(grep 'version:' $ARM64_FILE | awk '{print $2}')" > $OUTPUT_FILE +echo "files:" >> $OUTPUT_FILE +grep 'url:' $ARM64_FILE | while read -r line; do + echo " $line" >> $OUTPUT_FILE + grep -A 2 " $line" $ARM64_FILE | tail -n 2 >> $OUTPUT_FILE +done +grep 'url:' $X64_FILE | while read -r line; do + echo " $line" >> $OUTPUT_FILE + grep -A 2 " $line" $X64_FILE | tail -n 2 >> $OUTPUT_FILE +done + +echo "path: $(grep 'path:' $ARM64_FILE | awk '{print $2}')" >> $OUTPUT_FILE +echo "sha512: $(grep 'sha512:' $ARM64_FILE | tail -n 1 | awk '{print $2}')" >> $OUTPUT_FILE +echo "releaseDate: $(grep 'releaseDate:' $ARM64_FILE | awk '{print $2}')" >> $OUTPUT_FILE + +echo "Created latest-mac.yml"