Skip to content

Commit 6589758

Browse files
Merge pull request #136 from MatteoPologruto/arm64-support
Add support for macos arm64 build
2 parents 3150919 + 8e570a3 commit 6589758

File tree

2 files changed

+145
-1
lines changed

2 files changed

+145
-1
lines changed

Diff for: .github/workflows/release-go-task.yml

+122-1
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,138 @@ jobs:
4848
if-no-files-found: error
4949
name: ${{ env.ARTIFACT_NAME }}
5050
path: ${{ env.DIST_DIR }}
51+
52+
notarize-macos:
53+
name: Notarize ${{ matrix.artifact.name }}
54+
runs-on: macos-latest
55+
needs: create-release-artifacts
56+
outputs:
57+
checksum-darwin_amd64: ${{ steps.re-package.outputs.checksum-darwin_amd64 }}
58+
checksum-darwin_arm64: ${{ steps.re-package.outputs.checksum-darwin_arm64 }}
59+
60+
env:
61+
GON_CONFIG_PATH: gon.config.hcl
62+
63+
strategy:
64+
matrix:
65+
artifact:
66+
- name: darwin_amd64
67+
path: "macOS_64bit.tar.gz"
68+
- name: darwin_arm64
69+
path: "macOS_ARM64.tar.gz"
70+
71+
steps:
72+
- name: Checkout repository
73+
uses: actions/checkout@v3
74+
75+
- name: Download artifacts
76+
uses: actions/download-artifact@v3
77+
with:
78+
name: ${{ env.ARTIFACT_NAME }}
79+
path: ${{ env.DIST_DIR }}
80+
81+
- name: Import Code-Signing Certificates
82+
env:
83+
KEYCHAIN: "sign.keychain"
84+
INSTALLER_CERT_MAC_PATH: "/tmp/ArduinoCerts2020.p12"
85+
KEYCHAIN_PASSWORD: keychainpassword # Arbitrary password for a keychain that exists only for the duration of the job, so not secret
86+
run: |
87+
echo "${{ secrets.INSTALLER_CERT_MAC_P12 }}" | base64 --decode > "${{ env.INSTALLER_CERT_MAC_PATH }}"
88+
security create-keychain -p "${{ env.KEYCHAIN_PASSWORD }}" "${{ env.KEYCHAIN }}"
89+
security default-keychain -s "${{ env.KEYCHAIN }}"
90+
security unlock-keychain -p "${{ env.KEYCHAIN_PASSWORD }}" "${{ env.KEYCHAIN }}"
91+
security import \
92+
"${{ env.INSTALLER_CERT_MAC_PATH }}" \
93+
-k "${{ env.KEYCHAIN }}" \
94+
-f pkcs12 \
95+
-A \
96+
-T "/usr/bin/codesign" \
97+
-P "${{ secrets.INSTALLER_CERT_MAC_PASSWORD }}"
98+
security set-key-partition-list \
99+
-S apple-tool:,apple: \
100+
-s \
101+
-k "${{ env.KEYCHAIN_PASSWORD }}" \
102+
"${{ env.KEYCHAIN }}"
103+
104+
- name: Install gon for code signing and app notarization
105+
run: |
106+
wget -q https://github.com/mitchellh/gon/releases/download/v0.2.3/gon_macos.zip
107+
unzip gon_macos.zip -d /usr/local/bin
108+
109+
- name: Write gon config to file
110+
# gon does not allow env variables in config file (https://github.com/mitchellh/gon/issues/20)
111+
run: |
112+
cat > "${{ env.GON_CONFIG_PATH }}" <<EOF
113+
# See: https://github.com/mitchellh/gon#configuration-file
114+
source = ["${{ env.DIST_DIR }}/${{ env.PROJECT_NAME }}_osx_${{ matrix.artifact.name }}/${{ env.PROJECT_NAME }}"]
115+
bundle_id = "cc.arduino.${{ env.PROJECT_NAME }}"
116+
117+
sign {
118+
application_identity = "Developer ID Application: ARDUINO SA (7KT7ZWMCJT)"
119+
}
120+
121+
# Ask Gon for zip output to force notarization process to take place.
122+
# The CI will ignore the zip output, using the signed binary only.
123+
zip {
124+
output_path = "unused.zip"
125+
}
126+
EOF
127+
128+
- name: Sign and notarize binary
129+
env:
130+
AC_USERNAME: ${{ secrets.AC_USERNAME }}
131+
AC_PASSWORD: ${{ secrets.AC_PASSWORD }}
132+
run: |
133+
gon "${{ env.GON_CONFIG_PATH }}"
134+
135+
- name: Re-package binary and output checksum
136+
id: re-package
137+
working-directory: ${{ env.DIST_DIR }}
138+
# This step performs the following:
139+
# 1. Repackage the signed binary replaced in place by Gon (ignoring the output zip file)
140+
# 2. Recalculate package checksum
141+
# 3. Output the new checksum to include in the nnnnnn-checksums.txt file
142+
# (it cannot be done there because of workflow job parallelization)
143+
run: |
144+
# GitHub's upload/download-artifact actions don't preserve file permissions,
145+
# so we need to add execution permission back until the action is made to do this.
146+
chmod +x "${{ env.PROJECT_NAME }}_osx_${{ matrix.artifact.name }}/${{ env.PROJECT_NAME }}"
147+
TAG="${GITHUB_REF/refs\/tags\//}"
148+
PACKAGE_FILENAME="${{ env.PROJECT_NAME }}_${TAG}_${{ matrix.artifact.path }}"
149+
tar -czvf "$PACKAGE_FILENAME" \
150+
-C "${{ env.PROJECT_NAME }}_osx_${{ matrix.artifact.name }}/" "${{ env.PROJECT_NAME }}" \
151+
-C ../../ LICENSE.txt
152+
CHECKSUM_LINE="$(shasum -a 256 $PACKAGE_FILENAME)"
153+
echo "PACKAGE_FILENAME=$PACKAGE_FILENAME" >> $GITHUB_ENV
154+
echo "::set-output name=checksum-${{ matrix.artifact.name }}::$CHECKSUM_LINE"
155+
156+
- name: Upload artifacts
157+
uses: actions/upload-artifact@v3
158+
with:
159+
if-no-files-found: error
160+
name: ${{ env.ARTIFACT_NAME }}
161+
path: ${{ env.DIST_DIR }}/${{ env.PACKAGE_FILENAME }}
51162

