1

I have a github action that has a build phase that installs some libraries, then builds the project, then runs some tests. Concretely it looks like:

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      # install deps.
      - name: install dependencies
        run: |
          sudo apt-get update
          sudo apt-get install -y libsystemd-dev

      # cache libsodium
      - name: cache libsodium-1.0.18
        id: libsodium
        uses: actions/cache@v2
        with:
          path: ~/libsodium-stable
          key: ${{ runner.os }}-libsodium-1.0.18

      # install libsodium with cache
      - name: Install cache libsodium-1.0.18
        if: steps.libsodium.outputs.cache-hit == 'true'
        run: cd ~/libsodium-stable && ./configure && make -j2 && sudo make install

... etc
      - name: build project
        run: <build the project>
      - name: test1
        run: <run test1>
      - name: test2
        run: <run test2>

I would like to know the simplest way to run test1 and test2 as parallel actions given that they need to make use of the build environment created from all of the previous steps. I have seen some mention or reusable/composable actions but I didn't see anything that fit my situation exactly.

I tried the dumbest thing possible


  test1:
    needs: [build]
    steps:
      - name: test1
        run: <run test1>

  test2:
    needs: [build]
    steps:
      - name: test2
        run: <run test2>

but this didn't work, probably because it's missing a runs-on statement

martin
  • 31
  • 1
  • 2
  • Yes, every job needs a `runs-on`, did you try adding one? – Benjamin W. Dec 07 '22 at 22:16
  • You might also be able to use a [matrix](https://docs.github.com/en/actions/using-jobs/using-a-matrix-for-your-jobs). – Benjamin W. Dec 07 '22 at 22:16
  • @BenjaminW. but if I put runs-on: ubuntu-latest, wouldn't that just give me a fresh vm that doesn't have my build environment I created in the previous step? – – martin Dec 07 '22 at 22:25
  • Yeah, you'd have to use caches, or upload and download artifacts, though I don't think there's a good way to pass around APT packages like that. Maybe there's a native way to run the tests in parallel? – Benjamin W. Dec 07 '22 at 22:52
  • @BenjaminW., probably you need the matrix feature - https://docs.github.com/en/actions/using-jobs/using-a-matrix-for-your-jobs – Andrii Bodnar Dec 08 '22 at 09:26
  • 1
    @AndriiBodnar that's only half the answer. My matrix jobs each do the whole build steps independently before running my tests. But if you solve caching the build, then matrix jobs would indeed parallelize the tests. – joanis Dec 08 '22 at 13:20

0 Answers0