此社区论坛上的帖子可能会有所帮助。
https://github.community/t5/GitHub-Actions/What-happened-to-github-event-head-commit-modified/m-p/37736#M3066
那里的原始海报有一个类似的问题,他们创建了以下操作来确定是否对路径列表进行了修改。我不确定on: pull_request
是否也能正常工作,但是您可以尝试看看。
https://github.com/marketplace/actions/path-watcher-action
来自path-watcher-action
存储库的示例:
on: [push]
jobs:
job:
runs-on: ubuntu-latest
steps:
- id: modified
uses: pheel/path-watcher-action@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
paths: 'dir1/**/*,dir2/**/*'
- if: steps.modified.outputs.modified
run: echo "Hey some change happened in one of your watched paths!"
,
我设法通过使用git diff
用最新的PR提交(github.base_ref
来区分${GITHUB_SHA}
分支并过滤输出以选择路径来完成需要执行的步骤。陷阱在于:
- 我需要使用
github['base_ref']
语法(大概是由于下划线?)
- 克隆的存储库中不存在base_ref分支,因此我需要在其前面加上
origin/
- name: Conditional test
env:
BASE: origin/${{ github['base_ref'] }}
run: |
paths=(
path1
path2/src
path3/src/main
)
if [ -n "$(git --no-pager diff --name-only ${BASE} ${GITHUB_SHA} -- ${paths[@]})" ]; then
echo "Changes affect module,running ALL"
mvn -B test -P all-tests --no-transfer-progress
else
echo "No changes affect module,running MINIMAL"
mvn -B test -P minimal-tests --no-transfer-progress
fi
我在GitHub动作方面没有足够的经验,无法知道我们是否最好将这种逻辑封装在自定义动作中,但是现在我将继续使用它,以避免额外的外部依赖性
本文链接:https://www.f2er.com/3121315.html