Skip to content

Chore adding autofix ci #7

Chore adding autofix ci

Chore adding autofix ci #7

Workflow file for this run

name: autofix.ci
on:
pull_request:
push:
branches: [ "main" ]
permissions:
contents: read
jobs:
autofix:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
fetch-depth: 0
- uses: pnpm/action-setup@v2
with:
version: 8
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'pnpm'
- name: Install dependencies
run: pnpm install --no-frozen-lockfile
- name: Cache pnpm modules
uses: actions/cache@v3
with:
path: ~/.pnpm-store
key: ${{ runner.os }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-
- name: Format code with Prettier
id: format
run: |
pnpm exec prettier --write "**/*.{js,jsx,ts,tsx,json,md}"
if [ -n "$(git status --porcelain)" ]; then
echo "FORMAT_HAS_CHANGES=true" >> $GITHUB_ENV
fi
git add .
- name: Run ESLint fix
id: lint
continue-on-error: true
run: |
pnpm exec eslint . --ext .js,.jsx,.ts,.tsx --fix
if [ -n "$(git status --porcelain)" ]; then
echo "LINT_HAS_CHANGES=true" >> $GITHUB_ENV
fi
# Run ESLint again to check remaining issues
pnpm exec eslint . --ext .js,.jsx,.ts,.tsx --max-warnings 0 || echo "LINT_HAS_ERRORS=true" >> $GITHUB_ENV
git add .
- name: Check TypeScript
continue-on-error: true
run: |
pnpm exec tsc --noEmit
if [ $? -ne 0 ]; then
echo "TS_HAS_ERRORS=true" >> $GITHUB_ENV
fi
- name: Sort package.json
run: |
pnpm exec sort-package-json
git add package.json
- name: Commit changes
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
COMMIT_MESSAGE="style: 🎨 auto format and fix"
if [ "${{ env.FORMAT_HAS_CHANGES }}" = "true" ]; then
COMMIT_MESSAGE="$COMMIT_MESSAGE\n\n- Applied Prettier formatting"
fi
if [ "${{ env.LINT_HAS_CHANGES }}" = "true" ]; then
COMMIT_MESSAGE="$COMMIT_MESSAGE\n- Applied ESLint fixes"
fi
if [ "${{ env.LINT_HAS_ERRORS }}" = "true" ]; then
COMMIT_MESSAGE="$COMMIT_MESSAGE\n⚠️ Some ESLint issues remain"
fi
if [ "${{ env.TS_HAS_ERRORS }}" = "true" ]; then
COMMIT_MESSAGE="$COMMIT_MESSAGE\n⚠️ TypeScript errors detected"
fi
if [ -n "$(git status --porcelain)" ]; then
git commit -m "$COMMIT_MESSAGE" -m "Co-authored-by: ${{ github.event.pull_request.user.login }} <${{ github.event.pull_request.user.id }}+${{ github.event.pull_request.user.login }}@users.noreply.github.com>"
fi
- uses: autofix-ci/action@dd55f44df8f7cdb7a6bf74c78677eb8acd40cd0a