Skip to content

Commit 712ae23

Browse files
umbynosper1234
andcommitted
update release-go-crosscompile-task to support darwin arm64
Co-authored-by: per1234 <[email protected]>
1 parent cff1e0f commit 712ae23

File tree

4 files changed

+140
-40
lines changed

4 files changed

+140
-40
lines changed

workflow-templates/assets/release-go-crosscompile-task/DistTasks.yml

+17
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ tasks:
3232
- task: Linux_ARMv7
3333
- task: Linux_ARM64
3434
- task: macOS_64bit
35+
- task: macOS_ARM64
3536

3637
Windows_32bit:
3738
desc: Builds Windows 32 bit binaries
@@ -164,3 +165,19 @@ tasks:
164165
PLATFORM_DIR: "{{.PROJECT_NAME}}_osx_darwin_amd64"
165166
PACKAGE_PLATFORM: "macOS_64bit"
166167
PACKAGE_NAME: "{{.PROJECT_NAME}}_{{.VERSION}}_{{.PACKAGE_PLATFORM}}.tar.gz"
168+
169+
macOS_ARM64:
170+
desc: Builds Mac OS X ARM64 binaries
171+
env:
172+
GOOS: "darwin"
173+
GOARCH: "arm64"
174+
cmds:
175+
- |
176+
go build -o {{.DIST_DIR}}/{{.PLATFORM_DIR}}/{{.PROJECT_NAME}} {{.LDFLAGS}}
177+
cd {{.DIST_DIR}}
178+
tar cz -C {{.PLATFORM_DIR}} {{.PROJECT_NAME}} -C ../.. LICENSE.txt -f {{.PACKAGE_NAME}}
179+
sha256sum {{.PACKAGE_NAME}} >> {{.CHECKSUM_FILE}}
180+
vars:
181+
PLATFORM_DIR: "{{.PROJECT_NAME}}_osx_darwin_arm64"
182+
PACKAGE_PLATFORM: "macOS_ARM64"
183+
PACKAGE_NAME: "{{.PROJECT_NAME}}_{{.VERSION}}_{{.PACKAGE_PLATFORM}}.tar.gz"

workflow-templates/dependabot/workflow-template-copies/.github/workflows/release-go-crosscompile-task.yml

+60-14
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,23 @@ jobs:
5757
path: ${{ env.DIST_DIR }}
5858

5959
notarize-macos:
60+
name: Notarize ${{ matrix.artifact.name }}
6061
runs-on: macos-latest
6162
needs: create-release-artifacts
63+
outputs:
64+
checksum-darwin_amd64: ${{ steps.re-package.outputs.checksum-darwin_amd64 }}
65+
checksum-darwin_arm64: ${{ steps.re-package.outputs.checksum-darwin_arm64 }}
66+
67+
env:
68+
GON_CONFIG_PATH: gon.config.hcl
69+
70+
strategy:
71+
matrix:
72+
artifact:
73+
- name: darwin_amd64
74+
path: "macOS_64bit.tar.gz"
75+
- name: darwin_arm64
76+
path: "macOS_ARM64.tar.gz"
6277

