Skip to content
This repository has been archived by the owner on Mar 4, 2021. It is now read-only.

Document an example of tagging with a version #39

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

Document an example of tagging with a version #39

nathany opened this issue Jan 15, 2020 · 6 comments

Comments

@nathany
Copy link

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 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

@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

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 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?

@ryanweber88
Copy link

@RP-101 I used a similar solution to what @PeterHewat shared, but had to come up with my own way to add release notes from our text file. Here's both steps:

- name: Get Version
  id: vars
  run: echo ::set-output name=version::$(node -e "console.log(require('./version.json').version);")
- name: Get Release Notes
  id: notes
  run: |
    notes=$(cat .release_notes)
    notes="${notes//'%'/'%25'}"
    notes="${notes//$'\n'/'%0A'}"
    notes="${notes//$'\r'/'%0D'}"
    echo "::set-output name=release_notes::$notes"

set-output and set-env both appear to strip %, \r and \n characters (which we wanted to keep), which is why I've got a few lines that handle that before setting the output.

I was able to reference these vars in the step to create the release like this:

  • ${{ steps.vars.outputs.version }}
  • ${{ steps.notes.outputs.release_notes }}

@madsoliver
Copy link

How can I set prerelease: true if tag contains beta?
I tried with no luck:
prerelease: ${{ contains( steps.get_version.outputs.VERSION , 'beta') }} && true || false

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants