Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Github Release Version Number in Github Action

I have created a Github repo that has got an action to build the npm package and publish it to npmjs.com. The trigger for my action is the creation of a new release in Github. When creating the new release, Github is asking me for a version number. I would love to use this version number in the Action and provide it to the yarn publish command.

My ci-file looks like this (i stripped some parts that are not important here):

name: Deploy npm package

on:
  release:
    types: [created]

jobs:
  publish-npm:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      - uses: actions/setup-node@v1
        with:
          node-version: 12
          registry-url: https://registry.npmjs.org/
      - run: yarn install
      - run: yarn build
      - run: yarn publish --new-version ${...}
        env:a
          NODE_AUTH_TOKEN: ${{secrets.npm_token}}

Is there an environmental variable that contains the version number from the release?

like image 957
Woozar Avatar asked Dec 29 '19 10:12

Woozar


People also ask

How do I use GitHub release?

On GitHub.com, navigate to the main page of the repository. To the right of the list of files, click Releases. Click Draft a new release. Click Choose a tag, type a version number for your release, and press Enter.

How do I find the action version in GitHub?

You can get tag version using ${{ github. event. release. tag_name }} .

How do I check the version of a package in GitHub?

In the top right corner of GitHub.com, click your profile photo, then click Your profile. On the top of the profile page, in the main navigation, click Packages. Click the name of the package that you want to view.


2 Answers

It should be ${{ github.event.release.tag_name }}. The structure of a release can be found here: https://developer.github.com/v3/repos/releases/#get-a-single-release

I'd also suggest to use

on:
  release:
    types: [published]

instead of created to avoid putting something to npm for draft releases. See: https://help.github.com/en/actions/automating-your-workflow-with-github-actions/events-that-trigger-workflows#release-event-release

Hint:

To debug the event you can use:

jobs:
  debug:
    name: Debug
    runs-on: ubuntu-latest
    steps:
      - name: Dump env
        run: env | sort
      - name: Dump GitHub context
        env:
          GITHUB_CONTEXT: ${{ toJson(github) }}
        run: echo "$GITHUB_CONTEXT"
like image 113
scthi Avatar answered Oct 05 '22 22:10

scthi


You can get tag version using ${{ github.event.release.tag_name }}.

like image 40
milind Avatar answered Oct 05 '22 22:10

milind