Skip to content

Commit b8584f3

Browse files
authored
chore: run lint without installing the repo (#757)
1 parent 0c03bb1 commit b8584f3

2 files changed

Lines changed: 35 additions & 6 deletions

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,10 @@ jobs:
3232

3333
- uses: pnpm/action-setup@1e1c8eafbd745f64b1ef30a7d7ed7965034c486c
3434
name: Install pnpm
35-
with:
36-
cache: true
37-
38-
- name: 📦 Install dependencies
39-
run: pnpm install
35+
# pnpm cache skipped deliberately as the project is not actually installed here
4036

4137
- name: 🔠 Lint project
42-
run: pnpm lint
38+
run: node scripts/lint.ts
4339

4440
test:
4541
runs-on: ubuntu-latest

scripts/lint.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* This script runs oxlint and oxfmt in a CI environment, without the need to install the entire
3+
* project. It reads the required version from pnpm-lock.yaml and executes the linters accordingly.
4+
* It's "stupid by design" so it could work in minimal Node.js environments.
5+
*/
6+
7+
import { spawnSync } from 'node:child_process'
8+
9+
function getDependencyVersion(dependencyName: string): string {
10+
const result = spawnSync('npm', ['pkg', 'get', `devDependencies.${dependencyName}`], {
11+
encoding: 'utf8',
12+
})
13+
14+
if (result.status) {
15+
throw new Error(`Command failed: pnpm info ${dependencyName} version`)
16+
}
17+
18+
return JSON.parse(result.stdout)
19+
}
20+
21+
function runCommand(command: string, args: string[]) {
22+
const result = spawnSync(command, args, { stdio: 'inherit' })
23+
24+
if (result.status) {
25+
throw new Error(`Command failed: ${command} ${args.join(' ')}`)
26+
}
27+
}
28+
29+
const oxlintVersion = getDependencyVersion('oxlint')
30+
const oxfmtVersion = getDependencyVersion('oxfmt')
31+
32+
runCommand('pnpx', [`oxlint@${oxlintVersion}`])
33+
runCommand('pnpx', [`oxfmt@${oxfmtVersion}`, '--check'])

0 commit comments

Comments
 (0)