有没有办法通过提交信息的值来触发特定的Github action workflow?例如,如果我使用提交信息“smoke_test”推送,那么只有来自一组工作流中的(一个特定工作流程)smoke test工作流会被触发。请帮忙解答,谢谢!
有没有办法通过提交信息的值来触发特定的Github action workflow?例如,如果我使用提交信息“smoke_test”推送,那么只有来自一组工作流中的(一个特定工作流程)smoke test工作流会被触发。请帮忙解答,谢谢!
有的。如果提交说明包含特定关键词,您可以检查触发器事件。
这里是一个示例:
name: Smoke tests
on: push
jobs:
test:
runs-on: [ ubuntu-latest ]
steps:
- name: Run smoke tests
if: contains(github.event.head_commit.message, 'smoke_test')
run: |
echo 'Running smoke tests!'
if
关键字来条件化Job中的所有步骤。请参见下面的示例。name: My Build.
# The name for workflow runs generated from the workflow, which will appear in the list of workflow.
run-name: ${{ github.actor }} has triggered Build and Launch Unittests for the project
# Specify the trigger for this workflow.
on: [push]
jobs:
Build-my-project-for-Linux:
runs-on: ubuntu-latest
if: contains(github.event.head_commit.message, 'please build')
steps:
- name: Check out repository code
uses: actions/checkout@v3
- run: echo " The ${{ github.repository }} repository has been cloned to the runner into " ${{ github.workspace }}
- run: |
export CC=/usr/bin/gcc-10
export CXX=/usr/bin/g++-10
echo "Etc. for first step"
- run: |
echo "Etc. for second step"
1 https://docs.github.com/en/actions/learn-github-actions/understanding-github-actions
[2] https://docs.github.com/en/actions/using-workflows/about-workflows
工作流程 - 是一个可配置的自动化过程,将运行一个或多个作业。
事件 - 是触发工作流程运行的存储库中的特定活动。
运行器 - 是在触发工作流程时运行工作流程的服务器。每个运行器一次只能运行一个作业。GitHub提供Ubuntu Linux、Microsoft Windows和macOS运行器。
作业 - 是在工作流程中执行相同运行器上的一组步骤。
步骤 - 步骤可以是一个将被执行的Shell脚本,也可以是一个将被运行的动作。可以通过使用paths:
检查特定文件在提交中是否已更改,而不是检查提交消息内容,来替代在工作流启动后检查提交消息以跳过步骤/作业的方法(参见此处)。这样,您的工作流永远不会开始运行,与其他方法不同:
on:
push:
paths:
- '**trigger_file.txt'