mirror of
https://github.com/rlespinasse/github-slug-action.git
synced 2026-09-15 07:12:20 +00:00
fix: consolidate slugify-value calls to reduce console env dumps (#161)
Replace the 9 separate rlespinasse/slugify-value composite action calls (plus the 2 helper id steps feeding them) with a single in-repo slugify-env.sh script that reimplements the same slug/slug-cs/slug-url/ slug-url-cs logic for all 9 GitHub context keys in one pass. Each shell run step triggers the runner's own log renderer to print a full "env:" dump; with 9 separate steps that dump was repeated ~9 times per job. This collapses those calls into a single step, cutting the env-dump repetition ~9x with no change to any GITHUB_ENV variable name or value consumers rely on. Note: the "publish-env" input on slugify-value never controlled this log dump (it only gates writing computed values to GITHUB_ENV); the fix is purely a step-count reduction, per the maintainer's own comment on the issue.
This commit is contained in:
88
action.yml
88
action.yml
@@ -26,83 +26,19 @@ runs:
|
||||
INPUT_SLUG_MAXLENGTH: ${{ inputs.slug-maxlength }}
|
||||
INPUT_SHORT_LENGTH: ${{ inputs.short-length }}
|
||||
|
||||
# From Environment Variables
|
||||
- uses: rlespinasse/slugify-value@a4879db1eb3db9bbee01dca36f98a8236c2b8239 # v1.4.0
|
||||
with:
|
||||
key: GITHUB_REPOSITORY
|
||||
value: ${{ github.repository }}
|
||||
prefix: ${{ inputs.prefix }}
|
||||
slug-maxlength: ${{ inputs.slug-maxlength }}
|
||||
- uses: rlespinasse/slugify-value@a4879db1eb3db9bbee01dca36f98a8236c2b8239 # v1.4.0
|
||||
with:
|
||||
key: GITHUB_REF
|
||||
prefix: ${{ inputs.prefix }}
|
||||
slug-maxlength: ${{ inputs.slug-maxlength }}
|
||||
- uses: rlespinasse/slugify-value@a4879db1eb3db9bbee01dca36f98a8236c2b8239 # v1.4.0
|
||||
with:
|
||||
key: GITHUB_HEAD_REF
|
||||
prefix: ${{ inputs.prefix }}
|
||||
slug-maxlength: ${{ inputs.slug-maxlength }}
|
||||
- uses: rlespinasse/slugify-value@a4879db1eb3db9bbee01dca36f98a8236c2b8239 # v1.4.0
|
||||
with:
|
||||
key: GITHUB_BASE_REF
|
||||
prefix: ${{ inputs.prefix }}
|
||||
slug-maxlength: ${{ inputs.slug-maxlength }}
|
||||
|
||||
# From Specific values
|
||||
- uses: rlespinasse/slugify-value@a4879db1eb3db9bbee01dca36f98a8236c2b8239 # v1.4.0
|
||||
with:
|
||||
key: GITHUB_EVENT_REF
|
||||
value: ${{ github.event.ref }}
|
||||
prefix: ${{ inputs.prefix }}
|
||||
slug-maxlength: ${{ inputs.slug-maxlength }}
|
||||
- uses: rlespinasse/slugify-value@a4879db1eb3db9bbee01dca36f98a8236c2b8239 # v1.4.0
|
||||
with:
|
||||
key: GITHUB_REF_NAME
|
||||
value: ${{ github.ref_name }}
|
||||
prefix: ${{ inputs.prefix }}
|
||||
slug-maxlength: ${{ inputs.slug-maxlength }}
|
||||
- uses: rlespinasse/slugify-value@a4879db1eb3db9bbee01dca36f98a8236c2b8239 # v1.4.0
|
||||
with:
|
||||
key: GITHUB_REF_POINT
|
||||
value: ${{ env.GITHUB_HEAD_REF_RAW || env.GITHUB_REF_NAME_RAW }}
|
||||
prefix: ${{ inputs.prefix }}
|
||||
slug-maxlength: ${{ inputs.slug-maxlength }}
|
||||
# From Environment Variables, Specific values and Calculated values
|
||||
# Consolidated into a single step to avoid the runner printing a
|
||||
# repeated "env:" dump for every shell run step (see issue #161).
|
||||
- run: $GITHUB_ACTION_PATH/slugify-env.sh
|
||||
id: slugify-env
|
||||
shell: bash
|
||||
env:
|
||||
GITHUB_HEAD_REF_RAW: ${{ github.head_ref }}
|
||||
GITHUB_REF_NAME_RAW: ${{ github.ref_name }}
|
||||
|
||||
# From Calculated values
|
||||
- id: get-github-repository-owner-part
|
||||
run: |
|
||||
ownerpart=$(echo $GITHUB_REPOSITORY | cut -d/ -f1)
|
||||
if [ -f "$GITHUB_OUTPUT" ]; then
|
||||
echo "github-repository-owner-part=${ownerpart}" >> "$GITHUB_OUTPUT"
|
||||
else
|
||||
echo "::set-output name=github-repository-owner-part::${ownerpart}"
|
||||
fi
|
||||
shell: bash
|
||||
- uses: rlespinasse/slugify-value@a4879db1eb3db9bbee01dca36f98a8236c2b8239 # v1.4.0
|
||||
with:
|
||||
key: GITHUB_REPOSITORY_OWNER_PART
|
||||
value: ${{ steps.get-github-repository-owner-part.outputs.github-repository-owner-part }}
|
||||
prefix: ${{ inputs.prefix }}
|
||||
slug-maxlength: ${{ inputs.slug-maxlength }}
|
||||
- id: get-github-repository-name-part
|
||||
run: |
|
||||
namepart=$(echo $GITHUB_REPOSITORY | cut -d/ -f2)
|
||||
if [ -f "$GITHUB_OUTPUT" ]; then
|
||||
echo "github-repository-name-part=${namepart}" >> "$GITHUB_OUTPUT"
|
||||
else
|
||||
echo "::set-output name=github-repository-name-part::${namepart}"
|
||||
fi
|
||||
shell: bash
|
||||
- uses: rlespinasse/slugify-value@a4879db1eb3db9bbee01dca36f98a8236c2b8239 # v1.4.0
|
||||
with:
|
||||
key: GITHUB_REPOSITORY_NAME_PART
|
||||
value: ${{ steps.get-github-repository-name-part.outputs.github-repository-name-part }}
|
||||
prefix: ${{ inputs.prefix }}
|
||||
slug-maxlength: ${{ inputs.slug-maxlength }}
|
||||
INPUT_PREFIX: ${{ inputs.prefix }}
|
||||
INPUT_SLUG_MAXLENGTH: ${{ inputs.slug-maxlength }}
|
||||
INPUT_GITHUB_REPOSITORY: ${{ github.repository }}
|
||||
INPUT_GITHUB_EVENT_REF: ${{ github.event.ref }}
|
||||
INPUT_GITHUB_REF_NAME: ${{ github.ref_name }}
|
||||
GITHUB_HEAD_REF: ${{ github.head_ref }}
|
||||
|
||||
# From sha
|
||||
- uses: rlespinasse/shortify-git-revision@c90ba7007ef6c152254d10b9f1a327966ab13077 # v1.6.0
|
||||
|
||||
98
slugify-env.sh
Executable file
98
slugify-env.sh
Executable file
@@ -0,0 +1,98 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Consolidates the 9 previous `rlespinasse/slugify-value` composite action calls
|
||||
# into a single shell step, to avoid the "env:" dump printed by the runner's
|
||||
# log renderer for every shell run step (see issue #161). This script
|
||||
# reimplements slugify-value's slug/slug-cs/slug-url/slug-url-cs/reduce logic
|
||||
# verbatim and writes the same GITHUB_ENV lines as before, for each key.
|
||||
|
||||
if [[ "$OSTYPE" == "darwin"* ]]; then
|
||||
# On MacOS,
|
||||
# bash don't support substitution, so we use 'tr'
|
||||
upper() { tr '[:lower:]' '[:upper:]' <<<"$1"; }
|
||||
lower() { tr '[:upper:]' '[:lower:]' <<<"$1"; }
|
||||
else
|
||||
upper() { local s="$1"; echo "${s^^}"; }
|
||||
lower() { local s="$1"; echo "${s,,}"; }
|
||||
fi
|
||||
|
||||
PREFIX=$(upper "$INPUT_PREFIX")
|
||||
|
||||
MAX_LENGTH=""
|
||||
if [ -z "${INPUT_SLUG_MAXLENGTH}" ]; then
|
||||
echo "::error ::slug-maxlength cannot be empty"
|
||||
exit 1
|
||||
elif [ "${INPUT_SLUG_MAXLENGTH}" -eq "${INPUT_SLUG_MAXLENGTH}" ] 2>/dev/null; then
|
||||
MAX_LENGTH="${INPUT_SLUG_MAXLENGTH}"
|
||||
elif [ "${INPUT_SLUG_MAXLENGTH}" == "nolimit" ]; then
|
||||
MAX_LENGTH="${INPUT_SLUG_MAXLENGTH}"
|
||||
else
|
||||
echo "::error ::slug-maxlength must be a number or equals to 'nolimit'"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
slug() {
|
||||
# 1st : Remove refs prefix
|
||||
# 2d : Replace unwanted characters
|
||||
# 3d : Remove leading hypens
|
||||
output=$(sed -E 's#refs/[^\/]*/##;s/[^a-zA-Z0-9._-]+/-/g;s/^-*//' <<<"$1")
|
||||
reduce "$output"
|
||||
}
|
||||
|
||||
slug_url() {
|
||||
# 1st : Remove refs prefix
|
||||
# 2d : Replace unwanted characters
|
||||
# 3d : Remove leading hypens
|
||||
output=$(sed -E 's#refs/[^\/]*/##;s/[^a-zA-Z0-9-]+/-/g;s/^-*//' <<<"$1")
|
||||
reduce "$output"
|
||||
}
|
||||
|
||||
reduce() {
|
||||
reduced_value="$1"
|
||||
if [ "${MAX_LENGTH}" != "nolimit" ]; then
|
||||
reduced_value=$(cut -c1-"${MAX_LENGTH}" <<<"$reduced_value")
|
||||
fi
|
||||
# 1st : Remove trailing hypens
|
||||
sed -E 's/-*$//' <<<"$reduced_value"
|
||||
}
|
||||
|
||||
# Owner/name parts, computed inline (replaces the two helper `id:` steps' outputs)
|
||||
GITHUB_REPOSITORY_OWNER_PART_VALUE=$(cut -d/ -f1 <<<"$INPUT_GITHUB_REPOSITORY")
|
||||
GITHUB_REPOSITORY_NAME_PART_VALUE=$(cut -d/ -f2 <<<"$INPUT_GITHUB_REPOSITORY")
|
||||
|
||||
process() {
|
||||
local key="$1"
|
||||
local value="$2"
|
||||
local cs_value="${value:-${!key}}"
|
||||
local upper_key
|
||||
upper_key=$(upper "$key")
|
||||
local val
|
||||
val=$(lower "$cs_value")
|
||||
local slug_v slug_cs slug_url_v slug_url_cs
|
||||
slug_v=$(slug "$val")
|
||||
slug_cs=$(slug "$cs_value")
|
||||
slug_url_v=$(slug_url "$val")
|
||||
slug_url_cs=$(slug_url "$cs_value")
|
||||
{
|
||||
echo "${PREFIX}${upper_key}=${cs_value}"
|
||||
echo "${PREFIX}${upper_key}_SLUG=${slug_v}"
|
||||
echo "${PREFIX}${upper_key}_SLUG_CS=${slug_cs}"
|
||||
echo "${PREFIX}${upper_key}_SLUG_URL=${slug_url_v}"
|
||||
echo "${PREFIX}${upper_key}_SLUG_URL_CS=${slug_url_cs}"
|
||||
} >>"$GITHUB_ENV"
|
||||
}
|
||||
|
||||
# From Environment Variables
|
||||
process GITHUB_REPOSITORY "$INPUT_GITHUB_REPOSITORY"
|
||||
process GITHUB_REF ""
|
||||
process GITHUB_HEAD_REF ""
|
||||
process GITHUB_BASE_REF ""
|
||||
|
||||
# From Specific values
|
||||
process GITHUB_EVENT_REF "$INPUT_GITHUB_EVENT_REF"
|
||||
process GITHUB_REF_NAME "$INPUT_GITHUB_REF_NAME"
|
||||
process GITHUB_REF_POINT "${GITHUB_HEAD_REF:-$INPUT_GITHUB_REF_NAME}"
|
||||
|
||||
# From Calculated values
|
||||
process GITHUB_REPOSITORY_OWNER_PART "$GITHUB_REPOSITORY_OWNER_PART_VALUE"
|
||||
process GITHUB_REPOSITORY_NAME_PART "$GITHUB_REPOSITORY_NAME_PART_VALUE"
|
||||
Reference in New Issue
Block a user