I have a monorepo with two workflows:
.github/workflows/test.yml
name: test on: [push, pull_request] jobs: test-packages: runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 - name: test packages run: | yarn install yarn test ...
.github/workflows/deploy.yml
name: deploy on: push: tags: - "*" jobs: deploy-packages: runs-on: ubuntu-latest needs: test-packages steps: - uses: actions/checkout@v1 - name: deploy packages run: | yarn deploy env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} ...
This doesn't work, I can't reference a job in another workflow:
### ERRORED 19:13:07Z - Your workflow file was invalid: The pipeline is not valid. The pipeline must contain at least one job with no dependencies.
Is there a way to create a dependency between workflows?
What I want is to run test.yml
then deploy.yml
on tags, and test.yml
only on push and pull requests. I don't want to duplicate jobs between workflows.
If you do want to trigger a workflow from within a workflow run, you can use a personal access token instead of GITHUB_TOKEN to trigger events that require a token. You'll need to create a personal access token and store it as a secret.
To run jobs sequentially, you can define dependencies on other jobs using the jobs. <job_id>. needs keyword. Each job runs in a runner environment specified by runs-on .
Workflows. A workflow is a configurable automated process that will run one or more jobs. Workflows are defined by a YAML file checked in to your repository and will run when triggered by an event in your repository, or they can be triggered manually, or at a defined schedule.
You can have multiple files in the . github/workflows folder. All files will be read and run as independent tests.
Now it's possible to have dependencies between workflows on Github Actions using workflow_run.
Using this config, the Release
workflow will work when the Run Tests
workflow is completed.
name: Release on: workflow_run: workflows: ["Run Tests"] branches: [main] types: - completed
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With