Workflow_run by pushing tags

Hi there, I’d like to ask how can I set up workflow_run to trigger when I push tag to a repo.

I have 3 workflows: tests, deploy and push client

  • tests.yml runs tests
  • deploy.yml deploys my code to a server and starts it
  • push clients generate http clients (ts, python) and pushes them to their repos

I would like to chain them in style:

  • tests runs always
  • deploy and push runs only if tests completed successfully and tag was pushed

Is that possible with workflow_run event or should I do it in other way?

p.s. I dont know really if I’m doing “right” or “wrong” - I’ve just decided to push by tags so any good advices on general topic are welcome

1 Like

The same use case here. Tried using:

name: CD

on:
  workflow_run:
    workflows: ['CI']
    push:
      tags: v[1-9]+.[0-9]+.[0-9]+
    types:
      - completed

But no success.

In that kind of situation it’s usually best to use three jobs within one workflow. That way you can use needs to define the dependencies between jobs.

The jobs that should only run for tags can use check if github.ref is a tag in a job-level if.

But in this case, I will need to put all the work in one workflow file (tests, lint, Sonarqube scan, build). This is not a bad practice?

I wouldn’t say so, but that’s a bit of a philosophical question. :wink:

What I would try though: Avoid spelling too much logic out in the workflow file itself, and use a build tool or scripts as appropriate, so you can (mostly) use the same tools in CI as you would for local builds. E.g. in a C project with Autotools I just have the workflow call autoreconf, ./configure, make, make check, and so on.

1 Like