0

I want to create a release tag from a workflow with GitHub Actions using actions/create-release@v1. I am specifying the same value for the tag name and the release name, which is v${MAJOR}.${MINOR}.${PATCH}, where MAJOR, MINOR, and PATCH are defined under env at the beginning of the yaml file before all jobs like this:

env:
  MAJOR: $(cat VERSION.txt | cut -d . -f 1)
  MINOR: $(cat VERSION.txt | cut -d . -f 2)
  PATCH: $(cat VERSION.txt | cut -d . -f 3)

Here is the part where I invoke the create-release action:

- name: Create Release
  uses: actions/create-release@v1
  env:
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # this token is created by Actions, no need to set it up ourselves
  with:
    tag_name: "v${MAJOR}.${MINOR}.${PATCH}" #THIS DOESN'T CAST MAJOR, MINOR, PATCH
    release_name: "v${MAJOR}.${MINOR}.${PATCH}"

This creates a tag name that is explicitly v${MAJOR}.${MINOR}.${PATCH}. The environment variables are not converted to their values. When I use v${{ env.MAJOR }}.${{ env.MINOR }}.${{ env.PATCH }} instead, I get a not well-formed tag name.

When I echo v${MAJOR}.${MINOR}.${PATCH}, I get the desired output, which is something like v5.9.1.

How can I make the tag name use the values of the environment variables ?

4
  • Without the section where you are setting these variables it's just guessing Commented May 7, 2021 at 19:32
  • I added the part where I define the major, minor, and patch Commented May 7, 2021 at 19:37
  • You can't set the env vars like that. Check out the docs here: docs.github.com/en/actions/reference/… Commented May 7, 2021 at 20:17
  • If I'm not mistaking, the syntax you are pointing works at a job level, meaning that I have to repeat it for each job, while setting the env key at the beginning of the yaml file before any job makes the environment variables available to all jobs. Also, the way I did seems to work for other actions in the same yaml file. Commented May 7, 2021 at 20:40

1 Answer 1

0

Thanks to one of the comments, I managed to make tag_name receive the value v5.9.1. I removed the env key at the beginning of the yaml file, and created a step get_version with the following:

   - name: Get version
      id: get_version
      run:  |
        MAJOR=$(cat VERSION.txt | cut -d . -f 1)
        MINOR=$(cat VERSION.txt | cut -d . -f 2)
        PATCH=$(cat VERSION.txt | cut -d . -f 3)
        VERSION="v${MAJOR}.${MINOR}.${PATCH}"
        echo "::set-output name=version::${VERSION}"

then I modified the create release step :

- name: Create release
  uses: actions/create-release@v1
  env:
     GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  tag_name: ${{ needs.get_version.outputs.version }} 
  release_name: ${{ needs.get_version.outputs.version }}
   draft: false
   prerelease: false
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.