Search code examples
continuous-integrationgithub-actionssemantic-release

Pushing to repository with semantic-release and checkout out in other job with GitHub Actions


We're using GitHub Action to automatically publish our application. For this, we call semantic-release in our CI pipeline and then generate the binaries with electron-builder in the next step. We need binaries for MacOS, Windows and Linux. Sadly, we need two different jobs for this, as we one job must run on macos-latest (to sign the MacOS build) and the other on ubuntu-latest (because the Linux build doesn't work on macos-latest... some issue with converting the main icon).

The problem that arises is that the semantic-release step in the first job updates package.json and pushes the changes to the GitHub repository. Then it creates the MacOS and Windows binaries. After that the Linux job starts, checks out the repository and creates its binaries. However, it still operates on the old version number (the one before semantic-release created a new version).

How do you make sure that the second job really has the git repository revision that was pushed in the first job?

This is the yaml file for the action (environment variable mappings removed):

name: Release

on:
    push:
        branches:
          - master

jobs:
    release:
        runs-on: macos-latest

        strategy:
            matrix:
                node-version: [10.x]

        steps:
            - uses: actions/checkout@v2
            - name: Use Node.js ${{ matrix.node-version }}
              uses: actions/setup-node@v1
              with:
                  node-version: ${{ matrix.node-version }}
            - name: install
              run: npm ci
            - name: Release
              run: npm run semantic-release || true
            - name: Build
              run: npm run build
            - name: Publish macOS
              run: npm run publish:mac
            - name: Publish Windows
              run: npm run publish:win
    release-linux:
        needs: release
        runs-on: ubuntu-latest

        strategy:
            matrix:
                node-version: [10.x]

        steps:
            - uses: actions/checkout@v2
            - name: Use Node.js ${{ matrix.node-version }}
              uses: actions/setup-node@v1
              with:
                  node-version: ${{ matrix.node-version }}
            - name: install
              run: npm ci
            - name: Release
              run: npm run semantic-release || true
            - name: Build
              run: npm run build
            - name: Install Snapcraft
              uses: samuelmeuli/action-snapcraft@v1
              with:
                snapcraft_token: ${{ secrets.snapcraft_token }}
            - name: Publish Linux
              run: npm run publish:linux


Solution

  • I finally found out how to get this working and it's really easy:

    The second job (the linux release) simply has to checkout master like this. If you don't specify a branch, it will always check out the commit that triggered the whole workflow. But if you specify master, it will get the must recent commit from master (the one modified by the previous job).

    - uses: actions/checkout@v2
      with:
        ref: 'master'