I'm using the official black
GitHub Action. Currently, whenever I push changes, black
runs on the entire repository. However, I only want it to run on the changed files. I've tried using some of the GitHub environment variables, but to no avail. Here's my workflow yaml:
name: Lint
on: [push, pull_request]
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run : echo ${{ github.sha }} # this outputs a SHA
- run : echo ${{ github.run_attempt }} # this outputs an int
- run: echo ${{ github.head_ref }} # outputs nothing
- run: echo ${{ github.base_ref }} # outputs nothing
- uses: actions/setup-python@v3
with:
python-version: '3.9.12'
name: Run black on diffed files
- run: echo ${{ github.head_ref }} # outputs nothing
- run: echo ${{ github.base_ref }} # outputs nothing
- run: pip install black && black $(git diff --name-only ${{ github.base_ref}} ${{ github.head_ref }} | grep .py)
The workflow successfully installs and runs black
, but it fails because no files are being passed to the black
command.
I'm not sure what I'm doing wrong here.