Skip to content

Commit

Permalink
feat: add option to set a different slug length than 63
Browse files Browse the repository at this point in the history
  • Loading branch information
rlespinasse authored Mar 19, 2022
1 parent cd9871b commit 88f3ee8
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 9 deletions.
66 changes: 66 additions & 0 deletions .github/workflows/github-slug-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,71 @@ jobs:
[[ "${{ env.GITHUB_EVENT_PULL_REQUEST_HEAD_SHA_SHORT }}" == "${{ env.V4_GITHUB_EVENT_PULL_REQUEST_HEAD_SHA_SHORT }}" ]]
shell: bash

os-testing-slug-maxlength:
strategy:
fail-fast: false
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v3

# Test 1
- name: Using correct max length
uses: ./
with:
prefix: "CML_"
slug-maxlength: 1
- name: Using correct max length // Validate that all slug variables are equals or under the slug-maxlength
run: |
env | grep "CML_" | grep "_SLUG" | cut -d"=" -f2 | while read -r value; do [ "$(echo "$value" | wc -m)" -le 2 ] ; done
shell: bash

# Test 2
- name: Using wrong max length
id: using-wrong-max-length
uses: ./
with:
prefix: "WML_"
slug-maxlength: "wrong"
continue-on-error: true
- name: Using wrong max length // Validate that the action end with an error
run: |
[[ "$(env | grep "WML_" | grep "_SLUG" | wc -l)" -eq 0 ]]
[[ "${{ steps.using-wrong-max-length.outcome }}" == "failure" ]]
[[ "${{ steps.using-wrong-max-length.conclusion }}" == "success" ]]
shell: bash

# Test 3
- name: Using empty max length
id: using-empty-max-length
uses: ./
with:
prefix: "EML_"
slug-maxlength: ""
continue-on-error: true
- name: Using empty max length // Validate that the action end with an error
run: |
[[ "$(env | grep "EML_" | grep "_SLUG" | wc -l)" -eq 0 ]]
[[ "${{ steps.using-empty-max-length.outcome }}" == "failure" ]]
[[ "${{ steps.using-empty-max-length.conclusion }}" == "success" ]]
shell: bash

# Test 4
- name: Using no limit on max length
id: using-nolimit-max-length
uses: ./
with:
prefix: "NLML_"
slug-maxlength: "nolimit"
- name: Using no limit on length // Validate that the action end with an error
run: |
[[ "$(env | grep "NLML_" | grep "_SLUG" | wc -l)" -gt 0 ]]
[[ "${{ steps.using-nolimit-max-length.outcome }}" == "success" ]]
[[ "${{ steps.using-nolimit-max-length.conclusion }}" == "success" ]]
shell: bash

os-testing-without-checkout:
strategy:
fail-fast: false
Expand Down Expand Up @@ -144,6 +209,7 @@ jobs:
group: release-${{ github.ref }}-${{ github.event_name }}
needs:
- os-testing
- os-testing-slug-maxlength
- os-testing-without-checkout
steps:
- name: Checkout
Expand Down
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ Or with a prefix
prefix: CI_
```
Or with another max length for slug values
```yaml
- name: Inject slug/short variables
uses: rlespinasse/github-slug-action@v4
with:
slug-maxlength: 80 # use 'nolimit' to remove use of a max length
```
Check for more [examples][examples] (OS usage, URL use, ...)
**Tip:** Use [Dependabot][dependabot] to maintain your `github-slug-action` version updated in your GitHub workflows.
Expand Down Expand Up @@ -168,7 +177,7 @@ Download action repository 'rlespinasse/github-slug-action@GIT_REFERENCE'
##[error]An action could not be found at the URI 'https://api.github.com/repos/rlespinasse/github-slug-action/tarball/GIT_REFERENCE'
```

If the `GIT_REFERENCE` value is
If the `GIT_REFERENCE` value is

- `v4.x` or after, the branch don't exists anymore following the [end-of-life for a branch](SECURITY.md#end-of-life-of-a-branch) security process.
- `master`, the branch don't exists anymore, read more about it on the corresponding issue ([EOL issue][issue-15])
Expand Down
33 changes: 25 additions & 8 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,59 +9,76 @@ inputs:
description: "Value to prepend to each generated variable"
default: ""
required: false
slug-maxlength:
description: "Max length of the slugified values"
default: "63"
required: true
runs:
using: "composite"
steps:
- uses: rlespinasse/[email protected]
- run: $GITHUB_ACTION_PATH/preflight.sh
shell: bash
env:
INPUT_SLUG_MAXLENGTH: ${{ inputs.slug-maxlength }}

- uses: rlespinasse/[email protected]
with:
key: GITHUB_REPOSITORY
value: ${{ github.repository }}
prefix: ${{ inputs.prefix }}
- uses: rlespinasse/[email protected]
slug-maxlength: ${{ inputs.slug-maxlength }}
- uses: rlespinasse/[email protected]
with:
key: GITHUB_REF
prefix: ${{ inputs.prefix }}
- uses: rlespinasse/[email protected]
slug-maxlength: ${{ inputs.slug-maxlength }}
- uses: rlespinasse/[email protected]
with:
key: GITHUB_HEAD_REF
prefix: ${{ inputs.prefix }}
- uses: rlespinasse/[email protected]
slug-maxlength: ${{ inputs.slug-maxlength }}
- uses: rlespinasse/[email protected]
with:
key: GITHUB_BASE_REF
prefix: ${{ inputs.prefix }}
slug-maxlength: ${{ inputs.slug-maxlength }}

# Specific values
- uses: rlespinasse/slugify-value@v1.1.0
- uses: rlespinasse/slugify-value@v1.2.0
with:
key: GITHUB_EVENT_REF
value: ${{ github.event.ref }}
prefix: ${{ inputs.prefix }}
slug-maxlength: ${{ inputs.slug-maxlength }}

# Calculated values
- id: get-github-ref-name
run: echo "::set-output name=github-ref-name::$(echo "${{ github.head_ref || github.ref }}" | cut -d/ -f3)"
shell: bash
- uses: rlespinasse/slugify-value@v1.1.0
- uses: rlespinasse/slugify-value@v1.2.0
with:
key: GITHUB_REF_NAME
value: ${{ steps.get-github-ref-name.outputs.github-ref-name }}
prefix: ${{ inputs.prefix }}
slug-maxlength: ${{ inputs.slug-maxlength }}
- id: get-github-repository-owner-part
run: echo "::set-output name=github-repository-owner-part::$(echo $GITHUB_REPOSITORY | cut -d/ -f1)"
shell: bash
- uses: rlespinasse/slugify-value@v1.1.0
- uses: rlespinasse/slugify-value@v1.2.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: echo "::set-output name=github-repository-name-part::$(echo $GITHUB_REPOSITORY | cut -d/ -f2)"
shell: bash
- uses: rlespinasse/slugify-value@v1.1.0
- uses: rlespinasse/slugify-value@v1.2.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 }}

# Short
- uses: rlespinasse/[email protected]
Expand Down
9 changes: 9 additions & 0 deletions preflight.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

if [ -z "${INPUT_SLUG_MAXLENGTH}" ]; then
echo "::error ::slug-maxlength cannot be empty"
exit 1
elif [ "${INPUT_SLUG_MAXLENGTH}" != "nolimit" ] && [ ! "${INPUT_SLUG_MAXLENGTH}" -eq "${INPUT_SLUG_MAXLENGTH}" ] 2>/dev/null; then
echo "::error ::slug-maxlength must be a number or equals to 'nolimit'"
exit 1
fi

0 comments on commit 88f3ee8

Please sign in to comment.