I am trying to find a way to lint only markdown files that have changed on the current branch. I wrote a bash script that runs fine locally, but breaks in Github Actions.
Expected Outcome: lint only markdown files that have been changed on the branch in GitHub Actions on pull-request.
#!/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
I call the script in package.json
"scripts": {
"test": "bash mdlint.sh"
}
I then call the bash script in GitHub Actions workflow:
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
This is the Error in 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>...]'
Is there a way to make GitHub actions run the linter only on the files that changed on the current branch?
files=`(git fetch origin master:master) && (git diff --name-only master)
and your proposed changes in the workflow file. – Collage