Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document an example of tagging with a version #39

Open
nathany opened this issue Jan 15, 2020 · 4 comments
Open

Document an example of tagging with a version #39

nathany opened this issue Jan 15, 2020 · 4 comments

Comments

@nathany
Copy link

@nathany nathany commented Jan 15, 2020

It took a few attempts to find a solution to get a version # to tag the releases with. In my case I have a VERSION file containing the version number, such as 0.1.0. This solution should be applicable even if the desired version is stored elsewhere so long as it can be accessed from a bash shell.

The first step gets the version via a run command and sets the output. See the documentation for set-output.

- name: Get version
   id: get_version
   run: echo "::set-output name=version::$(cat VERSION)"

Then the id can be used to access the output for the tag and release name:

- name: Create release
  id: create_release
  uses: actions/create-release@v1
  env:
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  with:
    tag_name: v${{ steps.get_version.outputs.version }}
    release_name: v${{ steps.get_version.outputs.version }}
    draft: false
    prerelease: false

Is there a better way? I had no success using cat outside of a run step, but I didn't try every possibility.

In #31 I noticed that @fleskesvor wrote a more elaborate solution, which is another reason to document what GitHub Actions provides out-of-the-box.

@eine
Copy link

@eine eine commented Jan 15, 2020

@nathany, AFAIK there is no other solution to dynamically set the with arguments for an action. This action could honour an environment variable, as it does with GITHUB_TOKEN, but that's not implemented yet.

@PeterHewat
Copy link

@PeterHewat PeterHewat commented Feb 25, 2020

@nathany Is there a better way?
Yes using the environement to store your version:

- name: Get version
  run: echo ::set-env name=version::$(cat VERSION)

Then:

- name: Create release
  id: create_release
  uses: actions/create-release@v1
  env:
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  with:
    tag_name: v${{ env.version }}
    release_name: v${{ env.version }}
    draft: false
    prerelease: false
@PeterHewat
Copy link

@PeterHewat PeterHewat commented Feb 25, 2020

PS: In my case, the version is stored inside my package.json and since I use actions/setup-node@v1, I extract the version like this:

  run: echo ::set-env name=version::$(node -pe "require('./package.json').version")
@RP-101
Copy link

@RP-101 RP-101 commented May 8, 2020

Hi @PeterHewat , I also encountered a problem and want to create the version name and release notes from a txt file. Did you find a solution for this yet?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.