我正在尝试构建和部署一些代码。我想要 2 个 github 工作流程:构建和部署。我们的想法是构建一些工件,并在每次推送时将它们自动部署到功能分支的开发环境和主分支的阶段,而且还能够手动将其部署到生产环境。
构建工作流程按预期工作
build.yml:
name: build
on:
push:
jobs:
build-frontend:
steps:
- name: build
run:
.. do things here
- name: save artifact
uses: actions/upload-artifact@v3
并生成工件。
我试图让部署工作流程被触发:
build
已使用一些默认参数完成。我尝试过的:
name: deploy
on:
workflow_dispatch:
inputs:
environment:
description: 'Environment'
required: true
default: 'stage'
options:
- dev
- stage
- prod
workflow_run:
workflows: [build]
types:
- completed
并且此工作流程不会自动触发。我错过了什么?
任何有关不同方法的建议也将受到赞赏。
您的问题可能已在 文档中注明:
仅当工作流文件位于默认分支上时,此事件才会触发工作流运行
因此,例如,如果您在 PR 分支上运行,则该运行不会触发该工作流程。
我的建议只是将事件更改为workflow_call
,定义所需的输入,然后从构建中调用该作业。例如
name: build
on:
push:
jobs:
build-frontend:
steps:
- name: build
run:
.. do things here
- name: save artifact
uses: actions/upload-artifact@v3
trigger-deploy:
needs: [build-frontend]
uses: ./workflows/deploy.yml
with:
environment: dev