Home

Awesome

GitHub Slug action

This GitHub Action will expose the slug/short values of some GitHub environment variables inside your GitHub workflow.

Overview

SLUG on a variable will

Others Slug-ish variables are available

Installation

Add this step to your workflow

steps:
  - name: Inject enhanced GitHub environment variables
    uses: rlespinasse/github-slug-action@v5

[!CAUTION] Use Dependabot to maintain your github-slug-action version updated in your GitHub workflows.

Configuration Options

[!TIP] Check for more examples (OS usage, URL use, ...)

With a prefix

steps:
  - name: Inject enhanced GitHub environment variables
    uses: rlespinasse/github-slug-action@v5
    with:
      prefix: CI_

With another max length for slug values

steps:
  - name: Inject enhanced GitHub environment variables
    uses: rlespinasse/github-slug-action@v5
    with:
      slug-maxlength: 80 # Use 'nolimit' to remove use of a max length (Default to 63)

With another length for short values

steps:
  - name: Inject enhanced GitHub environment variables
    uses: rlespinasse/github-slug-action@v5
    with:
      short-length: 7 # By default it's up to Git to decide, use 8 to have the v3.x behavior

[!WARNING] If you leave it empty, you need to checkout the source first in order to let Git decide the size by itself.

Available Environment variables

[!TIP] If you don't find what you search for

Enhanced variables

[!NOTE] All enhanced variables are available in all slug formats.

Partial variables

VariableDescription
GITHUB_REPOSITORY_OWNER_PARTThe Owner part of GITHUB_REPOSITORY variable
GITHUB_REPOSITORY_NAME_PARTThe Repository name part of GITHUB_REPOSITORY variable

Slug variables

[!TIP] Available in standard and case-sensitive (_CS) versions.

VariableDescription
GITHUB_REPOSITORY_SLUGThe owner and repository name.
GITHUB_REPOSITORY_OWNER_PART_SLUGThe owner name.
GITHUB_REPOSITORY_NAME_PART_SLUGThe repository name.
GITHUB_REF_SLUGThe branch or tag ref that triggered the workflow.
GITHUB_REF_NAME_SLUGThis value matches the branch or tag name shown on GitHub.
GITHUB_HEAD_REF_SLUGThe branch of the head repository.
GITHUB_BASE_REF_SLUGThe branch of the base repository.
GITHUB_EVENT_REF_SLUGThe Git reference resource associated to triggered webhook.

URL-Safe Slug variables

Same as slug variables but URL-compliant

[!TIP] Available in standard and case-sensitive (_CS) versions.

VariableDescription
GITHUB_REPOSITORY_SLUG_URLThe owner and repository name.
GITHUB_REPOSITORY_OWNER_PART_SLUG_URLThe owner name.
GITHUB_REPOSITORY_NAME_PART_SLUG_URLThe repository name.
GITHUB_REF_SLUG_URLThe branch or tag ref that triggered the workflow.
GITHUB_REF_NAME_SLUG_URLThis value matches the branch or tag name shown on GitHub.
GITHUB_HEAD_REF_SLUG_URLThe branch of the head repository.
GITHUB_BASE_REF_SLUG_URLThe branch of the base repository.
GITHUB_EVENT_REF_SLUG_URLThe Git reference resource associated to triggered webhook.

Short variables

VariableDescription
GITHUB_SHA_SHORTThe commit SHA that triggered the workflow.
GITHUB_EVENT_PULL_REQUEST_HEAD_SHA_SHORTThe commit SHA on pull request that trigger workflow.

Migration from previous versions

v4 to v5

The GITHUB_REF_NAME SLUG/SLUG_URL variables doesn't work the same way as before

[!TIP] If you use v5 or related versions, you need to use GITHUB_REF_POINT instead of GITHUB_REF_NAME to get the behavior of the v4 action.

Before v5, the behavior was the same as the GitHub one except on pull_request* workflows (Ready the full story).

On pull_request* workflows, the content will be <PR-number>/merge instead of the branch name. So you need to use GITHUB_REF_POINT instead

steps:
  - name: Inject enhanced GitHub environment variables
    uses: rlespinasse/github-slug-action@v5
  - run: |
      echo "Branch Name: ${GITHUB_REF_POINT}"
    shell: bash

Then ${{ env.GITHUB_REF_POINT }}, and $GITHUB_REF_POINT will serve the behavior of this action. And ${{ env.GITHUB_REF_NAME }}, and $GITHUB_REF_NAME will serve the behavior of GitHub Action.

v3 to v4

Since v4, it's Git who manage the short variables by using git rev-parse behaviour. The length of a short sha depends of the size of our repository and can differ over time.

To manage that moving length, you can use short-length input

[!WARNING] The minimum length is 4, the default is the effective value of the core.abbrev configuration variable.

So to reproduce previous behavior, use

steps:
  - name: Inject enhanced GitHub environment variables
    uses: rlespinasse/github-slug-action@v5
    with:
      short-length: 8 # Same as v3 and before

Troubleshooting

One of the environment variables doesn't work as intended

[!WARNING] When you set a custom environment variable, you cannot use any of the default environment variable names. For a complete list of these, see Default environment variables. If you attempt to override the value of one of these default environment variables, the assignment is ignored.

If a variable start to be used as default environment variable, the environment variable may have a different behavior than the expected one.

If this append, the ${{ env.GITHUB_AWESOME_VARIABLE }} and $GITHUB_AWESOME_VARIABLE expression will not works in the same way.

Otherwise the two expression will serve the behavior of this action. This will not occurs if you use the prefix input to avoid the issue.

[!IMPORTANT] If detected, the maintainers of this action will choose the best course of action depending of the impact.

An action could not be found at the URI

If your workflow fail on the Set up job task with this kind of log

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

Please, use the current major tag v5 or a version tag (see releases pages) in order to fix your workflow.

Thanks for talking about us

In English :gb:

In French :fr:

In Chinese :cn:

The next one is you. Don't hesitate to add youself to one of these lists.