From 16271cdf28c6e83d1c13ff094c3188755b29042e Mon Sep 17 00:00:00 2001 From: pepix Date: Mon, 19 Dec 2022 16:25:17 +0900 Subject: [PATCH 1/3] Support arm64 binary generation --- CHANGELOG.md | 2 ++ package.json | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e0497832a..19dd1f911 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,8 @@ +- Support arm64 binary generation for Apple silicon users [#1342](https://github.com/danger/danger-js/pull/1342) [@pepix] + ## 11.2.0 diff --git a/package.json b/package.json index 3aad8bfc8..6ad672326 100644 --- a/package.json +++ b/package.json @@ -64,7 +64,8 @@ "build:pretty-types": "yarn prettier --write distribution/danger.d.ts; yarn prettier --parser flow distribution/danger.js.flow --write", "build:watch": "tsc -w", "link": "yarn run build && chmod +x distribution/commands/danger.js && yarn link", - "package": "yarn run pkg . --output brew-distribution/danger; zip -j brew-distribution/danger-macos.zip brew-distribution/danger; shasum -a 256 brew-distribution/danger-macos.zip", + "package:x64": "yarn run pkg . --output brew-distribution/danger-x64 --targets node16-macos-x64; zip -j brew-distribution/danger-macos-x64.zip brew-distribution/danger-x64; shasum -a 256 brew-distribution/danger-macos-x64.zip", + "package:arm64": "yarn run pkg . --output brew-distribution/danger-arm64 --targets node16-macos-arm64; zip -j brew-distribution/danger-macos-arm64.zip brew-distribution/danger-arm64; shasum -a 256 brew-distribution/danger-macos-arm64.zip", "declarations": "ts-node ./scripts/create-danger-dts.ts", "docs:cp_defs": "mkdir docs/docs_generate; cp source/danger.d.ts docs/docs_generate; cp node_modules/@octokit/rest/index.d.ts docs/docs_generate/github.d.ts", "docs": "yarn run docs:cp_defs; yarn typedoc --ignoreCompilerErrors --mode modules --json docs/js_ref_dsl_docs.json --includeDeclarations source", From 4efada71e01e4ddb6a44a7ee071d4995993f637b Mon Sep 17 00:00:00 2001 From: pepix Date: Wed, 21 Dec 2022 11:31:55 +0900 Subject: [PATCH 2/3] Update release-it.json and create-homebrew-tap-pr.sh --- .release-it.json | 4 ++-- CONTRIBUTING.md | 4 ++-- scripts/create-homebrew-tap-pr.sh | 37 +++++++++++++++++++++++-------- 3 files changed, 32 insertions(+), 13 deletions(-) diff --git a/.release-it.json b/.release-it.json index 3e05e518f..50c616a7a 100644 --- a/.release-it.json +++ b/.release-it.json @@ -3,10 +3,10 @@ "release": true, "assets": "brew-distribution/*.zip" }, - "buildCommand": "yarn package", + "buildCommand": "yarn package:x64; yarn package:arm64", "hooks": { "before:bump": "yarn declarations; yarn build:schemas", - "after:bump": "yarn package", + "after:bump": "yarn package:x64; yarn package:arm64", "after:release": "VERSION=${version} scripts/create-homebrew-tap-pr.sh" } } diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 65cf54ca8..5d7e4c143 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -40,8 +40,8 @@ Following [this commit](https://github.com/danger/danger-js/commit/a26ac3b3bd4f0 - Modify `changelog.md`, adding a new `### 0.21.0` heading under the `### Main` heading at the top of the file. - Commit both changes with the commit message **Version bump**. - Tag this commit - `git tag 0.21.0`. -- Push the commit and tag to master - `git push origin main --follow-tags`. Travis CI will build the tagged commit and - publish that tagged version to NPM. +- Push the commit and tag to master - `git push origin main --follow-tags`. GitHub Actions will build the tagged commit + and publish that tagged version to NPM. :ship: diff --git a/scripts/create-homebrew-tap-pr.sh b/scripts/create-homebrew-tap-pr.sh index 7a7442623..01d7d9455 100755 --- a/scripts/create-homebrew-tap-pr.sh +++ b/scripts/create-homebrew-tap-pr.sh @@ -2,15 +2,22 @@ [ -z ${VERSION+x} ] && { echo "VERSION is missing"; exit 1; } -FILE=brew-distribution/danger-macos.zip +FILE_X64=brew-distribution/danger-macos-x64.zip +FILE_ARM64=brew-distribution/danger-macos-arm64.zip -if [ ! -f ${FILE} ]; then - echo ${FILE} not found! +if [ ! -f ${FILE_X64} ]; then + echo ${FILE_X64} not found! + exit 1 +fi +if [ ! -f ${FILE_ARM64} ]; then + echo ${FILE_ARM64} not found! exit 1 fi -SHA=$(shasum -a 256 ${FILE} | cut -f 1 -d " ") -echo "$SHA" +SHA_X64=$(shasum -a 256 ${FILE_X64} | cut -f 1 -d " ") +echo "SHA_X64=$SHA_X64" +SHA_ARM64=$(shasum -a 256 ${FILE_ARM64} | cut -f 1 -d " ") +echo "SHA_ARM64=$SHA_ARM64" # Clone tap repo HOMEBREW_TAP_TMPDIR=$(mktemp -d) @@ -23,11 +30,23 @@ cd "$HOMEBREW_TAP_TMPDIR" || exit 1 # Write formula echo "class DangerJs < Formula" > danger-js.rb echo " homepage \"https://github.com/danger/danger-js\"" >> danger-js.rb -echo " url \"https://github.com/danger/danger-js/releases/download/${VERSION}/danger-macos.zip\"" >> danger-js.rb -echo " sha256 \"${SHA}\"" >> danger-js.rb echo >> danger-js.rb -echo " def install" >> danger-js.rb -echo " bin.install \"danger\"" >> danger-js.rb +echo " if Hardware::CPU.intel?" >> danger-js.rb +echo " url \"https://github.com/danger/danger-js/releases/download/${VERSION}/danger-macos-x64.zip\"" >> danger-js.rb +echo " sha256 \"${SHA_X64}\"" >> danger-js.rb +echo >> danger-js.rb +echo " def install" >> danger-js.rb +echo " bin.install \"danger-x64\" => \"danger\"" >> danger-js.rb +echo " end" >> danger-js.rb +echo " end" >> danger-js.rb +echo >> danger-js.rb +echo " if Hardware::CPU.arm?" >> danger-js.rb +echo " url \"https://github.com/danger/danger-js/releases/download/${VERSION}/danger-macos-arm64.zip\"" >> danger-js.rb +echo " sha256 \"${SHA_ARM64}\"" >> danger-js.rb +echo >> danger-js.rb +echo " def install" >> danger-js.rb +echo " bin.install \"danger-arm64\" => \"danger\"" >> danger-js.rb +echo " end" >> danger-js.rb echo " end" >> danger-js.rb echo "end" >> danger-js.rb From 40bdfe15ac41f7782478a780da48b3e436d65936 Mon Sep 17 00:00:00 2001 From: pepix Date: Sat, 24 Dec 2022 00:00:31 +0900 Subject: [PATCH 3/3] Add a new workflow to build binaries for macOS architectres on GitHub Actions --- .github/workflows/release.yml | 56 +++++++++++++++++++++++++++++++ .release-it.json | 2 +- package.json | 1 + scripts/create-homebrew-tap-pr.sh | 20 ++++++++--- 4 files changed, 73 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 000000000..48fe3eee7 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,56 @@ +name: Release executable files for macOS + +on: + workflow_dispatch: + inputs: + version_digit: + description: 'Version digit (major | minor | patch)' + required: true + default: 'patch' + type: choice + options: + - major + - minor + - patch + +jobs: + release: + runs-on: ubuntu-latest + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + HOMEBREW_TAP_DEPLOY_SECRET_KEY: ${{ secrets.HOMEBREW_TAP_DEPLOY_SECRET_KEY }} + permissions: write-all + steps: + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + + - name: Install ldid + uses: MOZGIII/install-ldid-action@v1 + with: + tag: v2.1.5-procursus6 + + - name: Check out repository code + uses: actions/checkout@v3 + + - name: Use node + uses: actions/setup-node@v3 + with: + node-version: "14" + + - name: Install dependencies + run: npm install + + - name: Build + run: npm run build + + - name: Package + run: | + git config --global user.email "action@github.com" + git config --global user.name "GitHub Action" + npm run release -- ${{ github.event.inputs.version_digit }} --ci + + - name: Update homebrew/tap repo for new release + shell: bash + run: scripts/create-homebrew-tap-pr.sh + env: + VERSION: ${{ env.VERSION }} \ No newline at end of file diff --git a/.release-it.json b/.release-it.json index 50c616a7a..356dd3347 100644 --- a/.release-it.json +++ b/.release-it.json @@ -7,6 +7,6 @@ "hooks": { "before:bump": "yarn declarations; yarn build:schemas", "after:bump": "yarn package:x64; yarn package:arm64", - "after:release": "VERSION=${version} scripts/create-homebrew-tap-pr.sh" + "after:release": "export VERSION=${version}; echo 'VERSION=${version}' >> $GITHUB_ENV" } } diff --git a/package.json b/package.json index 6ad672326..293466b67 100644 --- a/package.json +++ b/package.json @@ -64,6 +64,7 @@ "build:pretty-types": "yarn prettier --write distribution/danger.d.ts; yarn prettier --parser flow distribution/danger.js.flow --write", "build:watch": "tsc -w", "link": "yarn run build && chmod +x distribution/commands/danger.js && yarn link", + "package": "yarn run pkg . --output brew-distribution/danger; zip -j brew-distribution/danger-macos.zip brew-distribution/danger; shasum -a 256 brew-distribution/danger-macos.zip", "package:x64": "yarn run pkg . --output brew-distribution/danger-x64 --targets node16-macos-x64; zip -j brew-distribution/danger-macos-x64.zip brew-distribution/danger-x64; shasum -a 256 brew-distribution/danger-macos-x64.zip", "package:arm64": "yarn run pkg . --output brew-distribution/danger-arm64 --targets node16-macos-arm64; zip -j brew-distribution/danger-macos-arm64.zip brew-distribution/danger-arm64; shasum -a 256 brew-distribution/danger-macos-arm64.zip", "declarations": "ts-node ./scripts/create-danger-dts.ts", diff --git a/scripts/create-homebrew-tap-pr.sh b/scripts/create-homebrew-tap-pr.sh index 01d7d9455..ebf3287f2 100755 --- a/scripts/create-homebrew-tap-pr.sh +++ b/scripts/create-homebrew-tap-pr.sh @@ -19,14 +19,22 @@ echo "SHA_X64=$SHA_X64" SHA_ARM64=$(shasum -a 256 ${FILE_ARM64} | cut -f 1 -d " ") echo "SHA_ARM64=$SHA_ARM64" +# Set up SSH +mkdir -p ~/.ssh +echo "${HOMEBREW_TAP_DEPLOY_SECRET_KEY}" > ~/.ssh/id_rsa +chmod 600 ~/.ssh/id_rsa +git config --global user.name danger +git config --global user.email danger@users.noreply.github.com +eval "$(ssh-agent -s)" +ssh-add ~/.ssh/id_rsa +ssh-keyscan -H github.com >> ~/.ssh/known_hosts +ssh -o StrictHostKeyChecking=no -F /dev/null -vT git@github.com + # Clone tap repo HOMEBREW_TAP_TMPDIR=$(mktemp -d) -git clone --depth 1 https://github.com/danger/homebrew-tap.git "$HOMEBREW_TAP_TMPDIR" +git clone --depth 1 git@github.com:danger/homebrew-tap.git "$HOMEBREW_TAP_TMPDIR" cd "$HOMEBREW_TAP_TMPDIR" || exit 1 -# git config user.name danger -# git config user.email danger@users.noreply.github.com - # Write formula echo "class DangerJs < Formula" > danger-js.rb echo " homepage \"https://github.com/danger/danger-js\"" >> danger-js.rb @@ -53,4 +61,6 @@ echo "end" >> danger-js.rb # Commit changes git add danger-js.rb git commit -m "Releasing danger-js version ${VERSION}" -git push origin master +git remote rm origin +git remote add origin git@github.com:danger/homebrew-tap.git +git push origin master \ No newline at end of file