Skip to content

Commit 1360076

Browse files
committed
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.
1 parent 553d0b5 commit 1360076

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

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

+8-3
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ jobs:
9292
package-suffix: "macOS_ARM64.tar.gz"
9393

9494
steps:
95+
- name: Set environment variables
96+
run: |
97+
# See: https://docs.github.com/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions#setting-an-environment-variable
98+
echo "BUILD_FOLDER=${{ env.PROJECT_NAME }}_osx_${{ matrix.build.folder-suffix }}" >> "$GITHUB_ENV"
99+
95100
- name: Checkout repository
96101
uses: actions/checkout@v4
97102

@@ -135,7 +140,7 @@ jobs:
135140
run: |
136141
cat > "${{ env.GON_CONFIG_PATH }}" <<EOF
137142
# See: https://github.com/Bearer/gon#configuration-file
138-
source = ["${{ env.DIST_DIR }}/${{ env.PROJECT_NAME }}_osx_${{ matrix.build.folder-suffix }}/${{ env.PROJECT_NAME }}"]
143+
source = ["${{ env.DIST_DIR }}/${{ env.BUILD_FOLDER }}/${{ env.PROJECT_NAME }}"]
139144
bundle_id = "cc.arduino.${{ env.PROJECT_NAME }}"
140145
141146
sign {
@@ -164,11 +169,11 @@ jobs:
164169
run: |
165170
# GitHub's upload/download-artifact actions don't preserve file permissions,
166171
# so we need to add execution permission back until the action is made to do this.
167-
chmod +x "${{ env.PROJECT_NAME }}_osx_${{ matrix.build.folder-suffix }}/${{ env.PROJECT_NAME }}"
172+
chmod +x "${{ env.BUILD_FOLDER }}/${{ env.PROJECT_NAME }}"
168173
# Use of an array here is required for globbing
169174
PACKAGE_FILENAME=(${{ env.PROJECT_NAME }}_nightly-*${{ matrix.build.package-suffix }})
170175
tar -czvf "$PACKAGE_FILENAME" \
171-
-C "${{ env.PROJECT_NAME }}_osx_${{ matrix.build.folder-suffix }}/" "${{ env.PROJECT_NAME }}" \
176+
-C "${{ env.BUILD_FOLDER }}/" "${{ env.PROJECT_NAME }}" \
172177
-C ../../ LICENSE.txt
173178
echo "PACKAGE_FILENAME=$PACKAGE_FILENAME" >> $GITHUB_ENV
174179

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

+8-3
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ jobs:
9797
package-suffix: "macOS_ARM64.tar.gz"
9898

9999
steps:
100+
- name: Set environment variables
101+
run: |
102+
# See: https://docs.github.com/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions#setting-an-environment-variable
103+
echo "BUILD_FOLDER=${{ env.PROJECT_NAME }}_osx_${{ matrix.build.folder-suffix }}" >> "$GITHUB_ENV"
104+
100105
- name: Checkout repository
101106
uses: actions/checkout@v4
102107

@@ -140,7 +145,7 @@ jobs:
140145
run: |
141146
cat > "${{ env.GON_CONFIG_PATH }}" <<EOF
142147
# See: https://github.com/Bearer/gon#configuration-file
143-
source = ["${{ env.DIST_DIR }}/${{ env.PROJECT_NAME }}_osx_${{ matrix.build.folder-suffix }}/${{ env.PROJECT_NAME }}"]
148+
source = ["${{ env.DIST_DIR }}/${{ env.BUILD_FOLDER }}/${{ env.PROJECT_NAME }}"]
144149
bundle_id = "cc.arduino.${{ env.PROJECT_NAME }}"
145150
146151
sign {
@@ -169,11 +174,11 @@ jobs:
169174
run: |
170175
# GitHub's upload/download-artifact actions don't preserve file permissions,
171176
# so we need to add execution permission back until the action is made to do this.
172-
chmod +x "${{ env.PROJECT_NAME }}_osx_${{ matrix.build.folder-suffix }}/${{ env.PROJECT_NAME }}"
177+
chmod +x "${{ env.BUILD_FOLDER }}/${{ env.PROJECT_NAME }}"
173178
TAG="${GITHUB_REF/refs\/tags\//}"
174179
PACKAGE_FILENAME="${{ env.PROJECT_NAME }}_${TAG}_${{ matrix.build.package-suffix }}"
175180
tar -czvf "$PACKAGE_FILENAME" \
176-
-C "${{ env.PROJECT_NAME }}_osx_${{ matrix.build.folder-suffix }}/" "${{ env.PROJECT_NAME }}" \
181+
-C "${{ env.BUILD_FOLDER }}/" "${{ env.PROJECT_NAME }}" \
177182
-C ../../ LICENSE.txt
178183
echo "PACKAGE_FILENAME=$PACKAGE_FILENAME" >> $GITHUB_ENV
179184

0 commit comments

Comments
 (0)