I own an npm package and decided to create Github actions to automate processes effectively.
main.yml
- handle Node CI. on every push to the master branch, the action will install the dependencies and build through multiple operating systems.release.yml
- required to release a new version to npm and Github Releases. It'll fire on every commit tag which begins with "v" (e.g., "v0.1.4").
However, the release.yml
action is being skipped while pushing to git with the commit tag.
How to fire the release.yml
file? but still, wait for main.yml
to finish the entire workflow?
I would appreciate your assistance.
main.yml
action:
name: Node Continous Integration
on:
push:
branches: [master]
jobs:
build:
name: Build on Node ${{ matrix.node }} and ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
node: ['10.x', '12.x', '14.x']
os: [ubuntu-latest, windows-latest, macOS-latest]
steps:
- name: Checkout repo
uses: actions/checkout@v2
- name: Use Node ${{ matrix.node }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}
- name: Install deps and build (with cache)
uses: bahmutov/npm-install@v1
- name: Build
run: npm run build
release.yml
action:
# Name of the workflow
name: Release new version
# Run on every commit tag which begins with "v" (e.g., "v0.1.4")
on:
push:
tags:
- "v*"
jobs:
# Automatically publish a NPM release
npm-publish:
name: NPM Release
runs-on: ubuntu-latest
if: ${{ github.ref == 'refs/heads/master' }}
steps:
- name: Checkout repo
uses: actions/checkout@v2
- name: Use Node ${{ matrix.node }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}
- name: Install deps and build (with cache)
uses: bahmutov/npm-install@v1
- name: Publish
run: npm publish
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
# Automatically create a GitHub Release, with release details specified (the relevant commits)
github-release:
name: Github Release
needs: [npm-publish]
runs-on: ubuntu-latest
if: ${{ github.ref == 'refs/heads/master' }}
steps:
- uses: "marvinpinto/action-automatic-releases@latest"
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
prerelease: false
CodePudding user response:
The problem is with your if condition inside the jobs. if: ${{ github.ref == 'refs/heads/master' }}
In case of tags push, github.ref
will be something like refs/tags/v.2.2.2
Since the if condition is not matching the jobs are skipped.
I ran a sample job here to validate it. Link