Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run one step before matrix combinations

I'm creating a GitHub Actions workflow.
There is a phing build file that creates multiple zips depending on product variations. This is done with a matrix.

Before the product is build there is a JS file that needs to be built. That's done with a rollup build file.

Everything works fine, but the JS build only needs to be done once and not with every matrix combination.

I don't know how that should be done. Maybe with a single separate workflow running at start, but how would the finished JS file be pushed into the next workflow? Or maybe one workflow is fine?

name: Build

on: [push]

jobs:
  build:
    runs-on: ubuntu-latest
    env:
      VERSION: 1.0.1
    strategy:
      matrix:
        edition: ["product1", "product2", "product3"]
        limits: [100, 200, 300]
        exclude:
          - edition: product1
            limits: 100
          - edition: product2
            limits: 100
          - edition: product1
            limits: 200
          - edition: product2
            limits: 200
    steps:
      - uses: actions/checkout@v2

      - name: Build JS
        uses: actions/setup-node@v1
        with:
          node-version: 12.x
      - name: Cache Node.js modules
        uses: actions/cache@v2
        with:
          path: ~/.npm
          key: ${{ runner.OS }}-node-${{ hashFiles('**/package-lock.json') }}
          restore-keys: |
            ${{ runner.OS }}-node-
            ${{ runner.OS }}-
      - run: npm ci
      - run: npm run build # builds main.js

      - name: Phing Build
        uses: phingofficial/phing-github-action@main
        with:
          repo-token: "${{ secrets.GITHUB_TOKEN }}"
          buildfile: build/phing/build.xml
          targets: main
          user-properties: editions=${{ matrix.edition }} limits=${{ matrix.limits }}
          version: 3.0.0-alpha4

      - name: Archive code
        uses: actions/upload-artifact@v2
        with:
          name: file-${{ matrix.edition }}${{ matrix.limits }}-v${{ env.VERSION }}
          path: build/${{ matrix.edition }}/zip/
          retention-days: 1
like image 525
Mike Avatar asked Mar 01 '26 17:03

Mike


1 Answers

You can execute creating the JS File in a separate job (let's name it prepare) and then reference that job in the job with the matrix definition (build) using the needs keyword. Sharing files across jobs is something that GitHub is very specific about: not each job needs all files from a previous job, so you will need to upload and download that file yourself.

Example setup:

jobs:
  prepare:
    runs-on: ubuntu-latest
    steps:
      ...
      # upload the file here for later use
      - uses: actions/upload-artifact


  build:
    needs: prepare
    strategy:
      matrix:
        edition: ["product1", "product2", "product3"]
    steps:
      # download the file here so you can use it
      - uses: actions/download-artifact

See the docs on the needs keyword here.

like image 71
Rob Bos Avatar answered Mar 03 '26 09:03

Rob Bos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!