6378
steps:
6479
- name: Checkout repository
@@ -98,38 +113,59 @@ jobs:
98113
wget -q https://github.com/mitchellh/gon/releases/download/v0.2.3/gon_macos.zip
99114
unzip gon_macos.zip -d /usr/local/bin
100115
116+
- name: Write gon config to file
117+
# gon does not allow env variables in config file (https://github.com/mitchellh/gon/issues/20)
118+
run: |
119+
cat > "${{ env.GON_CONFIG_PATH }}" <<EOF
120+
# See: https://github.com/mitchellh/gon#configuration-file
121+
source = ["${{ env.DIST_DIR }}/${{ env.PROJECT_NAME }}_osx_${{ matrix.artifact.name }}/${{ env.PROJECT_NAME }}"]
122+
bundle_id = "cc.arduino.${{ env.PROJECT_NAME }}"
123+
124+
sign {
125+
application_identity = "Developer ID Application: ARDUINO SA (7KT7ZWMCJT)"
126+
}
127+
128+
# Ask Gon for zip output to force notarization process to take place.
129+
# The CI will ignore the zip output, using the signed binary only.
130+
zip {
131+
output_path = "unused.zip"
132+
}
133+
EOF
134+
101135
- name: Sign and notarize binary
102136
env:
103137
AC_USERNAME: ${{ secrets.AC_USERNAME }}
104138
AC_PASSWORD: ${{ secrets.AC_PASSWORD }}
105139
run: |
106-
gon gon.config.hcl
140+
gon "${{ env.GON_CONFIG_PATH }}"
107141
108-
- name: Re-package binary and update checksum
142+
- name: Re-package binary and output checksum
143+
id: re-package
144+
working-directory: ${{ env.DIST_DIR }}
109145
# This step performs the following:
110146
# 1. Repackage the signed binary replaced in place by Gon (ignoring the output zip file)
111-
# 2. Recalculate package checksum and replace it in the nnnnnn-checksums.txt file
147+
# 2. Recalculate package checksum
148+
# 3. Output the new checksum to include in the nnnnnn-checksums.txt file
149+
# (it cannot be done there because of workflow job parallelization)
112150
run: |
113151
# GitHub's upload/download-artifact actions don't preserve file permissions,
114152
# so we need to add execution permission back until the action is made to do this.
115-
chmod +x ${{ env.DIST_DIR }}/${{ env.PROJECT_NAME }}_osx_darwin_amd64/${{ env.PROJECT_NAME }}
153+
chmod +x "${{ env.PROJECT_NAME }}_osx_${{ matrix.artifact.name }}/${{ env.PROJECT_NAME }}"
116154
TAG="${GITHUB_REF/refs\/tags\//}"
117-
tar -czvf "${{ env.DIST_DIR }}/${{ env.PROJECT_NAME }}_${TAG}_macOS_64bit.tar.gz" \
118-
-C ${{ env.DIST_DIR }}/${{ env.PROJECT_NAME }}_osx_darwin_amd64/ ${{ env.PROJECT_NAME }} \
119-
-C ../../ LICENSE.txt
120-
CHECKSUM="$(shasum -a 256 ${{ env.DIST_DIR }}/${{ env.PROJECT_NAME }}_${TAG}_macOS_64bit.tar.gz | cut -d " " -f 1)"
121-
perl \
122-
-pi \
123-
-w \
124-
-e "s/.*${{ env.PROJECT_NAME }}_${TAG}_macOS_64bit.tar.gz/${CHECKSUM} ${{ env.PROJECT_NAME }}_${TAG}_macOS_64bit.tar.gz/g;" \
125-
${{ env.DIST_DIR }}/*-checksums.txt
155+
PACKAGE_FILENAME="${{ env.PROJECT_NAME }}_${TAG}_${{ matrix.artifact.path }}"
156+
tar -czvf "$PACKAGE_FILENAME" \
157+
-C "${{ env.PROJECT_NAME }}_osx_${{ matrix.artifact.name }}/" "${{ env.PROJECT_NAME }}" \
158+
-C ../../ LICENSE.txt
159+
CHECKSUM_LINE="$(shasum -a 256 $PACKAGE_FILENAME)"
160+
echo "PACKAGE_FILENAME=$PACKAGE_FILENAME" >> $GITHUB_ENV
161+
echo "::set-output name=checksum-${{ matrix.artifact.name }}::$CHECKSUM_LINE"
126162
127163
- name: Upload artifacts
128164
uses: actions/upload-artifact@v3
129165
with:
130166
if-no-files-found: error
131167
name: ${{ env.ARTIFACT_NAME }}
132-
path: ${{ env.DIST_DIR }}
168+
path: ${{ env.DIST_DIR }}/${{ env.PACKAGE_FILENAME }}
133169

134170
create-release:
135171
runs-on: ubuntu-latest
@@ -142,6 +178,16 @@ jobs:
142178
name: ${{ env.ARTIFACT_NAME }}
143179
path: ${{ env.DIST_DIR }}
144180

181+
- name: Update checksum
182+
run: |
183+
declare -a checksum_lines=("${{ needs.notarize-macos.outputs.checksum-darwin_amd64 }}" "${{ needs.notarize-macos.outputs.checksum-darwin_arm64 }}")
184+
for checksum_line in "${checksum_lines[@]}"
185+
do
186+
CHECKSUM=$(echo ${checksum_line} | cut -d " " -f 1)
187+
PACKAGE_FILENAME=$(echo ${checksum_line} | cut -d " " -f 2)
188+
perl -pi -w -e "s/.*${PACKAGE_FILENAME}/${CHECKSUM} ${PACKAGE_FILENAME}/g;" ${{ env.DIST_DIR }}/*-checksums.txt
189+
done
190+
145191
- name: Identify Prerelease
146192
# This is a workaround while waiting for create-release action
147193
# to implement auto pre-release based on tag

workflow-templates/release-go-crosscompile-task.md

+3-12
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ Install the [`release-go-crosscompile-task.yml`](release-go-crosscompile-task.ym
1616
- Install to: repository root (or merge into the existing `Taskfile.yml`).
1717
- [`DistTasks.yml`](assets/release-go-crosscompile-task/DistTasks.yml) - general purpose tasks for making production builds of Go projects using golang cross-compile.
1818
- Install to: repository root
19-
- [`gon.config.hcl`](assets/general/gon.config.hcl) - [gon](https://github.com/mitchellh/gon) configuration file for macOS signing and notarization.
20-
- Install to: repository root
2119
- [Installation script and documentation](../other/installation-script/README.md)
2220

2321
### Configuration
@@ -37,14 +35,7 @@ The following project-specific variables must be set/configured in `release-go-c
3735

3836
- `PROJECT_NAME`
3937
- `AWS_PLUGIN_TARGET`
40-
- `GO_VERSION`: version of Go used for development of the project
41-
42-
#### gon
43-
44-
The following project-specific variables must be set in `gon.config.hcl`:
45-
46-
- `source`
47-
- `bundle_id`
38+
- `GO_VERSION`: version of Go used for development of the project, use at least [GO 1.16 to be able to use 64-bit ARM architecture on macOS](https://tip.golang.org/doc/go1.16#ports)
4839

4940
#### Repository secrets
5041

@@ -87,7 +78,7 @@ Add CI workflow to publish releases
8778
On every push of a tag named with a version format:
8879

8980
- Build the project for all supported platforms.
90-
- Sign and notarize the macOS build.
81+
- Sign and notarize the macOS builds.
9182
- Create a GitHub release.
9283
- Builds and checksums are attached as release assets
9384
- A changelog generated from the commit history is added to the release description
@@ -101,7 +92,7 @@ On every push of a tag named with a version format:
10192
On every push of a tag named with a version format:
10293
10394
- Build the project for all supported platforms.
104-
- Use [gon](https://github.com/mitchellh/gon) to sign and notarize the macOS build.
95+
- Use [gon](https://github.com/mitchellh/gon) to sign and notarize the macOS builds.
10596
- Create a [GitHub release](https://docs.github.com/repositories/releasing-projects-on-github/about-releases).
10697
- Builds and checksums are attached as release assets
10798
- A changelog generated by [`arduino/create-changelog`](https://github.com/arduino/create-changelog) from the commit history is added to the release description

workflow-templates/release-go-crosscompile-task.yml

+60-14
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,23 @@ jobs:
5757
path: ${{ env.DIST_DIR }}
5858

5959
notarize-macos:
60+
name: Notarize ${{ matrix.artifact.name }}
6061
runs-on: macos-latest
6162
needs: create-release-artifacts
63+
outputs:
64+
checksum-darwin_amd64: ${{ steps.re-package.outputs.checksum-darwin_amd64 }}
65+
checksum-darwin_arm64: ${{ steps.re-package.outputs.checksum-darwin_arm64 }}
66+
67+
env:
68+
GON_CONFIG_PATH: gon.config.hcl
69+
70+
strategy:
71+
matrix:
72+
artifact:
73+
- name: darwin_amd64
74+
path: "macOS_64bit.tar.gz"
75+
- name: darwin_arm64
76+
path: "macOS_ARM64.tar.gz"
6277

6378
steps:
6479
- name: Checkout repository
@@ -98,38 +113,59 @@ jobs:
98113
wget -q https://github.com/mitchellh/gon/releases/download/v0.2.3/gon_macos.zip
99114
unzip gon_macos.zip -d /usr/local/bin
100115
116+
- name: Write gon config to file
117+
# gon does not allow env variables in config file (https://github.com/mitchellh/gon/issues/20)
118+
run: |
119+
cat > "${{ env.GON_CONFIG_PATH }}" <<EOF
120+
# See: https://github.com/mitchellh/gon#configuration-file
121+
source = ["${{ env.DIST_DIR }}/${{ env.PROJECT_NAME }}_osx_${{ matrix.artifact.name }}/${{ env.PROJECT_NAME }}"]
122+
bundle_id = "cc.arduino.${{ env.PROJECT_NAME }}"
123+
124+
sign {
125+
application_identity = "Developer ID Application: ARDUINO SA (7KT7ZWMCJT)"
126+
}
127+
128+
# Ask Gon for zip output to force notarization process to take place.
129+
# The CI will ignore the zip output, using the signed binary only.
130+
zip {
131+
output_path = "unused.zip"
132+
}
133+
EOF
134+
101135
- name: Sign and notarize binary
102136
env:
103137
AC_USERNAME: ${{ secrets.AC_USERNAME }}
104138
AC_PASSWORD: ${{ secrets.AC_PASSWORD }}
105139
run: |
106-
gon gon.config.hcl
140+
gon "${{ env.GON_CONFIG_PATH }}"
107141
108-
- name: Re-package binary and update checksum
142+
- name: Re-package binary and output checksum
143+
id: re-package
144+
working-directory: ${{ env.DIST_DIR }}
109145
# This step performs the following:
110146
# 1. Repackage the signed binary replaced in place by Gon (ignoring the output zip file)
111-
# 2. Recalculate package checksum and replace it in the nnnnnn-checksums.txt file
147+
# 2. Recalculate package checksum
148+
# 3. Output the new checksum to include in the nnnnnn-checksums.txt file
149+
# (it cannot be done there because of workflow job parallelization)
112150
run: |
113151
# GitHub's upload/download-artifact actions don't preserve file permissions,
114152
# so we need to add execution permission back until the action is made to do this.
115-
chmod +x ${{ env.DIST_DIR }}/${{ env.PROJECT_NAME }}_osx_darwin_amd64/${{ env.PROJECT_NAME }}
153+
chmod +x "${{ env.PROJECT_NAME }}_osx_${{ matrix.artifact.name }}/${{ env.PROJECT_NAME }}"
116154
TAG="${GITHUB_REF/refs\/tags\//}"
117-
tar -czvf "${{ env.DIST_DIR }}/${{ env.PROJECT_NAME }}_${TAG}_macOS_64bit.tar.gz" \
118-
-C ${{ env.DIST_DIR }}/${{ env.PROJECT_NAME }}_osx_darwin_amd64/ ${{ env.PROJECT_NAME }} \
119-
-C ../../ LICENSE.txt
120-
CHECKSUM="$(shasum -a 256 ${{ env.DIST_DIR }}/${{ env.PROJECT_NAME }}_${TAG}_macOS_64bit.tar.gz | cut -d " " -f 1)"
121-
perl \
122-
-pi \
123-
-w \
124-
-e "s/.*${{ env.PROJECT_NAME }}_${TAG}_macOS_64bit.tar.gz/${CHECKSUM} ${{ env.PROJECT_NAME }}_${TAG}_macOS_64bit.tar.gz/g;" \
125-
${{ env.DIST_DIR }}/*-checksums.txt
155+
PACKAGE_FILENAME="${{ env.PROJECT_NAME }}_${TAG}_${{ matrix.artifact.path }}"
156+
tar -czvf "$PACKAGE_FILENAME" \
157+
-C "${{ env.PROJECT_NAME }}_osx_${{ matrix.artifact.name }}/" "${{ env.PROJECT_NAME }}" \
158+
-C ../../ LICENSE.txt
159+
CHECKSUM_LINE="$(shasum -a 256 $PACKAGE_FILENAME)"
160+
echo "PACKAGE_FILENAME=$PACKAGE_FILENAME" >> $GITHUB_ENV
161+
echo "::set-output name=checksum-${{ matrix.artifact.name }}::$CHECKSUM_LINE"
126162
127163
- name: Upload artifacts
128164
uses: actions/upload-artifact@v3
129165
with:
130166
if-no-files-found: error
131167
name: ${{ env.ARTIFACT_NAME }}
132-
path: ${{ env.DIST_DIR }}
168+
path: ${{ env.DIST_DIR }}/${{ env.PACKAGE_FILENAME }}
133169

134170
create-release:
135171
runs-on: ubuntu-latest
@@ -142,6 +178,16 @@ jobs:
142178
name: ${{ env.ARTIFACT_NAME }}
143179
path: ${{ env.DIST_DIR }}
144180

181+
- name: Update checksum
182+
run: |
183+
declare -a checksum_lines=("${{ needs.notarize-macos.outputs.checksum-darwin_amd64 }}" "${{ needs.notarize-macos.outputs.checksum-darwin_arm64 }}")
184+
for checksum_line in "${checksum_lines[@]}"
185+
do
186+
CHECKSUM=$(echo ${checksum_line} | cut -d " " -f 1)
187+
PACKAGE_FILENAME=$(echo ${checksum_line} | cut -d " " -f 2)
188+
perl -pi -w -e "s/.*${PACKAGE_FILENAME}/${CHECKSUM} ${PACKAGE_FILENAME}/g;" ${{ env.DIST_DIR }}/*-checksums.txt
189+
done
190+
145191
- name: Identify Prerelease
146192
# This is a workaround while waiting for create-release action
147193
# to implement auto pre-release based on tag

0 commit comments

Comments
 (0)