Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Copilot Lvl 2
Message 1 of 2

Wait a workflow to finish before running another workflow

My Docker build workflow:

name: docker

on:
  push:
    paths:
    - 'Dockerfile'
    - 'setup.py'
    - 'install*.sh'

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@master
    - name: Publish to Registry
      uses: elgohr/Publish-Docker-Github-Action@master
      with:
        name: dragoncomputer/dragonfire
        username: ${{ secrets.DOCKER_USERNAME }}
        password: ${{ secrets.DOCKER_PASSWORD }}

 

and my test workflow:

name: test

on: [push]

jobs:
  build:

    container:
image: dragoncomputer/dragonfire:latest steps: - uses: actions/checkout@v1 - name: Install dependencies run: | sudo ./install-dev.sh --no-model sudo pip3 install pytest-faulthandler sudo apt install xvfb - name: Lint with flake8 run: | sudo pip3 install flake8 # stop the build if there are Python syntax errors or undefined names flake8 . --count --select=E9,F63,F72,F82 --show-source --statistics # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - name: Test with pytest run: | sudo pip3 install pytest pytest-cov codecov xvfb-run --auto-servernum python3 -m pytest --cov=dragonfire/ --capture=sys --disable-pytest-warnings -vv # send the code coverage report to Codeconv codecov --token=${{ secrets.CODECOV_TOKEN }}

 

But since my Docker build only runs when specific files are changed:

 

on:
  push:
    paths:
    - 'Dockerfile'
    - 'setup.py'
    - 'install*.sh'

it needs to be a separate workflow.

 

Since my Docker image is 5GB and it exceeds the GitHub Actions cache limit: https://github.com/actions/cache#cache-limits, I cannot use the cache either.

 

So my question: Is there a way to wait a workflow to finish before running another workflow? If there is none then how can combine these to workflows to single one?

 

By the way, I know there is jobs.<job_id>.needs but seems like it does not solve my problem because my Docker build/job runs when a specific criteria is met.

 

If you are wondering why do I need a comlicated workflow like this then you might want to check out the current situation of my repository:

docker.yml

pythonapp.yml

 

1 Reply
GitHub Partner
Message 2 of 2

Re: Wait a workflow to finish before running another workflow

There is no method to wait a workflow to finish before running another workflow. There is a work around to combine these two workflows to a single one.

You can add a step to get file names which changed in the commit. And set it to an output variable: commitpath .

- name: check1
   id: filepath
   run: |
        echo ::set-output name=commitpath::$(git diff-tree --no-commit-id --name-only -r ${{ github.sha }})

Then judge the path in if condition using contains function for ‘publish to registry step. As contains( searchString, searchValue ) function doesn’t support to use wildcards, you need to specify all your exact file names as searchValue.

Such as:

if: Contains(steps.filepath.outputs.commitpath, 'Dockerfile') || Contains(steps.filepath.outputs.commitpath, 'install.sh') || Contains(steps.filepath.outputs.commitpath, 'setup.py')

Also, you need to use  jobs.<job_id>.needs in build job.

Please see my examples:

docker test.png

Note that there will be some additional time for this workflow to run docker job when commits don’t include changes in Dockerfile, setup.py etc.

if path.png