From 553d0b5014d9592fb8380b893a767f5c86d9bab4 Mon Sep 17 00:00:00 2001 From: per1234 Date: Sun, 13 Oct 2024 15:44:59 -0700 Subject: [PATCH 1/3] Use more meaningful variable names in release workflows GitHub Actions workflows are used to automatically generate beta tester and production builds of the project. A separate build is generated for each of the target host types. This is done using a job matrix, which creates a parallel run of the workflow job for each target. The matrix defines variables that provide the data that is specific to each job. The variable names used previously did not clearly communicate their nature: - The variable for the task name was named "os" - The variables for the build filename components used the term "artifact", which is ambiguous in this context where the term is otherwise used to refer to the completely unrelated workflow artifacts These variable names made it very difficult for anyone not intimately familiar with the workings of the workflow to understand its code. --- .github/workflows/publish-go-nightly-task.yml | 59 ++++++++++-------- .github/workflows/publish-go-tester-task.yml | 22 +++---- .github/workflows/release-go-task.yml | 61 +++++++++++-------- 3 files changed, 80 insertions(+), 62 deletions(-) diff --git a/.github/workflows/publish-go-nightly-task.yml b/.github/workflows/publish-go-nightly-task.yml index e061698c..c68f02c7 100644 --- a/.github/workflows/publish-go-nightly-task.yml +++ b/.github/workflows/publish-go-nightly-task.yml @@ -8,7 +8,7 @@ env: DIST_DIR: dist # The project's folder on Arduino's download server for uploading builds AWS_PLUGIN_TARGET: /arduino-lint/ - ARTIFACT_NAME: dist + ARTIFACT_PREFIX: dist- # See: https://docs.github.com/actions/using-workflows/events-that-trigger-workflows on: @@ -27,15 +27,24 @@ jobs: strategy: matrix: os: - - Windows_32bit - - Windows_64bit - - Linux_32bit - - Linux_64bit - - Linux_ARMv6 - - Linux_ARMv7 - - Linux_ARM64 - - macOS_64bit - - macOS_ARM64 + - task: Windows_32bit + artifact-suffix: Windows_32bit + - task: Windows_64bit + artifact-suffix: Windows_64bit + - task: Linux_32bit + artifact-suffix: Linux_32bit + - task: Linux_64bit + artifact-suffix: Linux_64bit + - task: Linux_ARMv6 + artifact-suffix: Linux_ARMv6 + - task: Linux_ARMv7 + artifact-suffix: Linux_ARMv7 + - task: Linux_ARM64 + artifact-suffix: Linux_ARM64 + - task: macOS_64bit + artifact-suffix: macOS_64bit + - task: macOS_ARM64 + artifact-suffix: macOS_ARM64 steps: - name: Checkout repository @@ -50,17 +59,17 @@ jobs: - name: Build env: NIGHTLY: true - run: task dist:${{ matrix.os }} + run: task dist:${{ matrix.os.task }} - name: Upload artifacts uses: actions/upload-artifact@v4 with: if-no-files-found: error - name: ${{ env.ARTIFACT_NAME }}-${{ matrix.os }} + name: ${{ env.ARTIFACT_PREFIX }}${{ matrix.os.artifact-suffix }} path: ${{ env.DIST_DIR }} notarize-macos: - name: Notarize ${{ matrix.artifact.name }} + name: Notarize ${{ matrix.build.folder-suffix }} runs-on: macos-latest needs: create-nightly-artifacts @@ -76,11 +85,11 @@ jobs: strategy: matrix: - artifact: - - name: darwin_amd64 - path: "macOS_64bit.tar.gz" - - name: darwin_arm64 - path: "macOS_ARM64.tar.gz" + build: + - folder-suffix: darwin_amd64 + package-suffix: "macOS_64bit.tar.gz" + - folder-suffix: darwin_arm64 + package-suffix: "macOS_ARM64.tar.gz" steps: - name: Checkout repository @@ -89,7 +98,7 @@ jobs: - name: Download artifacts uses: actions/download-artifact@v4 with: - pattern: ${{ env.ARTIFACT_NAME }}-* + pattern: ${{ env.ARTIFACT_PREFIX }}* merge-multiple: true path: ${{ env.DIST_DIR }} @@ -126,7 +135,7 @@ jobs: run: | cat > "${{ env.GON_CONFIG_PATH }}" <> $GITHUB_ENV @@ -167,7 +176,7 @@ jobs: uses: actions/upload-artifact@v4 with: if-no-files-found: error - name: ${{ env.ARTIFACT_NAME }}-notarized-${{ matrix.artifact.name }} + name: ${{ env.ARTIFACT_PREFIX }}notarized-${{ matrix.build.folder-suffix }} path: ${{ env.DIST_DIR }}/${{ env.PACKAGE_FILENAME }} publish-nightly: @@ -179,7 +188,7 @@ jobs: - name: Download artifact uses: actions/download-artifact@v4 with: - pattern: ${{ env.ARTIFACT_NAME }}-* + pattern: ${{ env.ARTIFACT_PREFIX }}* merge-multiple: true path: ${{ env.DIST_DIR }} diff --git a/.github/workflows/publish-go-tester-task.yml b/.github/workflows/publish-go-tester-task.yml index 9b57d04d..5842ed10 100644 --- a/.github/workflows/publish-go-tester-task.yml +++ b/.github/workflows/publish-go-tester-task.yml @@ -75,7 +75,7 @@ jobs: build: needs: package-name-prefix - name: Build ${{ matrix.os.name }} + name: Build ${{ matrix.os.artifact-name }} runs-on: ubuntu-latest permissions: contents: read @@ -85,31 +85,31 @@ jobs: os: - task: Windows_32bit path: "*Windows_32bit.zip" - name: Windows_X86-32 + artifact-name: Windows_X86-32 - task: Windows_64bit path: "*Windows_64bit.zip" - name: Windows_X86-64 + artifact-name: Windows_X86-64 - task: Linux_32bit path: "*Linux_32bit.tar.gz" - name: Linux_X86-32 + artifact-name: Linux_X86-32 - task: Linux_64bit path: "*Linux_64bit.tar.gz" - name: Linux_X86-64 + artifact-name: Linux_X86-64 - task: Linux_ARMv6 path: "*Linux_ARMv6.tar.gz" - name: Linux_ARMv6 + artifact-name: Linux_ARMv6 - task: Linux_ARMv7 path: "*Linux_ARMv7.tar.gz" - name: Linux_ARMv7 + artifact-name: Linux_ARMv7 - task: Linux_ARM64 path: "*Linux_ARM64.tar.gz" - name: Linux_ARM64 + artifact-name: Linux_ARM64 - task: macOS_64bit path: "*macOS_64bit.tar.gz" - name: macOS_64 + artifact-name: macOS_64 - task: macOS_ARM64 path: "*macOS_ARM64.tar.gz" - name: macOS_ARM64 + artifact-name: macOS_ARM64 steps: - name: Checkout repository @@ -132,7 +132,7 @@ jobs: uses: actions/upload-artifact@v4 with: path: ${{ env.DIST_DIR }}/${{ matrix.os.path }} - name: ${{ matrix.os.name }} + name: ${{ matrix.os.artifact-name }} checksums: needs: diff --git a/.github/workflows/release-go-task.yml b/.github/workflows/release-go-task.yml index 751ab682..bbe405c2 100644 --- a/.github/workflows/release-go-task.yml +++ b/.github/workflows/release-go-task.yml @@ -8,7 +8,7 @@ env: DIST_DIR: dist # The project's folder on Arduino's download server for uploading builds AWS_PLUGIN_TARGET: /arduino-lint/ - ARTIFACT_NAME: dist + ARTIFACT_PREFIX: dist- on: push: @@ -24,15 +24,24 @@ jobs: strategy: matrix: os: - - Windows_32bit - - Windows_64bit - - Linux_32bit - - Linux_64bit - - Linux_ARMv6 - - Linux_ARMv7 - - Linux_ARM64 - - macOS_64bit - - macOS_ARM64 + - task: Windows_32bit + artifact-suffix: Windows_32bit + - task: Windows_64bit + artifact-suffix: Windows_64bit + - task: Linux_32bit + artifact-suffix: Linux_32bit + - task: Linux_64bit + artifact-suffix: Linux_64bit + - task: Linux_ARMv6 + artifact-suffix: Linux_ARMv6 + - task: Linux_ARMv7 + artifact-suffix: Linux_ARMv7 + - task: Linux_ARM64 + artifact-suffix: Linux_ARM64 + - task: macOS_64bit + artifact-suffix: macOS_64bit + - task: macOS_ARM64 + artifact-suffix: macOS_ARM64 steps: - name: Checkout repository @@ -42,7 +51,7 @@ jobs: - name: Create changelog # Avoid creating the same changelog for each os - if: matrix.os == 'Windows_32bit' + if: matrix.os.task == 'Windows_32bit' uses: arduino/create-changelog@v1 with: tag-regex: '^[0-9]+\.[0-9]+\.[0-9]+.*$' @@ -57,17 +66,17 @@ jobs: version: 3.x - name: Build - run: task dist:${{ matrix.os }} + run: task dist:${{ matrix.os.task }} - name: Upload artifacts uses: actions/upload-artifact@v4 with: if-no-files-found: error - name: ${{ env.ARTIFACT_NAME }}-${{ matrix.os }} + name: ${{ env.ARTIFACT_PREFIX }}${{ matrix.os.artifact-suffix }} path: ${{ env.DIST_DIR }} notarize-macos: - name: Notarize ${{ matrix.artifact.name }} + name: Notarize ${{ matrix.build.folder-suffix }} runs-on: macos-latest needs: create-release-artifacts outputs: @@ -81,11 +90,11 @@ jobs: strategy: matrix: - artifact: - - name: darwin_amd64 - path: "macOS_64bit.tar.gz" - - name: darwin_arm64 - path: "macOS_ARM64.tar.gz" + build: + - folder-suffix: darwin_amd64 + package-suffix: "macOS_64bit.tar.gz" + - folder-suffix: darwin_arm64 + package-suffix: "macOS_ARM64.tar.gz" steps: - name: Checkout repository @@ -94,7 +103,7 @@ jobs: - name: Download artifacts uses: actions/download-artifact@v4 with: - pattern: ${{ env.ARTIFACT_NAME }}-* + pattern: ${{ env.ARTIFACT_PREFIX }}* merge-multiple: true path: ${{ env.DIST_DIR }} @@ -131,7 +140,7 @@ jobs: run: | cat > "${{ env.GON_CONFIG_PATH }}" <> $GITHUB_ENV @@ -172,7 +181,7 @@ jobs: uses: actions/upload-artifact@v4 with: if-no-files-found: error - name: ${{ env.ARTIFACT_NAME }}-notarized-${{ matrix.artifact.name }} + name: ${{ env.ARTIFACT_PREFIX }}notarized-${{ matrix.build.folder-suffix }} path: ${{ env.DIST_DIR }}/${{ env.PACKAGE_FILENAME }} create-release: @@ -185,7 +194,7 @@ jobs: - name: Download artifact uses: actions/download-artifact@v4 with: - pattern: ${{ env.ARTIFACT_NAME }}-* + pattern: ${{ env.ARTIFACT_PREFIX }}* merge-multiple: true path: ${{ env.DIST_DIR }} From 13600767eaa858b5a3e1f757f9bf8ec8b08d6047 Mon Sep 17 00:00:00 2001 From: per1234 Date: Sun, 13 Oct 2024 15:49:46 -0700 Subject: [PATCH 2/3] Use environment variable to define build folder name in release workflows Multiple commands in the release workflow include the path of the folder that contains the build output. Previously, the complex folder name was specified redundantly in each instance. The readability and maintainability of the workflow is improved by using an environment variable to define the folder name in a single place, then referencing that environment variable in each of the individual commands that use the path. --- .github/workflows/publish-go-nightly-task.yml | 11 ++++++++--- .github/workflows/release-go-task.yml | 11 ++++++++--- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/.github/workflows/publish-go-nightly-task.yml b/.github/workflows/publish-go-nightly-task.yml index c68f02c7..75203701 100644 --- a/.github/workflows/publish-go-nightly-task.yml +++ b/.github/workflows/publish-go-nightly-task.yml @@ -92,6 +92,11 @@ jobs: package-suffix: "macOS_ARM64.tar.gz" steps: + - name: Set environment variables + run: | + # See: https://docs.github.com/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions#setting-an-environment-variable + echo "BUILD_FOLDER=${{ env.PROJECT_NAME }}_osx_${{ matrix.build.folder-suffix }}" >> "$GITHUB_ENV" + - name: Checkout repository uses: actions/checkout@v4 @@ -135,7 +140,7 @@ jobs: run: | cat > "${{ env.GON_CONFIG_PATH }}" <> $GITHUB_ENV diff --git a/.github/workflows/release-go-task.yml b/.github/workflows/release-go-task.yml index bbe405c2..8795334e 100644 --- a/.github/workflows/release-go-task.yml +++ b/.github/workflows/release-go-task.yml @@ -97,6 +97,11 @@ jobs: package-suffix: "macOS_ARM64.tar.gz" steps: + - name: Set environment variables + run: | + # See: https://docs.github.com/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions#setting-an-environment-variable + echo "BUILD_FOLDER=${{ env.PROJECT_NAME }}_osx_${{ matrix.build.folder-suffix }}" >> "$GITHUB_ENV" + - name: Checkout repository uses: actions/checkout@v4 @@ -140,7 +145,7 @@ jobs: run: | cat > "${{ env.GON_CONFIG_PATH }}" <> $GITHUB_ENV From 0e961c82a868348c765509ef6074eb972dcedd9d Mon Sep 17 00:00:00 2001 From: per1234 Date: Sun, 13 Oct 2024 15:52:31 -0700 Subject: [PATCH 3/3] Move definition of package filename to dedicated step in release workflow The package filename is referenced in multiple places in the release workflow. In order to avoid code duplication, it is defined once as an environment variable, then that variable referenced in each of the instances where the filename is needed. Previously, this was done by first defining and referencing a shell environment variable at the point of the first usage, then defining a workflow environment variable and referencing that in the second usage. The maintainability and readability of the workflow is improved by using a single workflow environment variable, defined in the step dedicated to defining such variables, then referencing it consistently in all usages. --- .github/workflows/release-go-task.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/release-go-task.yml b/.github/workflows/release-go-task.yml index 8795334e..1a0733a9 100644 --- a/.github/workflows/release-go-task.yml +++ b/.github/workflows/release-go-task.yml @@ -101,6 +101,8 @@ jobs: run: | # See: https://docs.github.com/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions#setting-an-environment-variable echo "BUILD_FOLDER=${{ env.PROJECT_NAME }}_osx_${{ matrix.build.folder-suffix }}" >> "$GITHUB_ENV" + TAG="${GITHUB_REF/refs\/tags\//}" + echo "PACKAGE_FILENAME=${{ env.PROJECT_NAME }}_${TAG}_${{ matrix.build.package-suffix }}" >> $GITHUB_ENV - name: Checkout repository uses: actions/checkout@v4 @@ -175,12 +177,9 @@ jobs: # GitHub's upload/download-artifact actions don't preserve file permissions, # so we need to add execution permission back until the action is made to do this. chmod +x "${{ env.BUILD_FOLDER }}/${{ env.PROJECT_NAME }}" - TAG="${GITHUB_REF/refs\/tags\//}" - PACKAGE_FILENAME="${{ env.PROJECT_NAME }}_${TAG}_${{ matrix.build.package-suffix }}" - tar -czvf "$PACKAGE_FILENAME" \ + tar -czvf "${{ env.PACKAGE_FILENAME }}" \ -C "${{ env.BUILD_FOLDER }}/" "${{ env.PROJECT_NAME }}" \ -C ../../ LICENSE.txt - echo "PACKAGE_FILENAME=$PACKAGE_FILENAME" >> $GITHUB_ENV - name: Upload artifact uses: actions/upload-artifact@v4