当项目中任何地方的python文件(.py)发生更改时,如何运行github操作测试



当项目中任何地方的任何python文件(.py文件(发生更改时,我如何让github操作运行pytest?这个项目包含不同语言的混合,我只想在项目中的某个地方(项目中任何级别的ANY目录中(有python文件更改时运行pytest。

name: Test Python Tests
on:
push:
paths:
- what to put here???? 
jobs:
build-and-run:
steps:
- uses: actions/checkout@v1
- name: Update Conda environment with "requirements.yml"
uses: matthewrmshin/conda-action@v1
with:
args: conda env update -f ./requirements.yml
- name: Run "pytest" with the Conda environment
uses: matthewrmshin/conda-action@v1
with:
args: pytest
on:
push:
paths:
- '**.py'

这应该做的技巧,见过滤模式备忘单

基本上,您需要的是git-diff信息,并从中读取所有更改的文件。

GitHub Actions的推送事件不包括已修改文件的列表。这意味着,您必须总是在推送时触发一个工作流运行,然后检查通过普通RESTneneneba API更改的文件。https://docs.github.com/en/actions/reference/events-that-trigger-workflows#push

注意:GitHub Actions可用的webhook负载不包括提交对象中添加、删除和修改的属性。您可以使用REST API检索完整提交对象。有关更多信息,请参阅";获取单个提交"&";。

您可以将JavaScript Action与OctoKit客户端结合使用(https://github.com/actions/toolkit)。如果您使用工具箱中的一个,它将已经通过身份验证。

OctoKit可以用来让REST调用变得相当简单。请参阅上的默认响应200https://docs.github.com/en/rest/reference/repos#get-a-commit

...
"files": [
{
"filename": "file1.txt",
"additions": 10,
"deletions": 2,
"changes": 12,
"status": "modified",
"raw_url": "https://github.com/octocat/Hello-World/raw/7ca483543807a51b6079e54ac4cc392bc29ae284/file1.txt",
"blob_url": "https://github.com/octocat/Hello-World/blob/7ca483543807a51b6079e54ac4cc392bc29ae284/file1.txt",
"patch": "@@ -29,7 +29,7 @@n....."
}
]
...

如果文件字段包含.py文件,请取消工作流。您可以直接从JS本身取消工作流:

core.setFailed(error.message);

核心是您的OctoKit客户端。

最新更新