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

Jobs optimization - workflow dependencies

Solved! Go to Solution.

I trying to automate releasing python package on pypi. I have two different workflows:

  1. Test
  2. Release

Tests runs on each push, so it will fire on create release too.

Release run only when release published/created/idk still playing with this action.

 

I want to test whole code just before release and run tests only once.

 

Test workflow runs after creating release but I don't know how to run release after tests and only when not failed. Other reasonable option will be two jobs in one workflow but with different triggers. I can't find both in docs.

 

Can somebody tell me how to implement most DRY solution? Partial solution will be import (yaml) test job from test workflow to release workflow and use `needs` keyword.

2 Replies
Highlighted
Solution
GitHub Partner
Message 2 of 3

Re: Jobs optimization - workflow dependencies

Hi @Behoston ,

 

You can specify the 'branches/branches-ignore' for the 'push' event, then create release will not trigger test workflow(push event).  code sample as below:

on: 
  push:
    branches: 
      - master

Now the two workflows are seperated.

If you'd like execute test workflow before release workflow, you can add an extra step at the end of test workflow, use rest api to create release, and if test passed, release workflow will be triggered automatically.

Code sample as below, test workflow yaml:

name: pushevent
on: 
  push:
    branches: 
      - master
jobs:
  pushevent:
    runs-on: [ubuntu-latest]
    steps:
      - name: test steps
        run: echo test steps...
      - name: create release
        run: |
          curl -v -X POST -u ${{ secrets.PAT }} -H "Accept: application/vnd.github.antiope-preview+json" --data '{"tag_name": "v2.4", "target_commitish": "master", "name": "v2.4"}' https://api.github.com/repos/weide-zhou/ticket17/releases

The release workflow which will be triggered automatically:

name: releasecheck
on: 
  release:
    types:
      - created

trigger.png

 Currently it's not supported to limit the concurrent workflow run numbers, eg: push code 3 times but ran just 1 workflow, it's not supported.

 

Thanks.

Highlighted
Copilot Lvl 2
Message 3 of 3

Re: Jobs optimization - workflow dependencies

Finally, I decided to not release automatically, due to release tool that is not ready for CI/CD or does not match my case. But I think disabling test job for version tags will be enough if somebody has similar problem.