|
| 1 | +name: Lint |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [ opened, synchronize, reopened ] |
| 6 | + |
| 7 | +permissions: { } |
| 8 | +env: |
| 9 | + CI: 'true' |
| 10 | + DO_NOT_TRACK: '1' |
| 11 | + NEXT_TELEMETRY_DISABLED: '1' |
| 12 | +concurrency: |
| 13 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 14 | + cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} |
| 15 | + |
| 16 | +jobs: |
| 17 | + lint: |
| 18 | + name: Lint app |
| 19 | + runs-on: ubuntu-latest |
| 20 | + permissions: |
| 21 | + contents: read |
| 22 | + pull-requests: write |
| 23 | + |
| 24 | + steps: |
| 25 | + - name: Checkout repository |
| 26 | + uses: actions/checkout@v4 |
| 27 | + |
| 28 | + - name: Setup pnpm |
| 29 | + uses: pnpm/action-setup@v4 |
| 30 | + with: |
| 31 | + run_install: false |
| 32 | + - name: Setup Node.js |
| 33 | + uses: actions/setup-node@v4 |
| 34 | + with: |
| 35 | + node-version-file: .node-version |
| 36 | + cache: 'pnpm' |
| 37 | + |
| 38 | + - name: Install dependencies |
| 39 | + run: pnpm install --frozen-lockfile |
| 40 | + - uses: oxc-project/[email protected] |
| 41 | + with: |
| 42 | + config: .oxlintrc.json |
| 43 | + - name: Run lint and capture output |
| 44 | + id: lint |
| 45 | + shell: bash |
| 46 | + run: | |
| 47 | + set -o pipefail |
| 48 | + pnpm run lint 2>&1 | tee lint-output.txt |
| 49 | + echo "exit_code=${PIPESTATUS[0]}" >> $GITHUB_OUTPUT |
| 50 | + continue-on-error: true |
| 51 | + - name: Comment lint results on PR |
| 52 | + if: ${{ !cancelled() }} |
| 53 | + uses: actions/github-script@v7 |
| 54 | + with: |
| 55 | + script: | |
| 56 | + const fs = require('fs'); |
| 57 | + const output = fs.readFileSync('lint-output.txt', 'utf8'); |
| 58 | + const exitCode = '${{ steps.lint.outputs.exit_code }}'; |
| 59 | + const title = exitCode === '0' ? '✅ Lint passed' : '❌ Lint found issues'; |
| 60 | + const marker = '<!-- lint-report:adev-nextjs-blog -->'; |
| 61 | + const body = `${marker}\n### ${title}\n\n<details><summary>Show output</summary>\n\n\`\`\`\n${output.slice(-60000)}\n\`\`\`\n\n</details>`; |
| 62 | + const { owner, repo } = context.repo; |
| 63 | + const issue_number = context.issue.number; |
| 64 | + if (!issue_number) { |
| 65 | + core.info('No pull request context detected, skipping comment.'); |
| 66 | + } else { |
| 67 | + // Find existing comment with the marker and update it; otherwise create a new one |
| 68 | + const comments = await github.paginate(github.rest.issues.listComments, { |
| 69 | + owner, |
| 70 | + repo, |
| 71 | + issue_number, |
| 72 | + per_page: 100, |
| 73 | + }); |
| 74 | + const existing = comments.find(c => typeof c.body === 'string' && c.body.includes(marker)); |
| 75 | + if (existing) { |
| 76 | + await github.rest.issues.updateComment({ owner, repo, comment_id: existing.id, body }); |
| 77 | + } else { |
| 78 | + await github.rest.issues.createComment({ owner, repo, issue_number, body }); |
| 79 | + } |
| 80 | + } |
| 81 | + - name: Fail if lint failed |
| 82 | + if: steps.lint.outputs.exit_code != '0' && !cancelled() |
| 83 | + run: exit ${{ steps.lint.outputs.exit_code }} |
| 84 | + - name: Build |
| 85 | + run: pnpm run build --no-lint |
| 86 | + env: |
| 87 | + SKIP_T3_ENV_VALIDATION: 'true' |
0 commit comments