From b24d25707d26c0bacf448c6fb6a2f15f901e8122 Mon Sep 17 00:00:00 2001 From: per1234 Date: Tue, 5 Nov 2024 23:25:14 -0800 Subject: [PATCH 1/3] Use more meaningful variable names in release workflow A GitHub Actions workflow is used to automatically generate 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/release-go-task.yml | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/release-go-task.yml b/.github/workflows/release-go-task.yml index 9e64699..0501bb8 100644 --- a/.github/workflows/release-go-task.yml +++ b/.github/workflows/release-go-task.yml @@ -23,7 +23,7 @@ jobs: strategy: matrix: - os: + task: - Windows_32bit - Windows_64bit - Linux_32bit @@ -42,7 +42,7 @@ jobs: - name: Create changelog # Avoid creating the same changelog for each os - if: matrix.os == 'Windows_32bit' + if: matrix.task == 'Windows_32bit' uses: arduino/create-changelog@v1 with: tag-regex: '^[0-9]+\.[0-9]+\.[0-9]+.*$' @@ -57,7 +57,7 @@ jobs: version: 3.x - name: Build - run: task dist:${{ matrix.os }} + run: task dist:${{ matrix.task }} - name: Upload artifacts uses: actions/upload-artifact@v3 @@ -67,7 +67,7 @@ jobs: 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 +81,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 @@ -131,7 +131,7 @@ jobs: run: | cat > "${{ env.GON_CONFIG_PATH }}" <> $GITHUB_ENV From 70a225bf2411df6e996ddd38d36dd68be4f38cf7 Mon Sep 17 00:00:00 2001 From: per1234 Date: Tue, 5 Nov 2024 23:32:27 -0800 Subject: [PATCH 2/3] Use environment variable to define build folder name in release workflow 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/release-go-task.yml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release-go-task.yml b/.github/workflows/release-go-task.yml index 0501bb8..daa2b61 100644 --- a/.github/workflows/release-go-task.yml +++ b/.github/workflows/release-go-task.yml @@ -88,6 +88,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 @@ -131,7 +136,7 @@ jobs: run: | cat > "${{ env.GON_CONFIG_PATH }}" <> $GITHUB_ENV + -C "${{ env.BUILD_FOLDER }}/" "${{ env.PROJECT_NAME }}" \ - name: Upload artifact uses: actions/upload-artifact@v3 From 12c05d1fde6973b4ec9c8c39b7bce4f3b902308d Mon Sep 17 00:00:00 2001 From: per1234 Date: Tue, 5 Nov 2024 23:33:46 -0800 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 daa2b61..fc92e81 100644 --- a/.github/workflows/release-go-task.yml +++ b/.github/workflows/release-go-task.yml @@ -92,6 +92,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 @@ -166,10 +168,7 @@ 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" "${PLATFORM_DIR}" - echo "PACKAGE_FILENAME=$PACKAGE_FILENAME" >> $GITHUB_ENV + tar -czvf "${{ env.PACKAGE_FILENAME }}" \ -C "${{ env.BUILD_FOLDER }}/" "${{ env.PROJECT_NAME }}" \ - name: Upload artifact