跳过特定文件的工作流程
我当前的github工作流程即使是.md
文件或.txt
文件也可以执行测试用例。
我想跳过对文档文件进行的任何更改的测试。我的文件夹结构是:
project
| source-codes
│ docs
│ file001.txt
| file.rst
| file.md
github工作流程必须跳过 doc 文件夹或使用.rst
或.md
文件的任何内容。
我有下面的代码,但似乎不起作用。我目前正在从我的功能分支中尝试此操作。
.github/workflows/main.yml
# This is a basic workflow to help you get started with Actions
name: Documentation Test
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the "main" branch
push:
branches:
- 'main'
# Allows you to run this workflow manually from the Actions tab
# workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "Documentation Testcase"
documentation_testcase:
# The type of runner that the job will run on
name: Documentation Job
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- name: Checkout
uses: actions/checkout@v3
with:
# Checkout as many commits as needed for the diff
fetch-depth: 2
- shell: pwsh
# Give an id to the step, so we can reference it later.
id: check_file_changed
run: |
# Diff HEAD with the previous commit
$diff = git diff --name-only HEAD^ HEAD
# Check if a file under docs/ or with the .md extension has changed (added, modified, deleted)
$SourceDiff = $diff | Where-Object { $_ -match '^docs/' -or $_ -match '.rst$' }
$HasDiff = $SourceDiff.Length -gt 0
# Set the output named "docs_changed"
Write-Host "::set-output name=docs_changed::$HasDiff"
# Run the step only with "docs_changed" equals "True"
- shell: pwsh
# steps.<step_id>.outputs.<output name>
if: steps.check_file_changed.outputs.docs_changed == 'True'
run: echo publish docs
My current GitHub workflow executes test cases even for .md
file or .txt
file.
I want to skip the test for any changes made to documentation files. My folder structure is:
project
| source-codes
│ docs
│ file001.txt
| file.rst
| file.md
The GitHub workflow must skip for docs folder or anything with .rst
or .md
file.
I have the code below but doesn't seem to work. I am currently trying this from my feature branch.
.github/workflows/main.yml
# This is a basic workflow to help you get started with Actions
name: Documentation Test
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the "main" branch
push:
branches:
- 'main'
# Allows you to run this workflow manually from the Actions tab
# workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "Documentation Testcase"
documentation_testcase:
# The type of runner that the job will run on
name: Documentation Job
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- name: Checkout
uses: actions/checkout@v3
with:
# Checkout as many commits as needed for the diff
fetch-depth: 2
- shell: pwsh
# Give an id to the step, so we can reference it later.
id: check_file_changed
run: |
# Diff HEAD with the previous commit
$diff = git diff --name-only HEAD^ HEAD
# Check if a file under docs/ or with the .md extension has changed (added, modified, deleted)
$SourceDiff = $diff | Where-Object { $_ -match '^docs/' -or $_ -match '.rst
}
$HasDiff = $SourceDiff.Length -gt 0
# Set the output named "docs_changed"
Write-Host "::set-output name=docs_changed::$HasDiff"
# Run the step only with "docs_changed" equals "True"
- shell: pwsh
# steps.<step_id>.outputs.<output name>
if: steps.check_file_changed.outputs.docs_changed == 'True'
run: echo publish docs
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议您使用
paths-ignore
设置,而不是复杂的shell脚本。在此处阅读有关此配置的更多信息:链接
示例动作: link < /a>
代码示例:
Instead of complex shell script, I'd recommend using
paths-ignore
setting.Read more about this configuration here: Link
Example Action: Link
Code Example: