Code Monkey home page Code Monkey logo

action-github-slug's Introduction

GitHub Slug action

Actions Status GitHub Super-Linter Public workflows that use this action. Licence

This GitHub Action will expose the slug value of all GitHub environment variables inside your GitHub workflow.

Slug a variable will

  • put the variable content in lower case
  • replace any character by - except 0-9, a-z, and .
  • remove leading and trailing - character
  • limit the string size to 63 characters

Others Slug-ish commands are available:

  • Slug URL a variable will be like the slug variable but the . character will also be replaced by -
  • Short SHA a variable will limit the string size to 8 characters

Exposed GitHub environment variables

- name: Inject slug/short variables
  uses: rlespinasse/[email protected]

- name: Print slug/short variables
  run: |
    echo "Slug variables"
    echo "   ref        : ${{ env.GITHUB_REF_SLUG }}"
    echo "   head ref   : ${{ env.GITHUB_HEAD_REF_SLUG }}"
    echo "   base ref   : ${{ env.GITHUB_BASE_REF_SLUG }}"
    echo "   event ref  : ${{ env.GITHUB_EVENT_REF_SLUG }}"
    echo "   repository : ${{ env.GITHUB_REPOSITORY_SLUG }}"
    echo "Slug URL variables"
    echo "   ref        : ${{ env.GITHUB_REF_SLUG_URL }}"
    echo "   head ref   : ${{ env.GITHUB_HEAD_REF_SLUG_URL }}"
    echo "   base ref   : ${{ env.GITHUB_BASE_REF_SLUG_URL }}"
    echo "   event ref  : ${{ env.GITHUB_EVENT_REF_SLUG_URL }}"
    echo "   repository : ${{ env.GITHUB_REPOSITORY_SLUG_URL }}"
    echo "Short SHA variables"
    echo "   sha        : ${{ env.GITHUB_SHA_SHORT }}"

Read default environment variables page for more information.

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

GITHUB_REF_SLUG / GITHUB_REF_SLUG_URL

Slug the environment variable GITHUB_REF

The branch or tag ref that triggered the workflow. If neither a branch or tag is available for the event type, the variable will not exist.

GITHUB_REF GITHUB_REF_SLUG GITHUB_REF_SLUG_URL
refs/heads/master master master
refs/heads/feat/new_feature feat-new-feature feat-new-feature
refs/tags/v1.0.0 v1.0.0 v1-0-0
refs/tags/[email protected] product-1.0.0-rc.2 product-1-0-0-rc-2
refs/heads/New_Awesome_Product new-awesome-product new-awesome-product

NOTE : GITHUB_REF_SLUG_URL is design to be used as subdomain in an URL.

Additional variables (only set for forked repositories) :

  • GITHUB_HEAD_REF_SLUG/GITHUB_HEAD_REF_SLUG_URL, The branch of the head repository GITHUB_HEAD_REF
  • GITHUB_BASE_REF_SLUG/GITHUB_BASE_REF_SLUG_URL, The branch of the base repository GITHUB_BASE_REF

Additional variables (only set for create, and delete webhook events with ref data) :

  • GITHUB_EVENT_REF_SLUG/GITHUB_EVENT_REF_SLUG_URL, The git reference resource associated to the webhook.

GITHUB_REPOSITORY_SLUG / GITHUB_REPOSITORY_SLUG_URL

Slug the environment variable GITHUB_REPOSITORY

The owner and repository name.

GITHUB_REPOSITORY GITHUB_REPOSITORY_SLUG GITHUB_REPOSITORY_SLUG_URL
octocat/Hello-World octocat-hello-world octocat-hello-world
rlespinasse/Hello-World.go rlespinasse-hello-world.go rlespinasse-hello-world-go

NOTE : GITHUB_REPOSITORY_SLUG_URL is design to be used as subdomain in an URL.

GITHUB_SHA_SHORT

Short the environment variable GITHUB_SHA

The commit SHA that triggered the workflow

GITHUB_SHA GITHUB_SHA_SHORT
ffac537e6cbbf934b08745a378932722df287a53 ffac537e

Use slug variable in an URL

In an URL, use <GITHUB_VARIABLE>_SLUG_URL instead of <GITHUB_VARIABLE>_SLUG as subdomain to be compliant.

NOTE : <GITHUBVARIABLE>_SLUG can be used in an URL only as part of the _resource path.

- name: Inject slug/short variables
  uses: rlespinasse/[email protected]

- name: Deploy dummy application using slug in the 'subdomain' part
  run: |
    ./deploy-application.sh --url "https://${{ env.<GITHUB_VARIABLE>_SLUG_URL }}.staging.app.mycompany.com"

- name: Deploy dummy application using slug in the 'resource path' part
  run: |
    ./deploy-application.sh --url "https://staging.app.mycompany.com/${{ env.<GITHUB_VARIABLE>_SLUG }}"

Contribute

Follow Developers guide

Troubleshooting

Missing master branch

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'

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

The master branch don't exists anymore.

The master branch EOL have been set to 2020-10-25 after a 6-month deprecation period (more information on the EOL issue)

action-github-slug's People

Contributors

ameausoone avatar dependabot[bot] avatar helaili avatar php-coder avatar rlespinasse avatar semantic-release-bot avatar

Watchers

 avatar  avatar

Forkers

armbiant

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.