From 1add0564986ea595514722755535738ed58f7cb4 Mon Sep 17 00:00:00 2001 From: yougotwill Date: Thu, 20 Feb 2025 16:57:31 +1100 Subject: [PATCH] feat: combine latest-mac.yml files from both architectures for autoupdates since we have separate jobs the files are made separate and overwrite each other on github. --- .github/workflows/build-binaries.yml | 31 ++++++++--------- build/afterAllArtifactBuild.js | 51 ++++++++++++++++++++++++++++ package.json | 1 + 3 files changed, 67 insertions(+), 16 deletions(-) create mode 100644 build/afterAllArtifactBuild.js diff --git a/.github/workflows/build-binaries.yml b/.github/workflows/build-binaries.yml index 1afa85aae..75e3dbfe6 100644 --- a/.github/workflows/build-binaries.yml +++ b/.github/workflows/build-binaries.yml @@ -119,8 +119,9 @@ 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 - build_macos_x64: - runs-on: macos-13 + # 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: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} MAC_CERTIFICATE: ${{ secrets.MAC_CERTIFICATE }} @@ -137,38 +138,36 @@ jobs: - name: Setup & Build uses: ./actions/setup_and_build with: - cache_suffix: ${{ runner.os }} + cache_suffix: mac-arm64 # we want to test on all platforms since some are testing the rendered menus (and are dependent on the platform) - name: Unit Test run: yarn test - - name: Build but do not publish + - name: Build but do not publish ${{ runner.arch }} # 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 (x64) + - name: Upload artefacts ${{ runner.arch }} # 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 with: - upload_prefix: mac-x64 + upload_prefix: mac-arm64 multiarch_build: 'true' - - name: Build & publish + - name: Build & publish ${{ runner.arch }} # 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 }} - # We want both arm64 and intel mac builds, but the x64 binaries built on an arm64 runner will not build native modules correctly https://github.com/electron-userland/electron-builder/issues/8646 - # However building both will give us a valid latest-mac.yml for auto updating https://github.com/electron-userland/electron-builder/issues/6643 - build_macos_arm64: - runs-on: macos-14 + build_mac_x64: + runs-on: macos-13 env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} MAC_CERTIFICATE: ${{ secrets.MAC_CERTIFICATE }} @@ -185,28 +184,28 @@ jobs: - name: Setup & Build uses: ./actions/setup_and_build with: - cache_suffix: ${{ runner.os }} + cache_suffix: mac-x64 # we want to test on all platforms since some are testing the rendered menus (and are dependent on the platform) - name: Unit Test run: yarn test - - name: Build but do not publish + - name: Build but do not publish ${{ runner.arch }} # 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 (arm64) + - name: Upload artefacts ${{ runner.arch }} # 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 with: - upload_prefix: mac-arm64 + upload_prefix: mac-x64 multiarch_build: 'true' - - name: Build & publish + - name: Build & publish ${{ runner.arch }} # we want this to run only when on "push" to "master" if: ${{ env.SHOULD_PUBLISH == 'true' || env.SHOULD_PUBLISH_ALPHA == 'true' }} run: | diff --git a/build/afterAllArtifactBuild.js b/build/afterAllArtifactBuild.js new file mode 100644 index 000000000..97ef37f6f --- /dev/null +++ b/build/afterAllArtifactBuild.js @@ -0,0 +1,51 @@ +const os = require('os'); +const path = require('path'); +const fs = require('fs'); +const util = require('util'); + +const existsAsync = util.promisify(fs.exists); +const readAsync = util.promisify(fs.readFile); +const renameAsync = util.promisify(fs.rename); +const writeAsync = util.promisify(fs.writeFile); + +const builds = []; + +exports.default = async function (context) { + // Update the latest-mac.yml on macOS only. + if (process.platform !== 'darwin') { + return; + } + + const sourceLatestYML = path.join(context.outDir, 'latest-mac.yml'); + // return if there is no latest-mac.yml file + if (!(await existsAsync(sourceLatestYML))) { + return; + } + + console.log(`afterAllArtifactBuild hook triggered on ${os.arch()}`); + + const targetHostYML = path.join(context.outDir, `latest-${os.arch()}-mac.yml`); + // rename latest-mac.yml to latest-{arm64 or x64}-mac.yml + await renameAsync(sourceLatestYML, targetHostYML); + console.log(`Renamed ${sourceLatestYML} to ${targetHostYML}`); + builds.push(targetHostYML); + + if (builds.length === 2) { + console.log('Both builds are complete'); + // we want to combine the files from both latest-arm64-mac.yml and latest-x64-mac.yml into latest-mac.yml + const targetLatestYML = path.join(context.outDir, 'latest-mac.yml'); + const arm64YML = builds.find(file => file.includes('arm64')); + const x64YML = builds.find(file => file.includes('x64')); + const arm64YMLContent = await readAsync(arm64YML, 'utf8'); + const x64YMLContent = await readAsync(x64YML, 'utf8'); + // read the files key from the x64 file and add it to the arm64 file in the files key + const x64FilesKey = x64YMLContent.match(/files:\n([\s\S]*?)\n\n/)[1]; + console.log('x64FilesKey', x64FilesKey); + const arm64YMLContentWithX64Files = arm64YMLContent.replace('files:', `files:\n${x64FilesKey}`); + await writeAsync(targetLatestYML, arm64YMLContentWithX64Files); + console.log(`Combined ${arm64YML} and ${x64YML} into ${targetLatestYML}`); + } + + // you can return additional files to publish + return [targetHostYML]; +}; diff --git a/package.json b/package.json index aec31ddb6..0bfd50195 100644 --- a/package.json +++ b/package.json @@ -213,6 +213,7 @@ "appId": "com.loki-project.messenger-desktop", "afterSign": "build/notarize.js", "afterPack": "build/afterPackHook.js", + "afterAllArtifactBuild": "build/afterAllArtifactBuild.js", "artifactName": "${name}-${os}-${arch}-${version}.${ext}", "generateUpdatesFilesForAllChannels": true, "extraResources": [