GitHub Action
GitHub slug
GitHub slug action
GitHub Action to expose slug values of branch/tag/version inside your GitHub workflow.
Overview
Slug on a variable will:
- Put the variable content in lower case
- Replace special characters like
$
or%
withdollar
andpercent
respectively - Replace any character by
-
except0-9
,a-z
, and-
- Remove leading, trailing, and duplicated
-
character
Usage
Add this in your workflow:
- uses: gacts/github-slug@v1
id: slug
with:
# replace value in "to-slug" this on your choice
to-slug: Hello ${{ github.actor }}! How are you?
And in subsequent steps you will be able to use the following variables:
Description | How to use in your workflow | Examples for branch /tag workflows |
---|---|---|
A slugged version of "to-slug" input | ${{ steps.slug.outputs.slug }} |
hello-username-how-are-you |
The workflow was triggered on a branch | ${{ steps.slug.outputs.is-branch }} |
true /false |
The workflow was triggered on a tag | ${{ steps.slug.outputs.is-tag }} |
false /true |
Current branch name | ${{ steps.slug.outputs.branch-name }} |
fix/Foo_bar /<empty-value> |
A slugged version of branch-name |
${{ steps.slug.outputs.branch-name-slug }} |
fix-foo-bar /<empty-value> |
Current tag name | ${{ steps.slug.outputs.tag-name }} |
<empty-value> /v1.2-rc1_Lorem |
A slugged version of tag-name |
${{ steps.slug.outputs.tag-name-slug }} |
<empty-value> /v1-2-rc1-lorem |
The commit SHA hash that triggered the workflow | ${{ steps.slug.outputs.commit-hash }} |
ffac537e6cbbf934b08745a378932722df287a53 |
Short (7 first characters) commit SHA hash | ${{ steps.slug.outputs.commit-hash-short }} |
ffac537 |
Cleared and slugged version value (prefix v/ver/version[._-] will be rejected) |
${{ steps.slug.outputs.version }} |
fix-foo-bar /1.2-rc1-lorem |
Major version | ${{ steps.slug.outputs.version-major }} |
0 /1 |
Minor version | ${{ steps.slug.outputs.version-minor }} |
0 /2 |
Patch version | ${{ steps.slug.outputs.version-patch }} |
0 /0 |
Semantic version value | ${{ steps.slug.outputs.version-semantic }} |
0.0.0-fix-foo-bar /1.2.0-rc1-lorem |
Tip: Use Dependabot to maintain your
gacts/github-slug
version updated in your GitHub workflows.
Examples
On the branch:
On the tag:
Releasing
New versions releasing scenario:
- Make required changes in the changelog file
- Build the action distribution (
make build
oryarn build
) - Commit and push changes (including
dist
directory changes - this is important) into themaster
branch - Publish new release using repo releases page (git tag should follow
vX.Y.Z
format)
Major and minor git tags (v1
and v1.2
if you publish v1.2.Z
release) will be updated automatically.
Support
If you will find any action errors - please, make an issue in the current repository.
License
This is open-sourced software licensed under the MIT License.