Skip to content

Commit 75f318a

Browse files
zakkakjerboaa
andcommitted
[CI] Ensure artifacts suffix is less than 200 characters
Fixes #902 Co-authored-by: Severin Gehwolf <sgehwolf@redhat.com>
1 parent 7678805 commit 75f318a

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

.github/workflows/base-windows.yml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,20 @@ jobs:
139139
steps:
140140
- id: suffix
141141
run: |
142-
export SUFFIX=$(echo '${{ toJson(inputs) }}' | jq -j 'del(."build-stats-tag", ."mandrel-it-issue-number", ."issue-repo", ."issue-number") | to_entries[] | "-\(.value)"' | tr '":<>|*?\\r\n\/' '-')
143-
echo $SUFFIX
142+
# Build a suffix from inputs but ensure it's safe and has an upper bound on its length (200 characters).
143+
SUFFIX_RAW=$(echo '${{ toJson(inputs) }}' | jq -j 'del(."build-stats-tag", ."mandrel-it-issue-number", ."issue-repo", ."issue-number") | to_entries[] | "-\(.value)"')
144+
# Replace characters that are unsafe for artifact names with '-'
145+
SUFFIX_CLEAN=$(echo "$SUFFIX_RAW" | tr '\":<>|*?\\r\\n\\/' '-' | tr -s '-')
146+
# If the cleaned suffix is reasonably short, use it. Otherwise, create a short stable suffix
147+
# using the run id and a short hash to guarantee length < 256.
148+
MAX_LEN=200
149+
if [ $(echo -n "$SUFFIX_CLEAN" | wc -c) -le $MAX_LEN ]; then
150+
SUFFIX="$SUFFIX_CLEAN"
151+
else
152+
HASH=$(echo -n "$SUFFIX_CLEAN" | sha1sum | cut -c1-40)
153+
SUFFIX="-run${GITHUB_RUN_ID}-${HASH}"
154+
fi
155+
echo "$SUFFIX"
144156
echo "suffix=$SUFFIX" >> $GITHUB_OUTPUT
145157
- name: Get Quarkus version and test matrix
146158
id: version

.github/workflows/base.yml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,20 @@ jobs:
175175
steps:
176176
- id: suffix
177177
run: |
178-
export SUFFIX=$(echo '${{ toJson(inputs) }}' | jq -j 'del(."build-stats-tag", ."mandrel-it-issue-number", ."issue-repo", ."issue-number") | to_entries[] | "-\(.value)"' | tr '":<>|*?\r\n\/' '-')
179-
echo $SUFFIX
178+
# Build a suffix from inputs but ensure it's safe and has an upper bound on its length (200 characters).
179+
SUFFIX_RAW=$(echo '${{ toJson(inputs) }}' | jq -j 'del(."build-stats-tag", ."mandrel-it-issue-number", ."issue-repo", ."issue-number") | to_entries[] | "-\(.value)"')
180+
# Replace characters that are unsafe for artifact names with '-'
181+
SUFFIX_CLEAN=$(echo "$SUFFIX_RAW" | tr '":<>|*?\r\n\/' '-' | tr -s '-')
182+
# If the cleaned suffix is reasonably short, use it. Otherwise, create a short stable suffix
183+
# using the run id and a short hash to guarantee length < 256.
184+
MAX_LEN=200
185+
if [ $(echo -n "$SUFFIX_CLEAN" | wc -c) -le $MAX_LEN ]; then
186+
SUFFIX="$SUFFIX_CLEAN"
187+
else
188+
HASH=$(echo -n "$SUFFIX_CLEAN" | sha1sum | cut -c1-40)
189+
SUFFIX="-run${GITHUB_RUN_ID}-${HASH}"
190+
fi
191+
echo "$SUFFIX"
180192
echo "suffix=$SUFFIX" >> $GITHUB_OUTPUT
181193
echo "**artifacts-suffix:** ${SUFFIX}" >> $GITHUB_STEP_SUMMARY
182194
- name: Get Quarkus version and test matrix

0 commit comments

Comments
 (0)