3 Commits

Author SHA1 Message Date
Romain Lespinasse
a4879db1eb feat: support GHES step output management 2022-10-31 19:44:04 +01:00
Vin
1d53af49fb fix: use environment file to manage outputs 2022-10-15 21:27:02 +02:00
Romain Lespinasse
f1c7463d0d fix(slug): remove trailing hypens if any after reduction 2022-06-16 09:55:04 +02:00
3 changed files with 28 additions and 23 deletions

View File

@@ -79,8 +79,8 @@ jobs:
- name: Validate // Slugify with another max length - name: Validate // Slugify with another max length
run: | run: |
[[ "${{ env.ANOTHER_MAX_LENGTH }}" == "Never gonna give you up Never gonna let you down" ]] [[ "${{ env.ANOTHER_MAX_LENGTH }}" == "Never gonna give you up Never gonna let you down" ]]
[[ "${{ env.ANOTHER_MAX_LENGTH_SLUG }}" == "never-gonna-give-you-up-" ]] [[ "${{ env.ANOTHER_MAX_LENGTH_SLUG }}" == "never-gonna-give-you-up" ]]
[[ "${{ env.ANOTHER_MAX_LENGTH_SLUG_CS }}" == "Never-gonna-give-you-up-" ]] [[ "${{ env.ANOTHER_MAX_LENGTH_SLUG_CS }}" == "Never-gonna-give-you-up" ]]
[[ "${{ env.ANOTHER_MAX_LENGTH_SLUG_URL }}" == "never-gonna-give-you-up" ]] [[ "${{ env.ANOTHER_MAX_LENGTH_SLUG_URL }}" == "never-gonna-give-you-up" ]]
[[ "${{ env.ANOTHER_MAX_LENGTH_SLUG_URL_CS }}" == "Never-gonna-give-you-up" ]] [[ "${{ env.ANOTHER_MAX_LENGTH_SLUG_URL_CS }}" == "Never-gonna-give-you-up" ]]
shell: bash shell: bash

View File

@@ -8,8 +8,9 @@ Produce some `slug`-ed environment variables based on the input one.
- put the variable content in lower case - put the variable content in lower case
- replace any character by `-` except `0-9`, `a-z`, `.`, and `_` - replace any character by `-` except `0-9`, `a-z`, `.`, and `_`
- remove leading and trailing `-` character - remove leading `-` character
- limit the string size to 63 characters - limit the string size to 63 characters
- remove trailing `-` character
- `<env name>_SLUG_CS` - `<env name>_SLUG_CS`
@@ -18,7 +19,6 @@ Produce some `slug`-ed environment variables based on the input one.
- `<env name>_SLUG_URL` (or `<env name>_SLUG_URL_CS`) - `<env name>_SLUG_URL` (or `<env name>_SLUG_URL_CS`)
- like `<env name>_SLUG` (or `<env name>_SLUG_CS`) with the `.`, and `_` characters also replaced by `-` - like `<env name>_SLUG` (or `<env name>_SLUG_CS`) with the `.`, and `_` characters also replaced by `-`
- will not end with `-`
## Usage ## Usage

View File

@@ -30,31 +30,26 @@ fi
slug() { slug() {
# 1st : Remove refs prefix # 1st : Remove refs prefix
# 2d : Replace unwanted characters # 2d : Replace unwanted characters
# 3d : Remove leading dashes # 3d : Remove leading hypens
# 4d : Remove trailing dashes output=$(sed -E 's#refs/[^\/]*/##;s/[^a-zA-Z0-9._-]+/-/g;s/^-*//' <<<"$1")
output=$(sed -E 's#refs/[^\/]*/##;s/[^a-zA-Z0-9._-]+/-/g;s/^-*//;s/-*$//' <<<"$1") reduce "$output"
reduce "$output" false
} }
slug_url() { slug_url() {
# 1st : Remove refs prefix # 1st : Remove refs prefix
# 2d : Replace unwanted characters # 2d : Replace unwanted characters
# 3d : Remove leading dashes # 3d : Remove leading hypens
# 4d : Remove trailing dashes output=$(sed -E 's#refs/[^\/]*/##;s/[^a-zA-Z0-9-]+/-/g;s/^-*//' <<<"$1")
output=$(sed -E 's#refs/[^\/]*/##;s/[^a-zA-Z0-9-]+/-/g;s/^-*//;s/-*$//' <<<"$1") reduce "$output"
reduce "$output" true
} }
reduce() { reduce() {
reduced_value="$1" reduced_value="$1"
remove_ending_hypen="$2"
if [ "${MAX_LENGTH}" != "nolimit" ]; then if [ "${MAX_LENGTH}" != "nolimit" ]; then
reduced_value=$(cut -c1-"${MAX_LENGTH}" <<<"$1") reduced_value=$(cut -c1-"${MAX_LENGTH}" <<<"$reduced_value")
fi fi
if [ "$remove_ending_hypen" == "true" ]; then # 1st : Remove trailing hypens
reduced_value=$(sed -E 's/-*$//' <<<"$reduced_value") sed -E 's/-*$//' <<<"$reduced_value"
fi
echo "$reduced_value"
} }
SLUG_VALUE=$(slug "$VALUE") SLUG_VALUE=$(slug "$VALUE")
@@ -62,11 +57,21 @@ SLUG_CS_VALUE=$(slug "$CS_VALUE")
SLUG_URL_VALUE=$(slug_url "$VALUE") SLUG_URL_VALUE=$(slug_url "$VALUE")
SLUG_URL_CS_VALUE=$(slug_url "$CS_VALUE") SLUG_URL_CS_VALUE=$(slug_url "$CS_VALUE")
echo "::set-output name=value::${CS_VALUE}" if [ -f "$GITHUB_OUTPUT" ]; then
echo "::set-output name=slug::${SLUG_VALUE}" {
echo "::set-output name=slug-cs::${SLUG_CS_VALUE}" echo "value=${CS_VALUE}"
echo "::set-output name=slug-url::${SLUG_URL_VALUE}" echo "slug=${SLUG_VALUE}"
echo "::set-output name=slug-url-cs::${SLUG_URL_CS_VALUE}" echo "slug-cs=${SLUG_CS_VALUE}"
echo "slug-url=${SLUG_URL_VALUE}"
echo "slug-url-cs=${SLUG_URL_CS_VALUE}"
} >> "$GITHUB_OUTPUT"
else
echo "::set-output name=value::${CS_VALUE}"
echo "::set-output name=slug::${SLUG_VALUE}"
echo "::set-output name=slug-cs::${SLUG_CS_VALUE}"
echo "::set-output name=slug-url::${SLUG_URL_VALUE}"
echo "::set-output name=slug-url-cs::${SLUG_URL_CS_VALUE}"
fi
if [ "${INPUT_PUBLISH_ENV}" == "true" ]; then if [ "${INPUT_PUBLISH_ENV}" == "true" ]; then
{ {