Chore adding autofix ci #6
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 and check | |
id: format | |
run: | | |
pnpm exec prettier --write "**/*.{js,jsx,ts,tsx,json,md}" | |
# Check if there are any formatting issues | |
if [ -n "$(git status --porcelain)" ]; then | |
echo "::set-output name=format_failed::true" | |
fi | |
git add . | |
- name: Run ESLint fix and check | |
id: lint | |
run: | | |
pnpm exec eslint . --ext .js,.jsx,.ts,.tsx --fix | |
# Run ESLint again to check if all issues are fixed | |
if ! pnpm exec eslint . --ext .js,.jsx,.ts,.tsx --max-warnings 0; then | |
echo "::set-output name=lint_failed::true" | |
fi | |
git add . | |
- name: Check if lint or format failed | |
id: check_failures | |
run: | | |
if [ "${{ steps.format.outputs.format_failed }}" = "true" ] || [ "${{ steps.lint.outputs.lint_failed }}" = "true" ]; then | |
echo "Formatting or linting issues found!" | |
exit 1 | |
fi | |
- name: Check TypeScript | |
if: success() | |
run: | | |
pnpm exec tsc --noEmit | |
continue-on-error: true | |
- name: Sort package.json | |
if: success() | |
run: | | |
pnpm exec sort-package-json | |
git add package.json | |
- name: Commit changes | |
if: success() | |
run: | | |
git config --global user.name 'github-actions[bot]' | |
git config --global user.email 'github-actions[bot]@users.noreply.github.com' | |
if [ -n "$(git status --porcelain)" ]; then | |
git commit -m "style: 🎨 auto format and fix" -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 |