@@ -21,34 +21,32 @@ jobs:
21
21
shell : bash
22
22
run : |
23
23
# Get repository name
24
- REPO_NAME="${{ github.event.repository.name }}"
24
+ repo_name="${{ github.event.repository.name }}"
25
+ # 1. Clean the repository name
26
+ # Convert to lowercase, replace non-alphanumeric/hyphen with hyphen,
27
+ # reduce multiple hyphens, remove leading/trailing hyphens.
28
+ cleaned_name=$(echo "$repo_name" | tr '[:upper:]' '[:lower:]' | \
29
+ sed 's/[^a-z0-9-]/-/g' | sed 's/-\{2,\}/-/g' | \
30
+ sed 's/^-//;s/-$//')
25
31
26
- # If repo name is less than 20 characters, use it directly
27
- if [[ ${#REPO_NAME} -lt 20 ]]; then
28
- STACK_PREFIX="${REPO_NAME}"
29
- else
30
- # Split by hyphen or underscore and get first letter of each word
31
- PREFIX=$(echo "$REPO_NAME" |
32
- awk -v RS='[-_]' '{printf "%s", tolower(substr($0,1,1))}' |
33
- tr -d '\n')
32
+ # Define the target length for the human-readable prefix
33
+ prefix_len=5
34
34
35
- # Ensure at least 4 characters without repetition
36
- while [[ ${#PREFIX} -lt 4 ]]; do
37
- # Concatenate with the next letter in the sequence (avoiding randomness)
38
- SUFFIX="${PREFIX: -1}" # Get the last character of the current PREFIX
39
- INDEX=$(( $(echo "$PREFIX" | grep -o "$SUFFIX" | wc -l) + 1 )) # Get the index of the next character
40
- NEXT_CHAR=$(echo "$PREFIX" | cut -c $INDEX) # Get the next character
41
- PREFIX="${PREFIX}${NEXT_CHAR}"
42
- done
35
+ # 2. Generate the 5-character human-readable prefix
36
+ prefix_part=""
37
+ # Remove all hyphens from the cleaned name to get a continuous string of letters/numbers
38
+ continuous_name=$(echo "$cleaned_name" | sed 's/-//g')
43
39
44
- # Truncate if prefix exceeds 10 characters
45
- if [[ ${#PREFIX} -gt 10 ]]; then
46
- PREFIX="${PREFIX:0:10}"
47
- fi
40
+ # Take up to 'prefix_len' (5) characters, but allow shorter prefixes
41
+ prefix_part="${continuous_name:0:$prefix_len}"
48
42
49
- STACK_PREFIX="${PREFIX}"
50
- fi
43
+ # 3. Generate the 4-character consistent hash suffix
44
+ # The MD5 hash of the original repo name ensures consistency and uniqueness
45
+ hash_suffix=$(echo -n "$repo_name" | md5sum | head -c 4)
46
+
47
+ # 4. Combine the prefix, hyphen, and hash suffix
48
+ final_name="${prefix_part}-${hash_suffix}"
51
49
52
50
# Set output
53
- echo "STACK_PREFIX=$STACK_PREFIX " >> $GITHUB_OUTPUT
54
- echo "Generated prefix: $STACK_PREFIX "
51
+ echo "STACK_PREFIX=$final_name " >> $GITHUB_OUTPUT
52
+ echo "Generated prefix: $final_name "
0 commit comments