Skip to content

feat(ci): auto-fmt and commit to the branch if lint fails #1684

feat(ci): auto-fmt and commit to the branch if lint fails

feat(ci): auto-fmt and commit to the branch if lint fails #1684

Workflow file for this run

name: lint
on:
pull_request:
push:
branches:
- master
jobs:
linter:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout repo
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
cache: 'yarn'
- name: Install project dependencies
run: yarn install
- name: Lint
id: lint
run: yarn nx format:check --all
continue-on-error: true # Continue even if the check fails
- name: Check Lint Results
if: steps.lint.outcome == 'failure'
run: echo "lint_failed=true" >> $GITHUB_OUTPUT
- name: Auto-format and commit changes if needed
if: steps.lint.outcome == 'failure'
run: |
yarn nx format:write --all
git config --global user.name "${{ github.actor }}"
git config --global user.email "${{ github.actor }}@users.noreply.github.com"
git add .
git commit -m "auto fmt" || echo "No changes to commit"
# Get the current branch name
BRANCH_NAME=$(git symbolic-ref --short HEAD || git rev-parse --abbrev-ref HEAD)
# If we're in detached HEAD state, use the GitHub event information
if [ "$BRANCH_NAME" = "HEAD" ]; then
BRANCH_NAME=${{ github.head_ref || github.ref_name }}
fi
# Push changes
git push origin HEAD:$BRANCH_NAME || echo "No changes to push"