Skip to content

Commit f9ede04

Browse files
committed
Add lint workflow
1 parent 8e2c47c commit f9ede04

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

.github/workflows/lint.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Lint
2+
3+
on:
4+
pull_request:
5+
types: [ opened, synchronize, reopened ]
6+
7+
permissions: { }
8+
9+
jobs:
10+
lint:
11+
name: Lint with pnpm and comment results
12+
runs-on: ubuntu-latest
13+
permissions:
14+
contents: read
15+
pull-requests: write
16+
17+
steps:
18+
- name: Checkout repository
19+
uses: actions/checkout@v4
20+
21+
- name: Setup pnpm
22+
uses: pnpm/action-setup@v4
23+
with:
24+
run_install: false
25+
- name: Setup Node.js
26+
uses: actions/setup-node@v4
27+
with:
28+
node-version-file: .node-version
29+
cache: 'pnpm'
30+
31+
- name: Install dependencies
32+
run: pnpm install --frozen-lockfile
33+
- uses: oxc-project/[email protected]
34+
with:
35+
config: .oxlintrc.json
36+
- name: Run lint and capture output
37+
id: lint
38+
shell: bash
39+
run: |
40+
set -o pipefail
41+
pnpm exec lint 2>&1 | tee lint-output.txt
42+
echo "exit_code=${PIPESTATUS[0]}" >> $GITHUB_OUTPUT
43+
continue-on-error: true
44+
- name: Comment lint results on PR
45+
if: ${{ !cancelled() }}
46+
uses: actions/github-script@v7
47+
with:
48+
script: |
49+
const fs = require('fs');
50+
const output = fs.readFileSync('lint-output.txt', 'utf8');
51+
const exitCode = '${{ steps.lint.outputs.exit_code }}';
52+
const title = exitCode === '0' ? '✅ Lint passed' : '❌ Lint found issues';
53+
const body = `### ${title}\n\n<details><summary>Show output</summary>\n\n\`\`\`\n${output.slice(-60000)}\n\`\`\`\n\n</details>`;
54+
const { owner, repo } = context.repo;
55+
const issue_number = context.issue.number;
56+
if (!issue_number) {
57+
core.info('No pull request context detected, skipping comment.');
58+
} else {
59+
await github.rest.issues.createComment({ owner, repo, issue_number, body });
60+
}
61+
62+
- name: Fail if lint failed
63+
if: steps.lint.outputs.exit_code != '0'
64+
run: exit ${{ steps.lint.outputs.exit_code }}

0 commit comments

Comments
 (0)