Skip to content

Commit fb13f31

Browse files
umbynosper1234
andcommitted
update release-go-task to support darwin arm64
Co-authored-by: per1234 <[email protected]>
1 parent 25a3000 commit fb13f31

File tree

4 files changed

+145
-39
lines changed

4 files changed

+145
-39
lines changed

workflow-templates/assets/release-go-task/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"

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

+60-14
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,23 @@ jobs:
5050
path: ${{ env.DIST_DIR }}
5151

5252
notarize-macos:
53+
name: Notarize ${{ matrix.artifact.name }}
5354
runs-on: macos-latest
5455
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"
5570

5671
steps:
5772
- name: Checkout repository
@@ -91,38 +106,59 @@ jobs:
91106
wget -q https://github.com/mitchellh/gon/releases/download/v0.2.3/gon_macos.zip
92107
unzip gon_macos.zip -d /usr/local/bin
93108
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+
94128
- name: Sign and notarize binary
95129
env:
96130
AC_USERNAME: ${{ secrets.AC_USERNAME }}
97131
AC_PASSWORD: ${{ secrets.AC_PASSWORD }}
98132
run: |
99-
gon gon.config.hcl
133+
gon "${{ env.GON_CONFIG_PATH }}"
100134
101-
- name: Re-package binary and update checksum
135+
- name: Re-package binary and output checksum
136+
id: re-package
137+
working-directory: ${{ env.DIST_DIR }}
102138
# This step performs the following:
103139
# 1. Repackage the signed binary replaced in place by Gon (ignoring the output zip file)
104-
# 2. Recalculate package checksum and replace it in the nnnnnn-checksums.txt 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)
105143
run: |
106144
# GitHub's upload/download-artifact actions don't preserve file permissions,
107145
# so we need to add execution permission back until the action is made to do this.
108-
chmod +x ${{ env.DIST_DIR }}/${{ env.PROJECT_NAME }}_osx_darwin_amd64/${{ env.PROJECT_NAME }}
146+
chmod +x "${{ env.PROJECT_NAME }}_osx_${{ matrix.artifact.name }}/${{ env.PROJECT_NAME }}"
109147
TAG="${GITHUB_REF/refs\/tags\//}"
110-
tar -czvf "${{ env.DIST_DIR }}/${{ env.PROJECT_NAME }}_${TAG}_macOS_64bit.tar.gz" \
111-
-C ${{ env.DIST_DIR }}/${{ env.PROJECT_NAME }}_osx_darwin_amd64/ ${{ env.PROJECT_NAME }} \
112-
-C ../../ LICENSE.txt
113-
CHECKSUM="$(shasum -a 256 ${{ env.DIST_DIR }}/${{ env.PROJECT_NAME }}_${TAG}_macOS_64bit.tar.gz | cut -d " " -f 1)"
114-
perl \
115-
-pi \
116-
-w \
117-
-e "s/.*${{ env.PROJECT_NAME }}_${TAG}_macOS_64bit.tar.gz/${CHECKSUM} ${{ env.PROJECT_NAME }}_${TAG}_macOS_64bit.tar.gz/g;" \
118-
${{ env.DIST_DIR }}/*-checksums.txt
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"
119155
120156
- name: Upload artifacts
121157
uses: actions/upload-artifact@v3
122158
with:
123159
if-no-files-found: error
124160
name: ${{ env.ARTIFACT_NAME }}
125-
path: ${{ env.DIST_DIR }}
161+
path: ${{ env.DIST_DIR }}/${{ env.PACKAGE_FILENAME }}
126162

127163
create-release:
128164
runs-on: ubuntu-latest
@@ -135,6 +171,16 @@ jobs:
135171
name: ${{ env.ARTIFACT_NAME }}
136172
path: ${{ env.DIST_DIR }}
137173

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
183+
138184
- name: Identify Prerelease
139185
# This is a workaround while waiting for create-release action
140186
# to implement auto pre-release based on tag

workflow-templates/release-go-task.md

+2-11
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ Install the [`release-go-task.yml`](release-go-task.yml) GitHub Actions workflow
1616
- Install to: repository root (or merge into the existing `Taskfile.yml`).
1717
- [`DistTasks.yml`](assets/release-go-task/DistTasks.yml) - general purpose tasks for making production builds of Go projects using cgo and [elastic docker containers](https://github.com/elastic/golang-crossbuild).
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
@@ -38,13 +36,6 @@ The following project-specific variables must be set in `release-go-task.yml`:
3836
- `PROJECT_NAME`
3937
- `AWS_PLUGIN_TARGET`
4038

41-
#### gon
42-
43-
The following project-specific variables must be set in `gon.config.hcl`:
44-
45-
- `source`
46-
- `bundle_id`
47-
4839
#### Repository secrets
4940

5041
The following [repository secrets](https://docs.github.com/actions/security-guides/encrypted-secrets#creating-encrypted-secrets-for-a-repository) must be defined:
@@ -86,7 +77,7 @@ Add CI workflow to publish releases
8677
On every push of a tag named with a version format:
8778

8879
- Build the project for all supported platforms.
89-
- Sign and notarize the macOS build.
80+
- Sign and notarize the macOS builds.
9081
- Create a GitHub release.
9182
- Builds and checksums are attached as release assets
9283
- A changelog generated from the commit history is added to the release description
@@ -100,7 +91,7 @@ On every push of a tag named with a version format:
10091
On every push of a tag named with a version format:
10192
10293
- Build the project for all supported platforms.
103-
- Use [gon](https://github.com/mitchellh/gon) to sign and notarize the macOS build.
94+
- Use [gon](https://github.com/mitchellh/gon) to sign and notarize the macOS builds.
10495
- Create a [GitHub release](https://docs.github.com/repositories/releasing-projects-on-github/about-releases).
10596
- Builds and checksums are attached as release assets
10697
- 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-task.yml

+60-14
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,23 @@ jobs:
5050
path: ${{ env.DIST_DIR }}
5151

5252
notarize-macos:
53+
name: Notarize ${{ matrix.artifact.name }}
5354
runs-on: macos-latest
5455
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"
5570

5671
steps:
5772
- name: Checkout repository
@@ -91,38 +106,59 @@ jobs:
91106
wget -q https://github.com/mitchellh/gon/releases/download/v0.2.3/gon_macos.zip
92107
unzip gon_macos.zip -d /usr/local/bin
93108
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+
94128
- name: Sign and notarize binary
95129
env:
96130
AC_USERNAME: ${{ secrets.AC_USERNAME }}
97131
AC_PASSWORD: ${{ secrets.AC_PASSWORD }}
98132
run: |
99-
gon gon.config.hcl
133+
gon "${{ env.GON_CONFIG_PATH }}"
100134
101-
- name: Re-package binary and update checksum
135+
- name: Re-package binary and output checksum
136+
id: re-package
137+
working-directory: ${{ env.DIST_DIR }}
102138
# This step performs the following:
103139
# 1. Repackage the signed binary replaced in place by Gon (ignoring the output zip file)
104-
# 2. Recalculate package checksum and replace it in the nnnnnn-checksums.txt 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)
105143
run: |
106144
# GitHub's upload/download-artifact actions don't preserve file permissions,
107145
# so we need to add execution permission back until the action is made to do this.
108-
chmod +x ${{ env.DIST_DIR }}/${{ env.PROJECT_NAME }}_osx_darwin_amd64/${{ env.PROJECT_NAME }}
146+
chmod +x "${{ env.PROJECT_NAME }}_osx_${{ matrix.artifact.name }}/${{ env.PROJECT_NAME }}"
109147
TAG="${GITHUB_REF/refs\/tags\//}"
110-
tar -czvf "${{ env.DIST_DIR }}/${{ env.PROJECT_NAME }}_${TAG}_macOS_64bit.tar.gz" \
111-
-C ${{ env.DIST_DIR }}/${{ env.PROJECT_NAME }}_osx_darwin_amd64/ ${{ env.PROJECT_NAME }} \
112-
-C ../../ LICENSE.txt
113-
CHECKSUM="$(shasum -a 256 ${{ env.DIST_DIR }}/${{ env.PROJECT_NAME }}_${TAG}_macOS_64bit.tar.gz | cut -d " " -f 1)"
114-
perl \
115-
-pi \
116-
-w \
117-
-e "s/.*${{ env.PROJECT_NAME }}_${TAG}_macOS_64bit.tar.gz/${CHECKSUM} ${{ env.PROJECT_NAME }}_${TAG}_macOS_64bit.tar.gz/g;" \
118-
${{ env.DIST_DIR }}/*-checksums.txt
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"
119155
120156
- name: Upload artifacts
121157
uses: actions/upload-artifact@v3
122158
with:
123159
if-no-files-found: error
124160
name: ${{ env.ARTIFACT_NAME }}
125-
path: ${{ env.DIST_DIR }}
161+
path: ${{ env.DIST_DIR }}/${{ env.PACKAGE_FILENAME }}
126162

127163
create-release:
128164
runs-on: ubuntu-latest
@@ -135,6 +171,16 @@ jobs:
135171
name: ${{ env.ARTIFACT_NAME }}
136172
path: ${{ env.DIST_DIR }}
137173

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
183+
138184
- name: Identify Prerelease
139185
# This is a workaround while waiting for create-release action
140186
# to implement auto pre-release based on tag

0 commit comments

Comments
 (0)