【发布时间】:2026-01-26 18:10:01
【问题描述】:
我正在尝试找到一种方法来仅对当前分支上已更改的降价文件进行 lint。我编写了一个在本地运行良好的 bash 脚本,但在 Github Actions 中中断。
预期结果: 仅对 GitHub Actions on pull-request 中分支上已更改的 markdown 文件进行 lint。
#!/bin/bash
files=`git diff --name-only master`
for x in $files;
do
if [ ${x: -3} == ".md" ]
then
node_modules/.bin/markdownlint $x
fi
done
我在 package.json 中调用脚本
"scripts": {
"test": "bash mdlint.sh"
}
然后我在 GitHub Actions 工作流程中调用 bash 脚本:
name: CI
on:
pull_request:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
with:
fetch-depth: 1
- uses: actions/setup-node@master
- name: lint all markdownfiles
run: |
npm install
npm run test
这是 GitHub Actions 中的错误:
shell: /bin/bash -e {0}
npm WARN Gatsby_site No repository field.
npm WARN Gatsby_site No license field.
added 33 packages from 26 contributors and audited 43 packages in 0.952s
found 0 vulnerabilities
> @ test /home/runner/work/Gatsby_site/Gatsby_site
> bash mdlint.sh
fatal: ambiguous argument 'master': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
有没有办法让 GitHub 操作仅在当前分支上更改的文件上运行 linter?
【问题讨论】:
标签: bash github-actions linter