Skip to content

Commit 91d3351

Browse files
committed
ci(ts): add dedicated TS CI workflow (guarded, pnpm fallback)
1 parent 6701538 commit 91d3351

File tree

1 file changed

+84
-53
lines changed

1 file changed

+84
-53
lines changed

.github/workflows/ts-ci.yml

Lines changed: 84 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,106 @@
1-
name: "TypeScript/Node CI (reusable)"
1+
name: TS CI
22

33
on:
4-
workflow_call:
5-
inputs:
6-
node_versions:
7-
type: string
8-
required: false
9-
default: '["22.x"]'
10-
os:
11-
type: string
12-
required: false
13-
default: '["ubuntu-latest"]'
14-
package_manager:
15-
type: string
16-
required: false
17-
default: pnpm
18-
test_command:
19-
type: string
20-
required: false
21-
default: 'pnpm -s test || echo "no tests"'
4+
push:
5+
paths:
6+
- "**/*.ts"
7+
- "**/*.tsx"
8+
- "package.json"
9+
- "pnpm-lock.yaml"
10+
- "eslint.*"
11+
- ".eslintrc.*"
12+
- "tsconfig*.json"
13+
pull_request:
14+
paths:
15+
- "**/*.ts"
16+
- "**/*.tsx"
17+
- "package.json"
18+
- "pnpm-lock.yaml"
19+
- "eslint.*"
20+
- ".eslintrc.*"
21+
- "tsconfig*.json"
22+
workflow_dispatch:
2223

2324
permissions:
2425
contents: read
2526

26-
concurrency:
27-
group: ${{ github.workflow }}-${{ github.ref }}
28-
cancel-in-progress: true
29-
3027
jobs:
31-
build:
32-
name: node${{ matrix.node }} • ${{ matrix.os }}
33-
runs-on: ${{ matrix.os }}
34-
strategy:
35-
fail-fast: false
36-
matrix:
37-
node: ${{ fromJson(inputs.node_versions) }}
38-
os: ${{ fromJson(inputs.os) }}
39-
28+
ts:
29+
name: "ts / node 22.x • ubuntu-latest"
30+
runs-on: ubuntu-latest
31+
continue-on-error: true
4032
steps:
4133
- uses: actions/checkout@v4
4234

43-
- name: Guard — skip if no Node project
35+
- name: Detect Node workspace
4436
id: guard
4537
shell: bash
4638
run: |
47-
if find -L . -type f -name package.json \
48-
-not -path "./.git/*" -not -path "*/node_modules/*" \
49-
-print -quit | grep -q .; then
50-
echo "has_pkg=true" >> "$GITHUB_OUTPUT"
39+
if find . -type f -name package.json -print -quit | grep -q .; then
40+
echo "HAS_NODE=1" >> "$GITHUB_ENV"
5141
else
52-
echo "has_pkg=false" >> "$GITHUB_OUTPUT"
42+
echo "HAS_NODE=0" >> "$GITHUB_ENV"
5343
fi
5444
55-
- uses: actions/setup-node@v4
56-
if: ${{ steps.guard.outputs.has_pkg == 'true' }}
45+
- if: ${{ env.HAS_NODE == '1' }}
46+
uses: actions/setup-node@v4
5747
with:
58-
node-version: ${{ matrix.node }}
59-
cache: ${{ inputs.package_manager }}
48+
node-version: 22.x
49+
cache: pnpm
6050

61-
- name: Install
62-
if: ${{ steps.guard.outputs.has_pkg == 'true' }}
51+
- if: ${{ env.HAS_NODE == '1' }}
52+
name: Ensure pnpm
6353
shell: bash
6454
run: |
6555
corepack enable || true
66-
case "${{ inputs.package_manager }}" in
67-
pnpm) pnpm i --frozen-lockfile || pnpm i ;;
68-
npm) npm ci || npm i ;;
69-
yarn) yarn install --frozen-lockfile || yarn install ;;
70-
*) echo "unknown package manager: ${{ inputs.package_manager }}" ;;
71-
esac
56+
corepack prepare pnpm@latest --activate || true
57+
if ! command -v pnpm >/dev/null; then
58+
npm i -g pnpm@9 || true
59+
fi
60+
pnpm -v || true
61+
62+
- if: ${{ env.HAS_NODE == '1' }}
63+
name: Install deps (pnpm)
64+
shell: bash
65+
run: |
66+
if [ -f pnpm-lock.yaml ]; then
67+
pnpm i --frozen-lockfile || true
68+
else
69+
echo "no pnpm lock; skip install"
70+
fi
71+
72+
- if: ${{ env.HAS_NODE == '1' }}
73+
name: Type check (tsc --noEmit if tsconfig present)
74+
shell: bash
75+
run: |
76+
if [ -f tsconfig.json ] || ls -1 tsconfig.*.json >/dev/null 2>&1; then
77+
npx -y typescript@latest --version
78+
npx -y tsc --noEmit
79+
else
80+
echo "no tsconfig; skip tsc"
81+
fi
82+
83+
- if: ${{ env.HAS_NODE == '1' }}
84+
name: Lint (eslint if config present)
85+
shell: bash
86+
run: |
87+
if ls -1 .eslintrc.* eslint.config.* >/dev/null 2>&1; then
88+
npx -y eslint . --max-warnings=0
89+
else
90+
echo "no eslint config; skip eslint"
91+
fi
7292
73-
- name: Test
74-
if: ${{ steps.guard.outputs.has_pkg == 'true' && inputs.test_command != '' }}
75-
run: ${{ inputs.test_command }}
93+
- if: ${{ env.HAS_NODE == '1' }}
94+
name: Tests (pnpm test if exists)
95+
shell: bash
96+
run: |
97+
if [ -f package.json ] && node -e "p=require('./package.json');process.exit(p.scripts&&p.scripts.test?0:1)"; then
98+
pnpm -s test || true
99+
else
100+
echo "no tests"
101+
fi
102+
103+
- if: ${{ env.HAS_NODE != '1' }}
104+
name: Skip (no Node workspace)
105+
run: |
106+
echo "skip ts-ci: no Node workspace"

0 commit comments

Comments
 (0)