forked from MattFisher/python-project-template
-
Notifications
You must be signed in to change notification settings - Fork 0
113 lines (105 loc) · 4.05 KB
/
Copy pathnode-ci.yml
File metadata and controls
113 lines (105 loc) · 4.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
name: Node CI
# Reusable CI for the TypeScript/JavaScript side of Generality Labs projects:
# install, type-check, and build. Consumers call it from a thin workflow — see
# the scaffolded `.github/workflows/ci.yml`.
#
# Lint and format are deliberately NOT here. Biome runs as a pre-commit hook,
# and `python-ci.yml` already runs the whole pre-commit stack, so a hybrid repo
# gets TS lint/format without paying for a second Node job. This workflow only
# covers the parts that genuinely need the project's own dependencies
# installed.
on:
workflow_call:
inputs:
node-version:
description: Node version to run against.
type: string
default: "22"
runs-on:
description: Runner to execute on (lets callers matrix over OSes).
type: string
default: ubuntu-latest
working-directory:
description: >
Directory holding package.json. Defaults to the repo root; set to
e.g. "frontend" for a Django/Vite repo where the frontend is a
subdirectory.
type: string
default: "."
package-manager:
description: One of yarn, npm, or pnpm.
type: string
default: yarn
lfs:
description: >
Fetch Git LFS objects during checkout. Off by default: LFS pulls cost
bandwidth against the account quota on every run. Turn it on for a
repo whose tests read LFS-tracked fixtures — without it they get the
pointer files, and fail with whatever the reading library says about
malformed input rather than anything about LFS.
type: boolean
default: false
run-build:
description: Run the build script after type-checking.
type: boolean
default: true
permissions:
contents: read
jobs:
ci:
name: Type-check and build
runs-on: ${{ inputs.runs-on }}
permissions:
contents: read
defaults:
run:
working-directory: ${{ inputs.working-directory }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
lfs: ${{ inputs.lfs }}
# Honours the `packageManager` field in package.json, which is how Yarn
# Berry and pnpm pin themselves.
#
# This MUST come before setup-node. With `cache` set, setup-node probes
# the package manager for its cache folder — for Yarn that means
# `yarn config get cacheFolder`, which fails when package.json pins
# yarn 4 and the runner's bare `yarn` is still 1.x. Enabling corepack
# first (with the runner's pre-installed Node) gives it a yarn that can
# answer. Verified in CI: with the steps the other way round, setup-node
# failed outright.
- name: Enable corepack
working-directory: ${{ github.workspace }}
run: corepack enable
- uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
with:
node-version: ${{ inputs.node-version }}
cache: ${{ inputs.package-manager }}
# Listing all three lockfile names keeps one workflow working for
# every package manager; only the project's own file will match.
cache-dependency-path: |
${{ inputs.working-directory }}/yarn.lock
${{ inputs.working-directory }}/package-lock.json
${{ inputs.working-directory }}/pnpm-lock.yaml
- name: Install dependencies
env:
PM: ${{ inputs.package-manager }} # via env to avoid run-step template injection
run: |
case "$PM" in
yarn) yarn install --immutable ;;
npm) npm ci ;;
pnpm) pnpm install --frozen-lockfile ;;
*) echo "::error::unsupported package-manager: $PM"; exit 1 ;;
esac
- name: Type-check
env:
PM: ${{ inputs.package-manager }}
run: |
"$PM" run typecheck
- name: Build
if: ${{ inputs.run-build }}
env:
PM: ${{ inputs.package-manager }}
run: |
"$PM" run build