Trying to auto-apply black and isort to only the files changed on some python code with github actions during a pull request on a self-hosted runner, and after that commit to the PR. But get errors such as Not a git repository on some of the steps. Here is my workflow file:
name: Autolint
on:
pull_request:
types: [opened, synchronize]
jobs:
run-linters:
name: Run linters
runs-on: self-hosted
container:
image: edlut/azion:monster-action-base
options: --privileged
steps:
- name: Install git
run: |
apt-get install -y git
git --version
echo "Path is ... $PATH"
PATH=$PATH:$(which git)
echo "Path is ... $PATH"
- uses: actions/checkout@v2
- name: Debug - Check if .git folder exists
run: |
ls -lah
- name: Install Python dependencies
run: pip3 install black isort
- name: Apply Black
env:
BRANCH: ${{ github.head_ref }}
run: |
echo "Branch is ... ${BRANCH}"
git diff --name-only "$GITHUB_BASE_REF..${BRANCH}" | grep .py | xargs black -l 119
- name: Apply isort
env:
BRANCH: ${{ github.head_ref }}
run: |
git diff --name-only "$GITHUB_BASE_REF..${BRANCH}" | xargs isort
- name: Check for modified files
id: git-check
run: echo ::set-output name=modified::$(if git status | grep "nothing to commit"; then echo "false"; else echo "true"; fi)
- name: Push changes
if: steps.git-check.outputs.modified == 'true'
run: |
git config --global user.name 'My Name'
git config --global user.email 'my-name@gmail.com'
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}
# git commit -am "style: Apply Black style"
# git push
Can anybody help me out on how to achieve this?