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.
This commit is contained in:
per1234 2023-10-03 00:32:01 -07:00
parent 4708bae9ab
commit f0706e1849

View File

@ -60,10 +60,43 @@ jobs:
echo "result=$RESULT" >> $GITHUB_OUTPUT echo "result=$RESULT" >> $GITHUB_OUTPUT
build: build-type-determination:
name: build (${{ matrix.config.name }})
needs: run-determination needs: run-determination
if: needs.run-determination.outputs.result == 'true' if: needs.run-determination.outputs.result == 'true'
runs-on: ubuntu-latest
outputs:
is-release: ${{ steps.determination.outputs.is-release }}
is-nightly: ${{ steps.determination.outputs.is-nightly }}
permissions: {}
steps:
- name: Determine the type of build
id: determination
run: |
if [[
"${{ startsWith(github.ref, 'refs/tags/') }}" == "true"
]]; then
is_release="true"
is_nightly="false"
elif [[
"${{ github.event_name }}" == "schedule" ||
(
"${{ github.event_name }}" == "workflow_dispatch" &&
"${{ github.ref }}" == "refs/heads/main"
)
]]; then
is_release="false"
is_nightly="true"
else
is_release="false"
is_nightly="false"
fi
echo "is-release=$is_release" >> $GITHUB_OUTPUT
echo "is-nightly=$is_nightly" >> $GITHUB_OUTPUT
build:
name: build (${{ matrix.config.name }})
needs: build-type-determination
strategy: strategy:
matrix: matrix:
config: config:
@ -120,8 +153,8 @@ jobs:
AC_TEAM_ID: ${{ secrets.AC_TEAM_ID }} AC_TEAM_ID: ${{ secrets.AC_TEAM_ID }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
IS_NIGHTLY: ${{ github.event_name == 'schedule' || (github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/main') }} IS_NIGHTLY: ${{ needs.build-type-determination.outputs.is-nightly }}
IS_RELEASE: ${{ startsWith(github.ref, 'refs/tags/') }} IS_RELEASE: ${{ needs.build-type-determination.outputs.is-release }}
CAN_SIGN: ${{ secrets[matrix.config.certificate-secret] != '' }} CAN_SIGN: ${{ secrets[matrix.config.certificate-secret] != '' }}
run: | run: |
# See: https://www.electron.build/code-signing # See: https://www.electron.build/code-signing
@ -190,7 +223,9 @@ jobs:
path: ${{ env.JOB_TRANSFER_ARTIFACT }}/${{ matrix.artifact.path }} path: ${{ env.JOB_TRANSFER_ARTIFACT }}/${{ matrix.artifact.path }}
changelog: changelog:
needs: build needs:
- build-type-determination
- build
runs-on: ubuntu-latest runs-on: ubuntu-latest
outputs: outputs:
BODY: ${{ steps.changelog.outputs.BODY }} BODY: ${{ steps.changelog.outputs.BODY }}
@ -203,7 +238,7 @@ jobs:
- name: Generate Changelog - name: Generate Changelog
id: changelog id: changelog
env: env:
IS_RELEASE: ${{ startsWith(github.ref, 'refs/tags/') }} IS_RELEASE: ${{ needs.build-type-determination.outputs.is-release }}
run: | run: |
export LATEST_TAG=$(git describe --abbrev=0) export LATEST_TAG=$(git describe --abbrev=0)
export GIT_LOG=$(git log --pretty=" - %s [%h]" $LATEST_TAG..HEAD | sed 's/ *$//g') export GIT_LOG=$(git log --pretty=" - %s [%h]" $LATEST_TAG..HEAD | sed 's/ *$//g')
@ -229,15 +264,19 @@ jobs:
echo "$BODY" > CHANGELOG.txt echo "$BODY" > CHANGELOG.txt
- name: Upload Changelog [GitHub Actions] - name: Upload Changelog [GitHub Actions]
if: github.event_name == 'schedule' || (github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/main') if: needs.build-type-determination.outputs.is-nightly == 'true'
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v3
with: with:
name: ${{ env.JOB_TRANSFER_ARTIFACT }} name: ${{ env.JOB_TRANSFER_ARTIFACT }}
path: CHANGELOG.txt path: CHANGELOG.txt
publish: publish:
needs: changelog needs:
if: github.repository == 'arduino/arduino-ide' && (github.event_name == 'schedule' || (github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/main')) - build-type-determination
- changelog
if: >
github.repository == 'arduino/arduino-ide' &&
needs.build-type-determination.outputs.is-nightly == 'true'
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Download [GitHub Actions] - name: Download [GitHub Actions]
@ -257,8 +296,10 @@ jobs:
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
release: release:
needs: changelog needs:
if: startsWith(github.ref, 'refs/tags/') - build-type-determination
- changelog
if: needs.build-type-determination.outputs.is-release == 'true'
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Download [GitHub Actions] - name: Download [GitHub Actions]