|
| 1 | +name: Format PR |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [opened, synchronize, reopened, ready_for_review] |
| 6 | + |
| 7 | +jobs: |
| 8 | + format: |
| 9 | + name: Format code |
| 10 | + runs-on: ubuntu-latest |
| 11 | + if: github.event.pull_request.draft == false |
| 12 | + |
| 13 | + steps: |
| 14 | + - name: Determine if fork |
| 15 | + id: check_fork |
| 16 | + run: | |
| 17 | + if [ "${{ github.event.pull_request.head.repo.full_name }}" = "${{ github.repository }}" ]; then |
| 18 | + echo "is_fork=false" >> $GITHUB_OUTPUT |
| 19 | + else |
| 20 | + echo "is_fork=true" >> $GITHUB_OUTPUT |
| 21 | + fi |
| 22 | +
|
| 23 | + - name: Checkout code |
| 24 | + uses: actions/checkout@v4 |
| 25 | + with: |
| 26 | + token: ${{ steps.check_fork.outputs.is_fork == 'true' && secrets.GITHUB_TOKEN || secrets.TSCIRCUIT_BOT_GITHUB_TOKEN }} |
| 27 | + |
| 28 | + - name: Setup Node.js |
| 29 | + uses: actions/setup-node@v3 |
| 30 | + with: |
| 31 | + node-version: '20' |
| 32 | + |
| 33 | + - name: Get @biomejs/biome version |
| 34 | + id: get-biome-version |
| 35 | + run: echo "BIOME_VERSION=$(node -p "require('./package.json').devDependencies['@biomejs/biome']")" >> $GITHUB_OUTPUT |
| 36 | + |
| 37 | + - name: Install @biomejs/biome |
| 38 | + run: npm install @biomejs/biome@${{ steps.get-biome-version.outputs.BIOME_VERSION }} |
| 39 | + |
| 40 | + - name: Run Formatter and autofix |
| 41 | + if: steps.check_fork.outputs.is_fork == 'false' |
| 42 | + run: npx @biomejs/biome format . --write |
| 43 | + |
| 44 | + - name: Format Check (cannot autofix against forks) |
| 45 | + if: steps.check_fork.outputs.is_fork == 'true' |
| 46 | + run: npx @biomejs/biome format . |
| 47 | + |
| 48 | + - name: Restore lock files |
| 49 | + if: steps.check_fork.outputs.is_fork == 'false' |
| 50 | + run: | |
| 51 | + git checkout -- *lock.json || true |
| 52 | + git checkout -- *.lock || true |
| 53 | + git checkout -- *.lockb || true |
| 54 | +
|
| 55 | + - name: Commit changes |
| 56 | + if: steps.check_fork.outputs.is_fork == 'false' |
| 57 | + uses: stefanzweifel/git-auto-commit-action@v4 |
| 58 | + with: |
| 59 | + commit_message: "formatbot: Automatically format code" |
| 60 | + branch: ${{ github.head_ref }} |
| 61 | + commit_user_name: tscircuitbot |
| 62 | + commit_user_email: [email protected] |
| 63 | + commit_author: tscircuitbot <[email protected]> |
0 commit comments