Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
216 views
in Technique[技术] by (71.8m points)

Can I have multiple GitHub Actions workflow files?

Can I have multiple workflow files?

I have a few repo's utilizing GitHub Actions and they work great! In my specific use case, I auto-deploy to my dev environment on "push," and I auto-deploy to production on "release." These are two separate workflows.

I know I can have these two workflows in the same main.workflow file and that would work just fine, but I would prefer to have them in separate workflow files completely. Would it be possible for example to have a dev.workflow file, and a prod.workflow file?

I have tried creating a dev.workflow and prod.workflow file, but they don't seem to be picked up by Actions. It appears a main.workflow file is required. If that is the case, is there a way to source other workflow files into the main.workflow?

question from:https://stackoverflow.com/questions/57115520/can-i-have-multiple-github-actions-workflow-files

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can have multiple files in the .github/workflows folder. All files will be read and run as independent tests. The 'on' parameter on each file will tell when it must be called.

Following your idea you could have:

dev.workflow.yml - To run some kind of testing maybe (only on dev branch, when push)

name: Dev Workflow - Test and check thing
on:
  push:
    branches:
      - dev
jobs:
  ...

prod.workflow.yml- To build and deploy your project (only on master branch, when a PR is closed)

name: Master Workflow - Build and deploy to production
on:
  pull_request:
    types: closed
    branches:
      - master
jobs:
  ...

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...