Skip to content

Commit 636d337

Browse files
committed
Build releases simultaneously
Introducing the use of a matrix greatly improves time performances during the build making process, since each build task is performed simultaneously. To support this, a check has been added to avoid creating the same changelog more than once. The calculation of the checksums has also been modified. Previously, it was done three (3) times at different stages of the workflow. This is pointless, since the only checksums that matter are the ones calculated when the files are in their final form. For this reason, it is now only done once during the release creation.
1 parent e309eee commit 636d337

File tree

3 files changed

+104
-103
lines changed

3 files changed

+104
-103
lines changed

Diff for: .github/workflows/publish-go-tester-task.yml

+81-57
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ on:
2626
env:
2727
# See: https://github.com/actions/setup-go/tree/main#supported-version-syntax
2828
GO_VERSION: "1.18"
29+
# As defined by the Taskfile's PROJECT_NAME variable
30+
PROJECT_NAME: arduino-fwuploader
2931
# As defined by the Taskfile's DIST_DIR variable
3032
DIST_DIR: dist
31-
BUILDS_ARTIFACT: build-artifacts
3233

3334
jobs:
3435
run-determination:
@@ -40,10 +41,12 @@ jobs:
4041
id: determination
4142
run: |
4243
RELEASE_BRANCH_REGEX="refs/heads/[0-9]+.[0-9]+.x"
44+
TAG_REGEX="refs/tags/.*"
4345
# The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead.
4446
if [[
45-
"${{ github.event_name }}" != "create" ||
46-
"${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX
47+
("${{ github.event_name }}" != "create" ||
48+
"${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX) &&
49+
! "${{ github.ref }}" =~ $TAG_REGEX
4750
]]; then
4851
# Run the other jobs.
4952
RESULT="true"
@@ -54,10 +57,59 @@ jobs:
5457
5558
echo "result=$RESULT" >> $GITHUB_OUTPUT
5659
57-
build:
60+
package-name-prefix:
5861
needs: run-determination
5962
if: needs.run-determination.outputs.result == 'true'
6063
runs-on: ubuntu-latest
64+
outputs:
65+
prefix: ${{ steps.calculation.outputs.prefix }}
66+
steps:
67+
- name: package name prefix calculation
68+
id: calculation
69+
run: |
70+
PACKAGE_NAME_PREFIX="test"
71+
if [ "${{ github.event_name }}" = "pull_request" ]; then
72+
PACKAGE_NAME_PREFIX="$PACKAGE_NAME_PREFIX-${{ github.event.number }}"
73+
fi
74+
PACKAGE_NAME_PREFIX="$PACKAGE_NAME_PREFIX-${{ github.sha }}-"
75+
76+
echo "prefix=$PACKAGE_NAME_PREFIX" >> $GITHUB_OUTPUT
77+
78+
build:
79+
needs: package-name-prefix
80+
name: Build ${{ matrix.os.name }}
81+
runs-on: ubuntu-latest
82+
83+
strategy:
84+
matrix:
85+
os:
86+
- task: Windows_32bit
87+
path: "*Windows_32bit.zip"
88+
name: Windows_X86-32
89+
- task: Windows_64bit
90+
path: "*Windows_64bit.zip"
91+
name: Windows_X86-64
92+
- task: Linux_32bit
93+
path: "*Linux_32bit.tar.gz"
94+
name: Linux_X86-32
95+
- task: Linux_64bit
96+
path: "*Linux_64bit.tar.gz"
97+
name: Linux_X86-64
98+
- task: Linux_ARMv6
99+
path: "*Linux_ARMv6.tar.gz"
100+
name: Linux_ARMv6
101+
- task: Linux_ARMv7
102+
path: "*Linux_ARMv7.tar.gz"
103+
name: Linux_ARMv7
104+
- task: Linux_ARM64
105+
path: "*Linux_ARM64.tar.gz"
106+
name: Linux_ARM64
107+
- task: macOS_64bit
108+
path: "*macOS_64bit.tar.gz"
109+
name: macOS_64
110+
- task: macOS_ARM64
111+
path: "*macOS_ARM64.tar.gz"
112+
name: macOS_ARM64
61113

62114
steps:
63115
- name: Checkout repository
@@ -76,69 +128,41 @@ jobs:
76128

77129
- name: Build
78130
run: |
79-
PACKAGE_NAME_PREFIX="test"
80-
if [ "${{ github.event_name }}" = "pull_request" ]; then
81-
PACKAGE_NAME_PREFIX="$PACKAGE_NAME_PREFIX-${{ github.event.number }}"
82-
fi
83-
PACKAGE_NAME_PREFIX="$PACKAGE_NAME_PREFIX-${{ github.sha }}-"
131+
PACKAGE_NAME_PREFIX=${{ needs.package-name-prefix.outputs.prefix }}
84132
export PACKAGE_NAME_PREFIX
85-
task dist:all
133+
task dist:${{ matrix.os.task }}
86134
87135
# Transfer builds to artifacts job
88-
- name: Upload combined builds artifact
136+
- name: Upload build artifact
89137
uses: actions/upload-artifact@v3
90138
with:
91-
path: ${{ env.DIST_DIR }}
92-
name: ${{ env.BUILDS_ARTIFACT }}
139+
path: ${{ env.DIST_DIR }}/${{ matrix.os.path }}
140+
name: ${{ matrix.os.name }}
93141

94-
artifacts:
95-
name: ${{ matrix.artifact.name }} artifact
96-
needs: build
142+
checksums:
143+
needs:
144+
- build
145+
- package-name-prefix
97146
runs-on: ubuntu-latest
98147

99-
strategy:
100-
matrix:
101-
artifact:
102-
- path: "*checksums.txt"
103-
name: checksums
104-
- path: "*Linux_32bit.tar.gz"
105-
name: Linux_X86-32
106-
- path: "*Linux_64bit.tar.gz"
107-
name: Linux_X86-64
108-
- path: "*Linux_ARM64.tar.gz"
109-
name: Linux_ARM64
110-
- path: "*Linux_ARMv6.tar.gz"
111-
name: Linux_ARMv6
112-
- path: "*Linux_ARMv7.tar.gz"
113-
name: Linux_ARMv7
114-
- path: "*macOS_64bit.tar.gz"
115-
name: macOS_64
116-
- path: "*macOS_ARM64.tar.gz"
117-
name: macOS_ARM64
118-
- path: "*Windows_32bit.zip"
119-
name: Windows_X86-32
120-
- path: "*Windows_64bit.zip"
121-
name: Windows_X86-64
122-
123148
steps:
124-
- name: Download combined builds artifact
149+
- name: Download build artifacts
125150
uses: actions/download-artifact@v3
126-
with:
127-
name: ${{ env.BUILDS_ARTIFACT }}
128-
path: ${{ env.BUILDS_ARTIFACT }}
129151

130-
- name: Upload individual build artifact
152+
- name: Create checksum file
153+
run: |
154+
TAG="${{ needs.package-name-prefix.outputs.prefix }}git-snapshot"
155+
declare -a artifacts=($(ls -d */))
156+
for artifact in ${artifacts[@]}
157+
do
158+
cd $artifact
159+
checksum=$(sha256sum ${{ env.PROJECT_NAME }}_${TAG}*)
160+
cd ..
161+
echo $checksum >> ${TAG}-checksums.txt
162+
done
163+
164+
- name: Upload checksum artifact
131165
uses: actions/upload-artifact@v3
132166
with:
133-
path: ${{ env.BUILDS_ARTIFACT }}/${{ matrix.artifact.path }}
134-
name: ${{ matrix.artifact.name }}
135-
136-
clean:
137-
needs: artifacts
138-
runs-on: ubuntu-latest
139-
140-
steps:
141-
- name: Remove unneeded combined builds artifact
142-
uses: geekyeggo/delete-artifact@v2
143-
with:
144-
name: ${{ env.BUILDS_ARTIFACT }}
167+
path: ./*checksums.txt
168+
name: checksums

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

+23-21
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,28 @@ jobs:
2121
create-release-artifacts:
2222
runs-on: ubuntu-latest
2323

24+
strategy:
25+
matrix:
26+
os:
27+
- Windows_32bit
28+
- Windows_64bit
29+
- Linux_32bit
30+
- Linux_64bit
31+
- Linux_ARMv6
32+
- Linux_ARMv7
33+
- Linux_ARM64
34+
- macOS_64bit
35+
- macOS_ARM64
36+
2437
steps:
2538
- name: Checkout repository
2639
uses: actions/checkout@v3
2740
with:
2841
fetch-depth: 0
2942

3043
- name: Create changelog
44+
# Avoid creating the same changelog for each os
45+
if: matrix.os == 'Windows_32bit'
3146
uses: arduino/create-changelog@v1
3247
with:
3348
tag-regex: '^[0-9]+\.[0-9]+\.[0-9]+.*$'
@@ -47,7 +62,7 @@ jobs:
4762
version: 3.x
4863

4964
- name: Build
50-
run: task dist:all
65+
run: task dist:${{ matrix.os }}
5166

5267
- name: Upload artifacts
5368
uses: actions/upload-artifact@v3
@@ -60,9 +75,6 @@ jobs:
6075
name: Notarize ${{ matrix.artifact.name }}
6176
runs-on: macos-latest
6277
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 }}
6678

6779
env:
6880
GON_CONFIG_PATH: gon.config.hcl
@@ -140,14 +152,10 @@ jobs:
140152
run: |
141153
gon "${{ env.GON_CONFIG_PATH }}"
142154
143-
- name: Re-package binary and output checksum
155+
- name: Re-package binary
144156
id: re-package
145157
working-directory: ${{ env.DIST_DIR }}
146-
# This step performs the following:
147-
# 1. Repackage the signed binary replaced in place by Gon (ignoring the output zip file)
148-
# 2. Recalculate package checksum
149-
# 3. Output the new checksum to include in the nnnnnn-checksums.txt file
150-
# (it cannot be done there because of workflow job parallelization)
158+
# Repackage the signed binary replaced in place by Gon (ignoring the output zip file)
151159
run: |
152160
# GitHub's upload/download-artifact actions don't preserve file permissions,
153161
# so we need to add execution permission back until the action is made to do this.
@@ -157,11 +165,9 @@ jobs:
157165
tar -czvf "$PACKAGE_FILENAME" \
158166
-C "${{ env.PROJECT_NAME }}_osx_${{ matrix.artifact.name }}/" "${{ env.PROJECT_NAME }}" \
159167
-C ../../ LICENSE.txt
160-
CHECKSUM_LINE="$(shasum -a 256 $PACKAGE_FILENAME)"
161168
echo "PACKAGE_FILENAME=$PACKAGE_FILENAME" >> $GITHUB_ENV
162-
echo "::set-output name=checksum-${{ matrix.artifact.name }}::$CHECKSUM_LINE"
163169
164-
- name: Upload artifacts
170+
- name: Upload artifact
165171
uses: actions/upload-artifact@v3
166172
with:
167173
if-no-files-found: error
@@ -193,15 +199,11 @@ jobs:
193199
# would be calculated since the binary is modified during notarization
194200
run: task dist:generate-index-data
195201

196-
- name: Update checksum
202+
- name: Create checksum file
203+
working-directory: ${{ env.DIST_DIR}}
197204
run: |
198-
declare -a checksum_lines=("${{ needs.notarize-macos.outputs.checksum-darwin_amd64 }}" "${{ needs.notarize-macos.outputs.checksum-darwin_arm64 }}")
199-
for checksum_line in "${checksum_lines[@]}"
200-
do
201-
CHECKSUM=$(echo ${checksum_line} | cut -d " " -f 1)
202-
PACKAGE_FILENAME=$(echo ${checksum_line} | cut -d " " -f 2)
203-
perl -pi -w -e "s/.*${PACKAGE_FILENAME}/${CHECKSUM} ${PACKAGE_FILENAME}/g;" ${{ env.DIST_DIR }}/*-checksums.txt
204-
done
205+
TAG="${GITHUB_REF/refs\/tags\//}"
206+
sha256sum ${{ env.PROJECT_NAME }}_${TAG}* > ${TAG}-checksums.txt
205207
206208
- name: Identify Prerelease
207209
# This is a workaround while waiting for create-release action

Diff for: DistTasks.yml

-25
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,7 @@ version: "3"
1717
#
1818
# The project MUST contain a LICENSE.txt file in the root folder or packaging will fail.
1919

20-
vars:
21-
CHECKSUM_FILE: "{{.VERSION}}-checksums.txt"
22-
2320
tasks:
24-
all:
25-
desc: Build for distribution for all platforms
26-
cmds:
27-
- task: Windows_32bit
28-
- task: Windows_64bit
29-
- task: Linux_32bit
30-
- task: Linux_64bit
31-
- task: Linux_ARMv6
32-
- task: Linux_ARMv7
33-
- task: Linux_ARM64
34-
- task: macOS_64bit
35-
- task: macOS_ARM64
36-
3721
Windows_32bit:
3822
desc: Builds Windows 32 bit binaries
3923
env:
@@ -45,7 +29,6 @@ tasks:
4529
go build -o {{.DIST_DIR}}/{{.PLATFORM_DIR}}/{{.PROJECT_NAME}}.exe {{.LDFLAGS}}
4630
cd {{.DIST_DIR}}
4731
zip {{.PACKAGE_NAME}} {{.PLATFORM_DIR}}/{{.PROJECT_NAME}}.exe ../LICENSE.txt -j
48-
sha256sum {{.PACKAGE_NAME}} >> {{.CHECKSUM_FILE}}
4932
vars:
5033
PLATFORM_DIR: "{{.PROJECT_NAME}}_windows_386"
5134
PACKAGE_PLATFORM: "Windows_32bit"
@@ -61,7 +44,6 @@ tasks:
6144
go build -o {{.DIST_DIR}}/{{.PLATFORM_DIR}}/{{.PROJECT_NAME}}.exe {{.LDFLAGS}}
6245
cd {{.DIST_DIR}}
6346
zip {{.PACKAGE_NAME}} {{.PLATFORM_DIR}}/{{.PROJECT_NAME}}.exe ../LICENSE.txt -j
64-
sha256sum {{.PACKAGE_NAME}} >> {{.CHECKSUM_FILE}}
6547
vars:
6648
PLATFORM_DIR: "{{.PROJECT_NAME}}_windows_amd64"
6749
PACKAGE_PLATFORM: "Windows_64bit"
@@ -78,7 +60,6 @@ tasks:
7860
go build -o {{.DIST_DIR}}/{{.PLATFORM_DIR}}/{{.PROJECT_NAME}} {{.LDFLAGS}}
7961
cd {{.DIST_DIR}}
8062
tar cz -C {{.PLATFORM_DIR}} {{.PROJECT_NAME}} -C ../.. LICENSE.txt -f {{.PACKAGE_NAME}}
81-
sha256sum {{.PACKAGE_NAME}} >> {{.CHECKSUM_FILE}}
8263
vars:
8364
PLATFORM_DIR: "{{.PROJECT_NAME}}_linux_amd32"
8465
PACKAGE_PLATFORM: "Linux_32bit"
@@ -94,7 +75,6 @@ tasks:
9475
go build -o {{.DIST_DIR}}/{{.PLATFORM_DIR}}/{{.PROJECT_NAME}} {{.LDFLAGS}}
9576
cd {{.DIST_DIR}}
9677
tar cz -C {{.PLATFORM_DIR}} {{.PROJECT_NAME}} -C ../.. LICENSE.txt -f {{.PACKAGE_NAME}}
97-
sha256sum {{.PACKAGE_NAME}} >> {{.CHECKSUM_FILE}}
9878
vars:
9979
PLATFORM_DIR: "{{.PROJECT_NAME}}_linux_amd64"
10080
PACKAGE_PLATFORM: "Linux_64bit"
@@ -111,7 +91,6 @@ tasks:
11191
go build -o {{.DIST_DIR}}/{{.PLATFORM_DIR}}/{{.PROJECT_NAME}} {{.LDFLAGS}}
11292
cd {{.DIST_DIR}}
11393
tar cz -C {{.PLATFORM_DIR}} {{.PROJECT_NAME}} -C ../.. LICENSE.txt -f {{.PACKAGE_NAME}}
114-
sha256sum {{.PACKAGE_NAME}} >> {{.CHECKSUM_FILE}}
11594
vars:
11695
PLATFORM_DIR: "{{.PROJECT_NAME}}_linux_arm_7"
11796
PACKAGE_PLATFORM: "Linux_ARMv7"
@@ -128,7 +107,6 @@ tasks:
128107
go build -o {{.DIST_DIR}}/{{.PLATFORM_DIR}}/{{.PROJECT_NAME}} {{.LDFLAGS}}
129108
cd {{.DIST_DIR}}
130109
tar cz -C {{.PLATFORM_DIR}} {{.PROJECT_NAME}} -C ../.. LICENSE.txt -f {{.PACKAGE_NAME}}
131-
sha256sum {{.PACKAGE_NAME}} >> {{.CHECKSUM_FILE}}
132110
vars:
133111
PLATFORM_DIR: "{{.PROJECT_NAME}}_linux_arm_6"
134112
PACKAGE_PLATFORM: "Linux_ARMv6"
@@ -144,7 +122,6 @@ tasks:
144122
go build -o {{.DIST_DIR}}/{{.PLATFORM_DIR}}/{{.PROJECT_NAME}} {{.LDFLAGS}}
145123
cd {{.DIST_DIR}}
146124
tar cz -C {{.PLATFORM_DIR}} {{.PROJECT_NAME}} -C ../.. LICENSE.txt -f {{.PACKAGE_NAME}}
147-
sha256sum {{.PACKAGE_NAME}} >> {{.CHECKSUM_FILE}}
148125
vars:
149126
PLATFORM_DIR: "{{.PROJECT_NAME}}_linux_arm_64"
150127
PACKAGE_PLATFORM: "Linux_ARM64"
@@ -160,7 +137,6 @@ tasks:
160137
go build -o {{.DIST_DIR}}/{{.PLATFORM_DIR}}/{{.PROJECT_NAME}} {{.LDFLAGS}}
161138
cd {{.DIST_DIR}}
162139
tar cz -C {{.PLATFORM_DIR}} {{.PROJECT_NAME}} -C ../.. LICENSE.txt -f {{.PACKAGE_NAME}}
163-
sha256sum {{.PACKAGE_NAME}} >> {{.CHECKSUM_FILE}}
164140
vars:
165141
PLATFORM_DIR: "{{.PROJECT_NAME}}_osx_darwin_amd64"
166142
PACKAGE_PLATFORM: "macOS_64bit"
@@ -176,7 +152,6 @@ tasks:
176152
go build -o {{.DIST_DIR}}/{{.PLATFORM_DIR}}/{{.PROJECT_NAME}} {{.LDFLAGS}}
177153
cd {{.DIST_DIR}}
178154
tar cz -C {{.PLATFORM_DIR}} {{.PROJECT_NAME}} -C ../.. LICENSE.txt -f {{.PACKAGE_NAME}}
179-
sha256sum {{.PACKAGE_NAME}} >> {{.CHECKSUM_FILE}}
180155
vars:
181156
PLATFORM_DIR: "{{.PROJECT_NAME}}_osx_darwin_arm64"
182157
PACKAGE_PLATFORM: "macOS_ARM64"

0 commit comments

Comments
 (0)