|
| 1 | +# They only run in direct branches and are not available in forks. |
| 2 | +name: ✅ Checks with autofixes |
| 3 | + |
| 4 | +env: |
| 5 | + HUSKY: 0 |
| 6 | + NODE_VERSION: 20 |
| 7 | + |
| 8 | +on: |
| 9 | + check_run: |
| 10 | + types: [requested_action] |
| 11 | + # NOTE: created? then close? |
| 12 | + |
| 13 | +concurrency: |
| 14 | + group: ${{ github.workflow }}-${{ github.ref }}-checks |
| 15 | + cancel-in-progress: true |
| 16 | + |
| 17 | +permissions: |
| 18 | + contents: write |
| 19 | + checks: write |
| 20 | + |
| 21 | +jobs: |
| 22 | + format-fix: |
| 23 | + name: "Fix formatting" |
| 24 | + runs-on: ubuntu-latest |
| 25 | + if: | |
| 26 | + github.event.requested_action.identifier == 'btn_fmt' && |
| 27 | + ( |
| 28 | + github.event.pull_request.head.repo.fork == true || |
| 29 | + github.event.pull_request.head.repo.full_name != github.repository |
| 30 | + ) |
| 31 | + steps: |
| 32 | + - name: Checkout PR branch |
| 33 | + uses: actions/checkout@v4 |
| 34 | + with: |
| 35 | + ref: ${{ github.event.check_run.head_sha }} |
| 36 | + |
| 37 | + - name: Setup Node.js |
| 38 | + uses: actions/setup-node@v4 |
| 39 | + with: |
| 40 | + node-version: ${{ env.NODE_VERSION }} |
| 41 | + cache: "npm" |
| 42 | + |
| 43 | + - name: Install dependencies |
| 44 | + run: | |
| 45 | + corepack enable |
| 46 | + npm ci |
| 47 | +
|
| 48 | + - name: Get changed MDX and Markdown files |
| 49 | + id: changed-files |
| 50 | + uses: tj-actions/changed-files@24d32ffd492484c1d75e0c0b894501ddb9d30d62 # v47 |
| 51 | + with: |
| 52 | + files: | |
| 53 | + **.md |
| 54 | + **.mdx |
| 55 | + separator: " " |
| 56 | + |
| 57 | + - name: Apply formatting |
| 58 | + id: fix-fmt |
| 59 | + env: |
| 60 | + ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }} |
| 61 | + uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7.1.0 |
| 62 | + with: |
| 63 | + script: | |
| 64 | + const files = (process.env.ALL_CHANGED_FILES ?? '') |
| 65 | + .trim().split(' ').filter(Boolean).filter((it) => it.match(/\.mdx?$/) !== null); |
| 66 | + if (files.length === 0) { |
| 67 | + console.log('\nNo such files affected!'); |
| 68 | + process.exit(0); |
| 69 | + } |
| 70 | + try { |
| 71 | + await exec.exec('npm', ['run', 'check:fmt:some', '--', ...files], { |
| 72 | + silent: true, // >/dev/null 2>&1 |
| 73 | + }); |
| 74 | + console.log('\nNo issues'); |
| 75 | + core.setOutput('changes', 'false'); |
| 76 | + } catch (_) { |
| 77 | + console.log('\nFound issues, fixing...'); |
| 78 | + await exec.exec('npm', ['run', 'fmt:some', '--', ...files], { |
| 79 | + silent: true, // >/dev/null 2>&1 |
| 80 | + }); |
| 81 | + core.setOutput('changes', 'true'); |
| 82 | + } |
| 83 | +
|
| 84 | + - name: Commit changes, if any |
| 85 | + if: steps.fix-fmt.outputs.changes == 'true' |
| 86 | + uses: stefanzweifel/git-auto-commit-action@28e16e81777b558cc906c8750092100bbb34c5e3 # v7.0.0 |
| 87 | + with: |
| 88 | + commit_message: "fix: apply automatic changes" |
0 commit comments