7 Commits

Author SHA1 Message Date
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
Romain Lespinasse
4e258f56ef fix(slug_url): remove ending hypen if any 2022-06-15 16:06:49 +02:00
rlespinasse
930d4521cc Revert "fix(slug_url): remove ending hypen if any"
This reverts commit cb3e46ca61.
2022-06-15 15:51:30 +02:00
Romain Lespinasse
cb3e46ca61 fix(slug_url): remove ending hypen if any 2022-06-15 15:48:10 +02:00
rlespinasse
cb5f2aad22 ci: fix typo 2022-04-17 20:06:56 +02:00
rlespinasse
1ce1e1b126 docs: improve sections 2022-04-17 19:48:08 +02:00
4 changed files with 60 additions and 53 deletions

View File

@@ -75,7 +75,7 @@ jobs:
with: with:
key: ANOTHER_MAX_LENGTH key: ANOTHER_MAX_LENGTH
value: "Never gonna give you up Never gonna let you down" value: "Never gonna give you up Never gonna let you down"
slug-maxlength: 23 slug-maxlength: 24
- 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" ]]
@@ -146,17 +146,17 @@ jobs:
id: slugify-key-without-env-publication id: slugify-key-without-env-publication
uses: ./ uses: ./
with: with:
key: KEY_WITHTOUT_ENV_PUBLICATION key: KEY_WITHOUT_ENV_PUBLICATION
publish-env: false publish-env: false
env: env:
KEY_WITHTOUT_ENV_PUBLICATION: "Never gonna give you up" KEY_WITHOUT_ENV_PUBLICATION: "Never gonna give you up"
- name: Validate // Slugify key without env publication - name: Validate // Slugify key without env publication
run: | run: |
[[ -z "${{ env.KEY_WITHTOUT_ENV_PUBLICATION }}" ]] [[ -z "${{ env.KEY_WITHOUT_ENV_PUBLICATION }}" ]]
[[ -z "${{ env.KEY_WITHTOUT_ENV_PUBLICATION_SLUG }}" ]] [[ -z "${{ env.KEY_WITHOUT_ENV_PUBLICATION_SLUG }}" ]]
[[ -z "${{ env.KEY_WITHTOUT_ENV_PUBLICATION_SLUG_CS }}" ]] [[ -z "${{ env.KEY_WITHOUT_ENV_PUBLICATION_SLUG_CS }}" ]]
[[ -z "${{ env.KEY_WITHTOUT_ENV_PUBLICATION_SLUG_URL }}" ]] [[ -z "${{ env.KEY_WITHOUT_ENV_PUBLICATION_SLUG_URL }}" ]]
[[ -z "${{ env.KEY_WITHTOUT_ENV_PUBLICATION_SLUG_URL_CS }}" ]] [[ -z "${{ env.KEY_WITHOUT_ENV_PUBLICATION_SLUG_URL_CS }}" ]]
[[ "${{ steps.slugify-key-without-env-publication.outputs.value }}" == "Never gonna give you up" ]] [[ "${{ steps.slugify-key-without-env-publication.outputs.value }}" == "Never gonna give you up" ]]
[[ "${{ steps.slugify-key-without-env-publication.outputs.slug }}" == "never-gonna-give-you-up" ]] [[ "${{ steps.slugify-key-without-env-publication.outputs.slug }}" == "never-gonna-give-you-up" ]]
[[ "${{ steps.slugify-key-without-env-publication.outputs.slug-cs }}" == "Never-gonna-give-you-up" ]] [[ "${{ steps.slugify-key-without-env-publication.outputs.slug-cs }}" == "Never-gonna-give-you-up" ]]

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`
@@ -92,34 +93,39 @@ Produce some `slug`-ed environment variables based on the input one.
Will produce SLUG variables without limiting the output length Will produce SLUG variables without limiting the output length
- Slugify a value without publishing the environment variables
```yaml
- uses: rlespinasse/slugify-value@v1.x
with:
key: KEY_NAME
value: value_to_slugify
```
Will **not** make available
- `KEY_NAME`
- `KEY_NAME_SLUG`
- `KEY_NAME_SLUG_CS`
- `KEY_NAME_SLUG_URL`
- `KEY_NAME_SLUG_URL_CS`
## Inputs ## Inputs
### `key` | Input | Description | Mandatory | Default |
| -------------- | ----------------------------------------------------------------------------------------------------- | --------- | ------- |
| key | Environment variable that will hold the value and serve as prefix to slugified value | Yes | |
| value | The value to slugify. If not set the value will be taken from the `key` input as environment variable | No | |
| prefix | The value will be prepend to each generated variable | No | |
| slug-maxlength | The value is a number or `nolimit` to reflect the length of the slug outputs | No | 63 |
| publish-env | In addition of the action output, the slug values are publish as environment variables | No | true |
Environment variable that will hold the value and serve as prefix to slugified value. ## Outputs
This input is _Mandatory_. | Output | Description |
| ----------- | ------------------------------- |
### `value` | value | The value to be slugify |
| slug | Value Slug |
The value to slugify. If not set the value will be taken from the `key` input as environment variable. | slug-cs | Value Slug (Case-sensitive) |
| slug-url | Value Slug URL |
This input is _Optional_. | slug-url-cs | Value Slug URL (Case-sensitive) |
### `prefix`
The value will be prepend to each generated variable.
This input is _Optional_.
### `slug-maxlength`
The value is a number or `nolimit` to reflect the length of the slug outputs.
This input is _Optional_. The default value is `63`.
### `publish-env`
In addition of the action output, the slug values are publish as environment variables.
This input is _Optional_. The default value is `true`.

View File

@@ -25,10 +25,10 @@ inputs:
required: true required: true
outputs: outputs:
value: value:
description: "Value" description: "The value to be slugify"
value: ${{ steps.slugify.outputs.value }} value: ${{ steps.slugify.outputs.value }}
slug: slug:
description: "Value slug" description: "Value Slug"
value: ${{ steps.slugify.outputs.slug }} value: ${{ steps.slugify.outputs.slug }}
slug-cs: slug-cs:
description: "Value Slug (Case-sensitive)" description: "Value Slug (Case-sensitive)"

View File

@@ -30,27 +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"
} }
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"
} }
reduce() { reduce() {
if [ "${MAX_LENGTH}" == "nolimit" ]; then reduced_value="$1"
echo "$1" if [ "${MAX_LENGTH}" != "nolimit" ]; then
else reduced_value=$(cut -c1-"${MAX_LENGTH}" <<<"$reduced_value")
cut -c1-"${MAX_LENGTH}" <<<"$1"
fi fi
# 1st : Remove trailing hypens
sed -E 's/-*$//' <<<"$reduced_value"
} }
SLUG_VALUE=$(slug "$VALUE") SLUG_VALUE=$(slug "$VALUE")
@@ -58,11 +57,13 @@ 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}" {
echo "::set-output name=slug::${SLUG_VALUE}" echo "value=${CS_VALUE}"
echo "::set-output name=slug-cs::${SLUG_CS_VALUE}" echo "slug=${SLUG_VALUE}"
echo "::set-output name=slug-url::${SLUG_URL_VALUE}" echo "slug-cs=${SLUG_CS_VALUE}"
echo "::set-output name=slug-url-cs::${SLUG_URL_CS_VALUE}" echo "slug-url=${SLUG_URL_VALUE}"
echo "slug-url-cs=${SLUG_URL_CS_VALUE}"
} >> $GITHUB_OUTPUT
if [ "${INPUT_PUBLISH_ENV}" == "true" ]; then if [ "${INPUT_PUBLISH_ENV}" == "true" ]; then
{ {