我正在处理一个包含多个项目的单一存储库,每个解决方案都在不同的文件夹中。我想要实现的是,如果对该文件夹中的代码进行了更改,则对该文件夹运行扫描操作。我想在 pull_request 路径触发器中设置每个解决方案的所有路径,然后根据触发工作流的路径对该文件夹运行扫描。
我在想做这样的事情:
name: scan
on:
pull_request:
paths:
- 'path/to/folder/*'
- 'path/to/anotherfolder/*'
jobs:
output_path:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/[email protected]
- name: Determine triggering path
id: determine_path
run: |
# Get the list of paths being monitored
monitored_paths=$(echo "${{ github.event.pull_request.paths }}" | tr -d '[] ')
# Loop through each path
for path in $monitored_paths; do
# Check if the modified files include this path
if echo "${{ github.event.pull_request.changed_files }}" | grep -q "$path"; then
# Set the output variables and exit the loop
echo "::set-output name=triggering_path::$path"
break
fi
done
- name: Output path
run: |
echo "The following path triggered this job: ${{ steps.determine_path.outputs.triggering_path }}"```
我最终通过以下方式解决了它:
name: scan
on:
pull_request:
branches:
- main
types:
- opened
- synchronize
paths: ["path/to/folder/*", "path/to/anotherfolder/*"]
env:
paths: 'path/to/folder/, path/to/anotherfolder/'
jobs:
output_path:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/[email protected]
- name: Get changed files
id: changes
run: |
echo "files=$(git diff --name-only --diff-filter=ACMRT ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | xargs)" >> $GITHUB_OUTPUT
- name: Determine triggering path and sonar project key
id: determine_path
shell: bash
run: |
# Show paths
echo "Paths: ${{ env.paths }}"
# Get the list of paths being monitored
monitored_paths=$(echo "${{ env.paths }}" | tr "," " ")
echo "Monitored paths: $monitored_paths"
echo "Changed files: ${{ steps.changes.outputs.files }}"
echo "If you see here files that you have not modified, please update your branch with changes from main."
# Loop through each path
for path in $monitored_paths
do
# Check if the modified files include this path
if echo "${{ steps.changes.outputs.files }}" | grep -q "$path"; then
# Set the output variable and exit the loop
echo "triggering_path is $path"
echo "triggering_path=$path" >> $GITHUB_OUTPUT
break
fi
done
然后您可以使用表达式使用 determine_path 的输出
${{ steps.determine_path.outputs.triggering_path }}
• Using python to generate a JWT raises ValueError "Could not deserialize key data"
• 从 Google Drive 将图像添加到 GitHub Readme.md
• Github Actions:如何在 WF 中检索运行时作业 ID?
• 在配置目录下找不到配置:E:iverr\新建文件夹iqlick-mai
• 是否可以在 GitHub actions docker/build-push-action v3 中指定注册表
• PHP curl 到 github rest api 不返回任何东西
• 如何配置 Visual Studio 2022 以使用 SSH 或 GPG 密钥为 GitHub 签署 Git 提交?
• C++ 构建系统 [配置] 执行时失败:[...] CXX1405 in android Kotlin
• .NET 应用程序测试由于缺少依赖项而在 GitHub Actions 上失败
• 我已经从 github 下载了示例项目,它由 html、css、javascript 和 php 作为后端构建,它只显示 dasboard 但没有其他功能 [关闭]
• Caused by: java.lang.ClassNotFoundException: com.android.tools.lint.client.api.Vendor