Clarification of job dependencies. i.e. test -> needs: build

https://github.com/fluffy-bunny/typescript-action-needs/actions

I started with the typescript-action template and made 2 modificaitons.

  1. Introduce needs: build to the test job

I wanted to test the dist/index.js that the build job produces.

ncc: Version 0.20.5
ncc: Compiling file index.js
12kB dist/index.js
12kB [654ms] - ncc 0.20.5
  1. deleted ./dist/index.js

result: 

Run ./
##[error]File not found: '/home/runner/work/typescript-action-needs/typescript-action-needs/./dist/index.js'

The build job produced the dist/index.js, but  the test job is not seing it.

Why?

If those are separate jobs they will run on separate runners, so the “test” job does not (automatically) get the data from the “build” job.

Depending on your workflow it may make sense to use one job that does both, or you could use cache or artifact actions to pass data between jobs.

1 Like

https://github.com/fluffy-bunny/typescript-action-needs/blob/master/.github/workflows/test.yml

name: "build-test"
on: # rebuild any PRs and main branch changes
  pull_request:
  push:
    branches:
      - master
      - 'releases/*'

jobs:
  build: # make sure build/ci work properly
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v1
    - run: |
        npm install
        npm run all

    - name: upload-artifact
      uses: actions/upload-artifact@v1
      with:
        name: my-artifact
        path: dist

  test: # make sure the action works on a clean machine without building
    needs: build
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v1

    - name: download-artifact from build
      uses: actions/download-artifact@v1
      with:
        name: my-artifact
        path: dist

    - uses: ./
      with:
        milliseconds: 1000

upload->download artifact works for my use case.

Thank you