Github actions: Can the effects of one job trigger another?

Viewed 819

I want to define a workflow as follows, for a node.js repo:

  • When new code is merged into master AND version in package.json is changed, create a new Github release for that version
  • When a new Github release is created, publish package to NPM

What I hope to achieve is that in our most typical workflow (PR merged to master) a release s created and package is automatically uploaded to NPM but to also be able to trigger an upload to NPM directly from a feature branch (usually a pre-release version, 1.0.3-rc1) by manually creating a release from such branch.

I've set up two Github workflows, each with a single job. The first:

name: Create release on new version merge
on:
  push:
    branches:
    - master
jobs:
  release-on-new-version:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Check for version change
        id: check
        uses: EndBug/version-check@v1
        with:
          file-url: ::before
          static-checking: localIsNew
          token: ${{ secrets.GITHUB_TOKEN }}
      - name: Log when changed
        if: steps.check.outputs.changed == 'true'
        run: 'echo "Version change found: ${{ steps.check.outputs.version }}"'
      - name: Create Release
        if: steps.check.outputs.changed == 'true'
        id: create_release
        uses: actions/create-release@v1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          tag_name: v${{ steps.check.outputs.version }}
          release_name: v${{ steps.check.outputs.version }}...

The second:

name: Publish on new release

on:
  release:
    types: created

jobs:
  publish-on-release:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v1
        with:
          node-version: 10
          registry-url: https://registry.npmjs.org/
      - run: npm publish
        env:
          NODE_AUTH_TOKEN: ${{secrets.npm_token}}

Individually these workflows work as expected: When I merge some work onto master that changes the version number a release is created, and when I manually create a release it gets published to NPM. However I would also expect the release created as the effect of the first workflow to trigger the second flow and therefore when I merge a version change into master eventually automatically see it published to NPM. But to my amazement that does not happen. Is there some sort of mechanism that prevents the effects of one job to (indirectly) trigger another? Or am I missing something?

1 Answers

You might consider to explicitly mention the dependency of one job needed another job, using needs.

You can see that approach illustrated with:

"GitHub Actions: Dependent Jobs" from Edward Thomson (who is also on Stack Overflow)

That would allow to define a third action which would need the first two, forcing them to be chained in their execution.

Related