How to create git branch names as part of artifacts while upload

how to create git branch names as part of artifacts while upload like feature/workflowchanges, master and release branch artifacts to differentiate


You can use the upload-artifact action in your workflow.
When using the upload-artifact action, you can custom the artifact name as you like. The value of the input parameter ‘name’ on this action can receive strings, and expressions to access environment variables and contexts.

To get the branch ref of current running workflow run, you can use the expression “github.ref” to get the branch name from the github context, or use expression “GITHUB_REF” to access the corresponding environment variable.

Generally, the branch ref get from “github.ref” or “GITHUB_REF” has the prefixes “refs/heads/” (e.g. refs/heads/master). If you do not need the prefixes, you can remove it.
A simple example:

- name: Get branch name
  if: ${{ contains(github.ref, 'refs/tags/') }}
  run: echo "::set-env name=BRANCH_NAME::${GITHUB_REF##*/}"
# use the expression '${GITHUB_REF##*/}' to remove the prefixes 'refs/heads/'
# from the branch ref and only return the branch name (e.g. 'master')
# use the 'set-env' command to set the returned branch name as an environment variable
# see ''

- name: Upload artifact
  uses: actions/upload-artifact@v2
    name: ${{ env.BRANCH_NAME }}-artifact
    path: path/to/artifact/files

In this example, the artifact name will be “master-artifact” when the branch ref is “refs/heads/master”.