Reuse build phase from Github action in order to run tests in parallel actions

214 Views Asked by At

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

0

There are 0 best solutions below