GitHub Action
GitHub Slug Action
This GitHub Action will expose the slug/short values of some GitHub environment variables inside your GitHub workflow.
- GitHub Slug action
SLUG
on a variable will
- put the variable content in lower case
- replace any character by
-
except0-9
,a-z
,.
, and_
- remove leading
-
characters - limit the string size to 63 characters
- remove trailing
-
characters
Others Slug-ish commands are available
-
SLUG_URL
on a variable to have aslug
variable compliant to be used in an URL- Like
SLUG
but.
is also replaced by-
- Like
-
SHORT
on a variable will limit the string size to 8 characters- Useful for sha value
-
<KEY>_PART
on a variable will give a part of a variable defined by a key- Like
GITHUB_REPOSITORY_OWNER_PART
for the owner part ofGITHUB_REPOSITORY
- Like
-
<VAR>_CS
on others variables to keep the value case-sensitive- Like
GITHUB_REF_SLUG_CS
- Like
Additional enhanced environment variables can be compute to help you around GitHub environment variables.
Add this in your workflow
- name: Inject slug/short variables
uses: rlespinasse/[email protected]
Check for more examples (OS usage, URL use, ...)
Tip: Use Dependabot to maintain your github-slug-action
version updated in your GitHub workflows.
Note: If you don't find what you search for, read more about available GitHub
variables, and propose a new custom variable.
GITHUB_REF_NAME
will contains the reference name (branch or tag)- based on
GITHUB_HEAD_REF
in apull-request*
event context, - based on
GITHUB_REF
in others event context.
- based on
NOTE: All enhanced variables are available in all slug formats.
Variable | Partial version of | Description |
---|---|---|
GITHUB_REPOSITORY_OWNER_PART | GITHUB_REPOSITORY | The Owner part of GITHUB_REPOSITORY variable |
GITHUB_REPOSITORY_NAME_PART | GITHUB_REPOSITORY | The Repository name part of GITHUB_REPOSITORY variable |
NOTE: _CS
suffix available
Variable | Slug version of | Description |
---|---|---|
GITHUB_REPOSITORY_SLUG | GITHUB_REPOSITORY | The owner and repository name. |
GITHUB_REPOSITORY _OWNER_PART_SLUG |
GITHUB_REPOSITORY_OWNER_PART | The owner name. |
GITHUB_REPOSITORY _NAME_PART_SLUG |
GITHUB_REPOSITORY_NAME_PART | The repository name. |
GITHUB_REF_SLUG | GITHUB_REF | The branch or tag ref that triggered the workflow. |
GITHUB_HEAD_REF_SLUG | GITHUB_HEAD_REF | The branch of the head repository. Only set for [pull-request][event-pull-request] event and forked repositories. |
GITHUB_BASE_REF_SLUG | GITHUB_BASE_REF | The branch of the base repository. Only set for [pull-request][event-pull-request] event and forked repositories. |
GITHUB_EVENT_REF_SLUG | github.event.ref | Only set for following webhook events
|
NOTE: _CS
suffix available
Variable | Slug URL version of | Description |
---|---|---|
GITHUB_REPOSITORY_SLUG_URL | GITHUB_REPOSITORY | The owner and repository name. |
GITHUB_REPOSITORY _OWNER_PART_SLUG_URL |
GITHUB_REPOSITORY_OWNER_PART | The owner name. |
GITHUB_REPOSITORY _NAME_PART_SLUG_URL |
GITHUB_REPOSITORY_NAME_PART | The repository name. |
GITHUB_REF_SLUG_URL | GITHUB_REF | The branch or tag ref that triggered the workflow. |
GITHUB_HEAD_REF_SLUG_URL | GITHUB_HEAD_REF | The branch of the head repository. Only set for pull-request event and forked repositories. |
GITHUB_BASE_REF_SLUG_URL | GITHUB_BASE_REF | The branch of the base repository. Only set for pull-request event and forked repositories. |
GITHUB_EVENT_REF_SLUG_URL | github.event.ref | Only set for following webhook events
|
Variable | Short version of | Description |
---|---|---|
GITHUB_SHA_SHORT | GITHUB_SHA | The commit SHA that triggered the workflow. |
GITHUB_EVENT _PULL_REQUEST _HEAD_SHA_SHORT |
github.event .pull_request .head.sha |
The commit SHA on pull request that trigger workflow. Only set for following webhook events
|
Follow Developers guide
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.
${{ env.GITHUB_AWESOME_VARIABLE }}
will serve the behavior of this action,$GITHUB_AWESOME_VARIABLE
will serve the behavior of GitHub Action.
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.
The behavior is the same as the GitHub one except on pull_request*
workflows (Ready the full story).
${{ env.GITHUB_REF_NAME }}
will serve the behavior of this action,$GITHUB_REF_NAME
will serve the behavior of GitHub Action.
On pull_request*
workflows, the content will be <PR-number>/merge
instead of the branch name.
A possible workaround is to use prefix
input available in v4
version
- 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.
If your workflow fail on the Set up job
task with this kind of log :
Download action repository 'rlespinasse/github-slug-action@master'
##[error]An action could not be found at the URI 'https://api.github.com/repos/rlespinasse/github-slug-action/tarball/master'
The master branch doesn't exists anymore.
The master branch EOL has been set to 2020-10-25 after a 6-month deprecation period (more information on the EOL issue)
Please, use the current branch v3.x
or a version tag (see releases pages) in order to fix your workflow.
- Mettre en place une CI/CD Angular avec GitHub Actions & Netlify (in french 🇫🇷)
- Github Actions : enfin des pipelines accessibles aux développeurs (in french 🇫🇷)
- Action spotlight by Michael Heap
- The next one is you. Don't hesitate to add youself to this list.