-
-
Notifications
You must be signed in to change notification settings - Fork 1
122 lines (111 loc) · 4.38 KB
/
type-check.yml
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
114
115
116
117
118
119
120
121
122
name: Type Checks
on:
workflow_call:
inputs:
ts-prebuild-script:
description: 'The npm script used to prebuild.'
required: false
type: string
ts-versions:
description: 'A comma separated list of TypeScript versions that you want to test against.'
required: false
default: '4.5,4.6,4.7,4.8'
type: string
ts-libs:
description: 'A semi-colon separated list of TypeScript libs that you want to test against.'
required: false
default: 'es2020;esnext'
type: string
ts-projects:
description: 'A comma separated list of TypeScript project that you want to test.'
required: false
default: '.'
type: string
ts-working-directory:
description: 'Where the ts-projects are relative to.'
required: false
default: '.'
type: string
lockfile:
description: 'Whether to expect a lockfile or not'
required: false
default: false
type: boolean
permissions:
contents: read
jobs:
resolve_inputs:
name: Resolving inputs
runs-on: ubuntu-latest
outputs:
tsVersions: ${{ steps.split-ts-versions.outputs.splitted }}
tsLibs: ${{ steps.split-ts-libs.outputs.splitted }}
tsProjects: ${{ steps.split-ts-projects.outputs.splitted }}
steps:
- id: split-ts-versions
run: echo "splitted=$(echo '${{ inputs.ts-versions }}' | jq -R -c 'split(",")')" >> $GITHUB_OUTPUT
- id: split-ts-libs
run: echo "splitted=$(echo '${{ inputs.ts-libs }}' | jq -R -c 'split(";")')" >> $GITHUB_OUTPUT
- id: split-ts-projects
run: echo "splitted=$(echo '${{ inputs.ts-projects }}' | jq -R -c 'split(",")')" >> $GITHUB_OUTPUT
test:
name: TS ${{ matrix.ts_version }}, "${{ matrix.ts_lib }}", ${{ inputs.ts-working-directory }}/${{ matrix.ts_project }}
runs-on: ubuntu-latest
needs:
- resolve_inputs
strategy:
fail-fast: false
matrix:
node_version: [lts/*]
ts_version: ${{ fromJson(needs.resolve_inputs.outputs.tsVersions) }}
ts_lib: ${{ fromJson(needs.resolve_inputs.outputs.tsLibs) }}
ts_project: ${{ fromJson(needs.resolve_inputs.outputs.tsProjects) }}
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
show-progress: false
- name: Use Node.js ${{ matrix.node_version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node_version }}
registry-url: 'https://registry.npmjs.org'
- name: Determine npm cache directory windows
id: npm-cache-dir-windows
if: runner.os == 'Windows'
run: echo "dir=$(npm config get cache)" >> $env:GITHUB_OUTPUT
- name: Determine npm cache directory non-windows
id: npm-cache-dir
if: runner.os != 'Windows'
run: echo "dir=$(npm config get cache)" >> $GITHUB_OUTPUT
- uses: actions/cache@v4
with:
path: ${{ steps.npm-cache-dir-windows.outputs.dir || steps.npm-cache-dir.outputs.dir }}
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json', '**/package.json') }}
restore-keys: |
${{ runner.os }}-node-
- if: inputs.lockfile == false
run: npm install --ignore-scripts
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- if: inputs.lockfile == true
run: npm ci --ignore-scripts
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- run: npm rebuild && npm run prepare --if-present
- name: prebuild types
if: inputs.ts-prebuild-script
run: npm run ${{ inputs.ts-prebuild-script }}
- name: npm install working directory
if: inputs.ts-working-directory != '.'
run: npm install --ignore-scripts
working-directory: ${{ inputs.ts-working-directory }}
- name: install typescript version ${{ matrix.ts_version }}
run: npm install --force typescript@${{ matrix.ts_version }}
working-directory: ${{ inputs.ts-working-directory }}
- name: show installed typescript version
run: npm list typescript --depth=0
working-directory: ${{ inputs.ts-working-directory }}
- name: test using lib "${{ matrix.ts_lib }}"
run: npx tsc -p ${{ matrix.ts_project }} --lib ${{ matrix.ts_lib }}
working-directory: ${{ inputs.ts-working-directory }}