From 88f3ee8f6f5d1955de92f1fe2fdb301fd40207c6 Mon Sep 17 00:00:00 2001 From: Romain Lespinasse Date: Sat, 19 Mar 2022 22:50:08 +0100 Subject: [PATCH] feat: add option to set a different slug length than 63 --- .github/workflows/github-slug-action.yml | 66 ++++++++++++++++++++++++ README.md | 11 +++- action.yml | 33 +++++++++--- preflight.sh | 9 ++++ 4 files changed, 110 insertions(+), 9 deletions(-) create mode 100755 preflight.sh diff --git a/.github/workflows/github-slug-action.yml b/.github/workflows/github-slug-action.yml index 9350939..600fdd3 100644 --- a/.github/workflows/github-slug-action.yml +++ b/.github/workflows/github-slug-action.yml @@ -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 @@ -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 diff --git a/README.md b/README.md index 4866239..159e5ab 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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]) diff --git a/action.yml b/action.yml index 5f8008a..f3c2c7e 100644 --- a/action.yml +++ b/action.yml @@ -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/slugify-value@v1.1.0 + - run: $GITHUB_ACTION_PATH/preflight.sh + shell: bash + env: + INPUT_SLUG_MAXLENGTH: ${{ inputs.slug-maxlength }} + + - uses: rlespinasse/slugify-value@v1.2.0 with: key: GITHUB_REPOSITORY value: ${{ github.repository }} prefix: ${{ inputs.prefix }} - - uses: rlespinasse/slugify-value@v1.1.0 + slug-maxlength: ${{ inputs.slug-maxlength }} + - uses: rlespinasse/slugify-value@v1.2.0 with: key: GITHUB_REF prefix: ${{ inputs.prefix }} - - uses: rlespinasse/slugify-value@v1.1.0 + slug-maxlength: ${{ inputs.slug-maxlength }} + - uses: rlespinasse/slugify-value@v1.2.0 with: key: GITHUB_HEAD_REF prefix: ${{ inputs.prefix }} - - uses: rlespinasse/slugify-value@v1.1.0 + slug-maxlength: ${{ inputs.slug-maxlength }} + - uses: rlespinasse/slugify-value@v1.2.0 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/shortify-git-revision@v1.4.0 diff --git a/preflight.sh b/preflight.sh new file mode 100755 index 0000000..bd06e9c --- /dev/null +++ b/preflight.sh @@ -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