Home

Awesome

GitHub Slug action

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

Table of Contents

Overview

SLUG on a variable will

<details> <summary>Others <b>Slug-ish</b> commands are available</summary> <p>

Additional enhanced environment variables can be compute to help you around GitHub environment variables.

</p> </details>

Use this action

Add this in your workflow

- name: Inject slug/short variables
  uses: rlespinasse/github-slug-action@v4
<details> <summary>Others configurations</summary> <p> </details>

Check for more examples (OS usage, URL use, ...)

Tip: Use Dependabot to maintain your github-slug-action version updated in your GitHub workflows.

Migration from previous versions

The short sha length is not the same as previous version.

So to reproduce previous behavior, use

- name: Inject slug/short variables
  uses: rlespinasse/github-slug-action@v4
  with:
    short-length: 8 # Same as v3 and before

Available Environment variables

Note: If you don't find what you search for, read more about available GitHub variables, and propose a new custom variable.

Enhanced variables

NOTE: All enhanced variables are available in all slug formats.

Partial variables

VariablePartial version ofDescription
GITHUB_REPOSITORY_OWNER_PARTGITHUB_REPOSITORYThe Owner part of GITHUB_REPOSITORY variable
GITHUB_REPOSITORY_NAME_PARTGITHUB_REPOSITORYThe Repository name part of GITHUB_REPOSITORY variable

Slug variables

NOTE: _CS suffix available

VariableSlug version ofDescription
GITHUB_REPOSITORY_SLUGGITHUB_REPOSITORYThe owner and repository name.
GITHUB_REPOSITORY<br>_OWNER_PART_SLUGGITHUB_REPOSITORY_OWNER_PARTThe owner name.
GITHUB_REPOSITORY<br>_NAME_PART_SLUGGITHUB_REPOSITORY_NAME_PARTThe repository name.
GITHUB_REF_SLUGGITHUB_REFThe branch or tag ref that triggered the workflow.
GITHUB_HEAD_REF_SLUGGITHUB_HEAD_REFThe branch of the head repository.<br>Only set for [pull-request][event-pull-request] event and forked repositories.
GITHUB_BASE_REF_SLUGGITHUB_BASE_REFThe branch of the base repository.<br>Only set for [pull-request][event-pull-request] event and forked repositories.
GITHUB_EVENT_REF_SLUGgithub.event.ref<br>Only set for following webhook events<ul><li>create</li><li>delete</li></ul>

Slug URL variables

NOTE: _CS suffix available

VariableSlug URL version ofDescription
GITHUB_REPOSITORY_SLUG_URLGITHUB_REPOSITORYThe owner and repository name.
GITHUB_REPOSITORY<br>_OWNER_PART_SLUG_URLGITHUB_REPOSITORY_OWNER_PARTThe owner name.
GITHUB_REPOSITORY<br>_NAME_PART_SLUG_URLGITHUB_REPOSITORY_NAME_PARTThe repository name.
GITHUB_REF_SLUG_URLGITHUB_REFThe branch or tag ref that triggered the workflow.
GITHUB_HEAD_REF_SLUG_URLGITHUB_HEAD_REFThe branch of the head repository.<br>Only set for pull-request event and forked repositories.
GITHUB_BASE_REF_SLUG_URLGITHUB_BASE_REFThe branch of the base repository.<br>Only set for pull-request event and forked repositories.
GITHUB_EVENT_REF_SLUG_URLgithub.event.ref<br>Only set for following webhook events<ul><li>create</li><li>delete</li></ul>

Short variables

VariableShort version ofDescription
GITHUB_SHA_SHORTGITHUB_SHAThe commit SHA that triggered the workflow.
GITHUB_EVENT<br>_PULL_REQUEST<br>_HEAD_SHA_SHORTgithub.event<br>.pull_request<br>.head.shaThe commit SHA on pull request that trigger workflow.<br>Only set for following webhook events<ul><li>pull_request</li><li>pull_request_review</li><li>pull_request_review_comment</li><li>pull_request_target</li></ul>

Troubleshooting

The SHORT variables doesn't have the same lengths as before

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.

One of the environment variables doesn't work as intended

Note: 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.

NOTE: If detected, the maintainers of this action will choose the best course of action depending of the impact.

Known environment variable conflicts

GITHUB_REF_NAME

The behavior is 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.

A possible workaround is to use prefix input

- name: Inject slug/short variables
  uses: rlespinasse/github-slug-action@v4
  with:
    prefix: CI_

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

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 v4 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.