52163
create-release:
53164
runs-on: ubuntu-latest
54-
needs: create-release-artifacts
165+
needs: notarize-macos
55166

56167
steps:
57168
- name: Download artifact
58169
uses: actions/download-artifact@v3
59170
with:
60171
name: ${{ env.ARTIFACT_NAME }}
61172
path: ${{ env.DIST_DIR }}
173+
174+
- name: Update checksum
175+
run: |
176+
declare -a checksum_lines=("${{ needs.notarize-macos.outputs.checksum-darwin_amd64 }}" "${{ needs.notarize-macos.outputs.checksum-darwin_arm64 }}")
177+
for checksum_line in "${checksum_lines[@]}"
178+
do
179+
CHECKSUM=$(echo ${checksum_line} | cut -d " " -f 1)
180+
PACKAGE_FILENAME=$(echo ${checksum_line} | cut -d " " -f 2)
181+
perl -pi -w -e "s/.*${PACKAGE_FILENAME}/${CHECKSUM} ${PACKAGE_FILENAME}/g;" ${{ env.DIST_DIR }}/*-checksums.txt
182+
done
62183
63184
- name: Identify Prerelease
64185
# This is a workaround while waiting for create-release action

Diff for: DistTasks.yml

+23
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ tasks:
3434
- task: Linux_ARMv7
3535
- task: Linux_ARM64
3636
- task: macOS_64bit
37+
- task: macOS_ARM64
3738

3839
Windows_32bit:
3940
desc: Builds Windows 32 bit binaries
@@ -251,3 +252,25 @@ tasks:
251252
CONTAINER_TAG: "{{.GO_VERSION}}-darwin-debian10"
252253
PACKAGE_PLATFORM: "macOS_64bit"
253254
PACKAGE_NAME: "{{.PROJECT_NAME}}_{{.VERSION}}_{{.PACKAGE_PLATFORM}}.tar.gz"
255+
256+
macOS_ARM64:
257+
desc: Builds Mac OS X ARM64 binaries
258+
dir: "{{.DIST_DIR}}"
259+
cmds:
260+
- |
261+
docker run -v `pwd`/..:/home/build -w /home/build \
262+
-e CGO_ENABLED=1 \
263+
{{.CONTAINER}}:{{.CONTAINER_TAG}} \
264+
--build-cmd "{{.BUILD_COMMAND}}" \
265+
-p "{{.BUILD_PLATFORM}}"
266+
267+
tar cz -C {{.PLATFORM_DIR}} {{.PROJECT_NAME}} -C ../.. LICENSE.txt -f {{.PACKAGE_NAME}}
268+
sha256sum {{.PACKAGE_NAME}} >> {{.CHECKSUM_FILE}}
269+
270+
vars:
271+
PLATFORM_DIR: "{{.PROJECT_NAME}}_osx_darwin_arm64"
272+
BUILD_COMMAND: "go build -o {{.DIST_DIR}}/{{.PLATFORM_DIR}}/{{.PROJECT_NAME}} {{.LDFLAGS}}"
273+
BUILD_PLATFORM: "darwin/arm64"
274+
CONTAINER_TAG: "{{.GO_VERSION}}-darwin-arm64-debian10"
275+
PACKAGE_PLATFORM: "macOS_ARM64"
276+
PACKAGE_NAME: "{{.PROJECT_NAME}}_{{.VERSION}}_{{.PACKAGE_PLATFORM}}.tar.gz"

0 commit comments

Comments
 (0)