Thursday, March 10, 2022

Github actions: get current branchname with lowercase

    # extract branch name
    - name: Extract branch name
      if: github.event_name != 'pull_request'
      shell: bash
      run: echo "::set-env name=BRANCH_NAME::$(branchname=${GITHUB_REF#refs/heads/};echo ${branchname,,})"
      id: extract_branch        
      env:
          ACTIONS_ALLOW_UNSECURE_COMMANDS: true
    # extract branch name on pull request
    - name: Extract branch name on Pull Request
      if: github.event_name == 'pull_request'
      run: echo "::set-env name=BRANCH_NAME::$(branchname=${GITHUB_REF};echo ${branchname,,})"
      env:
          ACTIONS_ALLOW_UNSECURE_COMMANDS: true
    # print branch name
    - name: Get branch name
      run: echo 'The branch name is' $BRANCH_NAME

 ACTIONS_ALLOW_UNSECURE environment variable is added when we get below error.

The `set-env` command is disabled. Please upgrade to using Environment Files or opt into unsecure command execution by setting the `ACTIONS_ALLOW_UNSECURE_COMMANDS` environment variable to `true`. For more information see: https://github.blog/changelog/2020-10-01-github-actions-deprecating-set-env-and-add-path-commands/

Reference:

https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-environment-variable

Convert to Uppercase or Lowercase on Linux (linoxide.com)

Get Current Branch Name in GitHub Actions with GITHUB_REF and Bash | Techiediaries

How to Manage GitHub Actions Environment Variables and Secrets (adamtheautomator.com)

Add repo secrets in below location:

https://github.com/org/repo/settings/secrets/actions



No comments:

Post a Comment