Skip to content

Commit 01508be

Browse files
committed
Include a branch name (from the input) when generating artifact names
since we may end up trying to create artifacts with the same names for different branches when running a scheduled workflow
1 parent 5ea1eb9 commit 01508be

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

.github/workflows/build.yml

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,14 @@ jobs:
9191
run: |
9292
echo "yearmonth=$(/bin/date -u '+%Y-%m')" >> "$GITHUB_OUTPUT"
9393
shell: bash
94+
- name: Sanitize the branch name
95+
# We want to include the branch in artifact names to keep them unique.
96+
# Branch names may have some symbols that are not "friendly" for file names e.g. we may have a branch `wip/4.0`
97+
# This step replaces any unwanted characters with a dash:`wip/4.0` -> `wip-4.0` or build/test-github-workflow-update123.4
98+
shell: bash
99+
id: current-branch-suffix
100+
run: |
101+
echo "value=$(echo ${{ inputs.branch }} | sed -E 's/[^A-Za-z0-9._-]+/-/g')" >> "$GITHUB_OUTPUT"
94102
- name: Cache Gradle downloads
95103
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
96104
id: cache-gradle
@@ -121,7 +129,7 @@ jobs:
121129
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
122130
if: failure()
123131
with:
124-
name: reports-examples-${{ matrix.db }}
132+
name: reports-examples-${{ matrix.db }}-${{steps.current-branch-suffix.outputs.value}}
125133
path: './**/build/reports/'
126134

127135
test_dbs:
@@ -140,6 +148,14 @@ jobs:
140148
run: |
141149
echo "yearmonth=$(/bin/date -u '+%Y-%m')" >> "$GITHUB_OUTPUT"
142150
shell: bash
151+
- name: Sanitize the branch name
152+
# We want to include the branch in artifact names to keep them unique.
153+
# Branch names may have some symbols that are not "friendly" for file names e.g. we may have a branch `wip/4.0`
154+
# This step replaces any unwanted characters with a dash:`wip/4.0` -> `wip-4.0` or build/test-github-workflow-update123.4
155+
shell: bash
156+
id: current-branch-suffix
157+
run: |
158+
echo "value=$(echo ${{ inputs.branch }} | sed -E 's/[^A-Za-z0-9._-]+/-/g')" >> "$GITHUB_OUTPUT"
143159
- name: Cache Gradle downloads
144160
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
145161
id: cache-gradle
@@ -171,7 +187,7 @@ jobs:
171187
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
172188
if: failure()
173189
with:
174-
name: reports-db-${{ matrix.db }}
190+
name: reports-db-${{ matrix.db }}-${{steps.current-branch-suffix.outputs.value}}
175191
path: './**/build/reports/'
176192

177193
test_jdks:
@@ -204,7 +220,14 @@ jobs:
204220
run: |
205221
echo "yearmonth=$(/bin/date -u '+%Y-%m')" >> "$GITHUB_OUTPUT"
206222
shell: bash
207-
223+
- name: Sanitize the branch name
224+
# We want to include the branch in artifact names to keep them unique.
225+
# Branch names may have some symbols that are not "friendly" for file names e.g. we may have a branch `wip/4.0`
226+
# This step replaces any unwanted characters with a dash:`wip/4.0` -> `wip-4.0` or build/test-github-workflow-update123.4
227+
shell: bash
228+
id: current-branch-suffix
229+
run: |
230+
echo "value=$(echo ${{ inputs.branch }} | sed -E 's/[^A-Za-z0-9._-]+/-/g')" >> "$GITHUB_OUTPUT"
208231
- name: Generate cache key
209232
id: cache-key
210233
run: |
@@ -295,5 +318,5 @@ jobs:
295318
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
296319
if: failure()
297320
with:
298-
name: reports-java${{ matrix.java.name }}
321+
name: reports-java${{ matrix.java.name }}-${{steps.current-branch-suffix.outputs.value}}
299322
path: './**/build/reports/'

0 commit comments

Comments
 (0)