跳过特定文件的工作流程

发布于 2025-02-10 03:19:45 字数 2255 浏览 0 评论 0原文

我当前的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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

屌丝范 2025-02-17 03:19:45

我建议您使用paths-ignore设置,而不是复杂的shell脚本。
在此处阅读有关此配置的更多信息:链接

示例动作: link < /a>

代码示例:

on:
  push:
    paths-ignore:
      - 'README.md'
      - 'backup/**'
      - 'masterDir/contentDir/**/*.draft.md'

Instead of complex shell script, I'd recommend using paths-ignore setting.
Read more about this configuration here: Link

Example Action: Link

Code Example:

on:
  push:
    paths-ignore:
      - 'README.md'
      - 'backup/**'
      - 'masterDir/contentDir/**/*.draft.md'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文