mirror of
https://github.com/rlespinasse/slugify-value.git
synced 2026-06-13 01:51:24 +00:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4e258f56ef | ||
|
|
930d4521cc | ||
|
|
cb3e46ca61 | ||
|
|
cb5f2aad22 | ||
|
|
1ce1e1b126 |
20
.github/workflows/slugify-value.yaml
vendored
20
.github/workflows/slugify-value.yaml
vendored
@@ -75,12 +75,12 @@ 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" ]]
|
||||||
[[ "${{ 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
|
||||||
@@ -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" ]]
|
||||||
|
|||||||
60
README.md
60
README.md
@@ -18,6 +18,7 @@ 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
|
||||||
|
|
||||||
@@ -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`.
|
|
||||||
|
|||||||
@@ -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)"
|
||||||
|
|||||||
16
slugify.sh
16
slugify.sh
@@ -33,7 +33,7 @@ slug() {
|
|||||||
# 3d : Remove leading dashes
|
# 3d : Remove leading dashes
|
||||||
# 4d : Remove trailing dashes
|
# 4d : Remove trailing dashes
|
||||||
output=$(sed -E 's#refs/[^\/]*/##;s/[^a-zA-Z0-9._-]+/-/g;s/^-*//;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() {
|
||||||
@@ -42,15 +42,19 @@ slug_url() {
|
|||||||
# 3d : Remove leading dashes
|
# 3d : Remove leading dashes
|
||||||
# 4d : Remove trailing dashes
|
# 4d : Remove trailing dashes
|
||||||
output=$(sed -E 's#refs/[^\/]*/##;s/[^a-zA-Z0-9-]+/-/g;s/^-*//;s/-*$//' <<<"$1")
|
output=$(sed -E 's#refs/[^\/]*/##;s/[^a-zA-Z0-9-]+/-/g;s/^-*//;s/-*$//' <<<"$1")
|
||||||
reduce "$output"
|
reduce "$output" true
|
||||||
}
|
}
|
||||||
|
|
||||||
reduce() {
|
reduce() {
|
||||||
if [ "${MAX_LENGTH}" == "nolimit" ]; then
|
reduced_value="$1"
|
||||||
echo "$1"
|
remove_ending_hypen="$2"
|
||||||
else
|
if [ "${MAX_LENGTH}" != "nolimit" ]; then
|
||||||
cut -c1-"${MAX_LENGTH}" <<<"$1"
|
reduced_value=$(cut -c1-"${MAX_LENGTH}" <<<"$1")
|
||||||
fi
|
fi
|
||||||
|
if [ "$remove_ending_hypen" == "true" ]; then
|
||||||
|
reduced_value=$(sed -E 's/-*$//' <<<"$reduced_value")
|
||||||
|
fi
|
||||||
|
echo "$reduced_value"
|
||||||
}
|
}
|
||||||
|
|
||||||
SLUG_VALUE=$(slug "$VALUE")
|
SLUG_VALUE=$(slug "$VALUE")
|
||||||
|
|||||||
Reference in New Issue
Block a user