G.S
G.S

Reputation: 10871

GitHub - Multiple workflow files for a repo is good practice?

I am using github repository for one of my java projects and I have following scenario to handle as part of CI/CD

  1. Push to any branch - then compile and run unit tests
  2. Push to development branch - then compile and produce artifact. Deploy to test server
  3. Push to main branch - then compile and produce artifact. Deploy to staging server

To handle the CI/CD, I can achieve in couple of ways that I can think of:

  1. Create a single workflow yml and predicate the jobs based on the condition (More of GitLab style of writing the CI file)
  2. Create multiple workflow yml and in each file use the condition to run

My question is: is it the good choice to write the workflow in multiple yml files as the actions/steps in the jobs are almost same and the differences can be handled via the env variables.

Upvotes: 2

Views: 3655

Answers (1)

VonC
VonC

Reputation: 1324935

Considering workflow 2 and 3 are independent one from another, it makes sense putting them in their own workflow file, in order to be able to maintain them independently.
But if they are doing the same thing, with only a server name difference, 2 and 3 would be one workflow file with a variable as parameter, in order to publish the build result to the right server. (so your option 1)

2 and 3 could both depend on workflow 1, which would do the compilation and unit testing. You could actually separate 1 into 1a for compilation and 1b for testing.

That way, through workflow_run, you could make 2 and 3 (or a unique workflow file with a server name parameter) depend on 1a (compilation) execution, restricting 2 and 3 to publication only (no compilation).
This is discussed here and used with workflow-run-conclusion-dispatch-action (which allows for a finer grained response to a workflow run).

Upvotes: 2

Related Questions