Skip to content

Commit 9d8f4ce

Browse files
committed
Deduplicate type determination code in build workflow
The "Arduino IDE" GitHub Actions workflow is used to generate several distinct types of builds: - Tester builds of commits - Nightly builds - Release builds Different actions must be performed depending on which type of build is being produced. The workflow contains code that uses various criteria to determine the build type. Previously that code was duplicated in multiple places: - The packaging job - The changelog generation job - The nightly build publishing job - The release publishing job This duplication is avoided by moving the code to a dedicated job that makes the build type information available to all subsequent jobs via outputs.
1 parent a47a581 commit 9d8f4ce

File tree

1 file changed

+52
-11
lines changed

1 file changed

+52
-11
lines changed

Diff for: .github/workflows/build.yml

+52-11
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,43 @@ jobs:
6060
6161
echo "result=$RESULT" >> $GITHUB_OUTPUT
6262
63-
build:
64-
name: build (${{ matrix.config.name }})
63+
build-type-determination:
6564
needs: run-determination
6665
if: needs.run-determination.outputs.result == 'true'
66+
runs-on: ubuntu-latest
67+
outputs:
68+
is-release: ${{ steps.determination.outputs.is-release }}
69+
is-nightly: ${{ steps.determination.outputs.is-nightly }}
70+
permissions: {}
71+
steps:
72+
- name: Determine the type of build
73+
id: determination
74+
run: |
75+
if [[
76+
"${{ startsWith(github.ref, 'refs/tags/') }}" == "true"
77+
]]; then
78+
is_release="true"
79+
is_nightly="false"
80+
elif [[
81+
"${{ github.event_name }}" == "schedule" ||
82+
(
83+
"${{ github.event_name }}" == "workflow_dispatch" &&
84+
"${{ github.ref }}" == "refs/heads/main"
85+
)
86+
]]; then
87+
is_release="false"
88+
is_nightly="true"
89+
else
90+
is_release="false"
91+
is_nightly="false"
92+
fi
93+
94+
echo "is-release=$is_release" >> $GITHUB_OUTPUT
95+
echo "is-nightly=$is_nightly" >> $GITHUB_OUTPUT
96+
97+
build:
98+
name: build (${{ matrix.config.name }})
99+
needs: build-type-determination
67100
strategy:
68101
matrix:
69102
config:
@@ -120,8 +153,8 @@ jobs:
120153
AC_TEAM_ID: ${{ secrets.AC_TEAM_ID }}
121154
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
122155
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
123-
IS_NIGHTLY: ${{ github.event_name == 'schedule' || (github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/main') }}
124-
IS_RELEASE: ${{ startsWith(github.ref, 'refs/tags/') }}
156+
IS_NIGHTLY: ${{ needs.build-type-determination.outputs.is-nightly }}
157+
IS_RELEASE: ${{ needs.build-type-determination.outputs.is-release }}
125158
CAN_SIGN: ${{ secrets[matrix.config.certificate-secret] != '' }}
126159
run: |
127160
# See: https://www.electron.build/code-signing
@@ -190,7 +223,9 @@ jobs:
190223
path: ${{ env.JOB_TRANSFER_ARTIFACT }}/${{ matrix.artifact.path }}
191224

192225
changelog:
193-
needs: build
226+
needs:
227+
- build-type-determination
228+
- build
194229
runs-on: ubuntu-latest
195230
outputs:
196231
BODY: ${{ steps.changelog.outputs.BODY }}
@@ -203,7 +238,7 @@ jobs:
203238
- name: Generate Changelog
204239
id: changelog
205240
env:
206-
IS_RELEASE: ${{ startsWith(github.ref, 'refs/tags/') }}
241+
IS_RELEASE: ${{ needs.build-type-determination.outputs.is-release }}
207242
run: |
208243
export LATEST_TAG=$(git describe --abbrev=0)
209244
export GIT_LOG=$(git log --pretty=" - %s [%h]" $LATEST_TAG..HEAD | sed 's/ *$//g')
@@ -229,15 +264,19 @@ jobs:
229264
echo "$BODY" > CHANGELOG.txt
230265
231266
- name: Upload Changelog [GitHub Actions]
232-
if: github.event_name == 'schedule' || (github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/main')
267+
if: needs.build-type-determination.outputs.is-nightly == 'true'
233268
uses: actions/upload-artifact@v3
234269
with:
235270
name: ${{ env.JOB_TRANSFER_ARTIFACT }}
236271
path: CHANGELOG.txt
237272

238273
publish:
239-
needs: changelog
240-
if: github.repository == 'arduino/arduino-ide' && (github.event_name == 'schedule' || (github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/main'))
274+
needs:
275+
- build-type-determination
276+
- changelog
277+
if: >
278+
github.repository == 'arduino/arduino-ide' &&
279+
needs.build-type-determination.outputs.is-nightly == 'true'
241280
runs-on: ubuntu-latest
242281
steps:
243282
- name: Download [GitHub Actions]
@@ -257,8 +296,10 @@ jobs:
257296
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
258297

259298
release:
260-
needs: changelog
261-
if: startsWith(github.ref, 'refs/tags/')
299+
needs:
300+
- build-type-determination
301+
- changelog
302+
if: needs.build-type-determination.outputs.is-release == 'true'
262303
runs-on: ubuntu-latest
263304
steps:
264305
- name: Download [GitHub Actions]

0 commit comments

Comments
 (0)