Skip to content

Commit d8cd5d5

Browse files
committed
Update CI to run example apps and package format checks
1 parent d4ebdbd commit d8cd5d5

File tree

3 files changed

+107
-13
lines changed

3 files changed

+107
-13
lines changed

.github/workflows/build-and-test-types.yml

Lines changed: 92 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
name: CI
2-
on: [pull_request]
2+
3+
on:
4+
push:
5+
branches: [master]
6+
pull_request:
7+
branches: [master]
8+
39
jobs:
410
build:
511
name: Lint, Test, Report Coverage on Node ${{ matrix.node }}
6-
712
runs-on: ubuntu-latest
813
strategy:
914
matrix:
@@ -22,22 +27,26 @@ jobs:
2227
- name: Install dependencies
2328
run: yarn install
2429

30+
# Read existing version, reuse that, add a Git short hash
31+
- name: Set build version to Git commit
32+
run: node scripts/writeGitVersion.mjs $(git rev-parse --short HEAD)
33+
34+
- name: Check updated version
35+
run: jq .version package.json
36+
2537
- name: Run linter
2638
run: yarn lint
2739

2840
- name: Run tests
2941
run: yarn test
3042

31-
- name: Generate test coverage
32-
run: yarn test:cov
33-
34-
- name: Compile
35-
run: yarn build
43+
- name: Pack
44+
run: yarn pack
3645

37-
- name: Report to Codecov.io
38-
uses: codecov/codecov-action@v1
46+
- uses: actions/upload-artifact@v2
3947
with:
40-
files: ./coverage/lcov.info
48+
name: package
49+
path: ./package.tgz
4150

4251
test-types:
4352
name: Test Types with TypeScript ${{ matrix.ts }}
@@ -48,7 +57,7 @@ jobs:
4857
fail-fast: false
4958
matrix:
5059
node: ['16.x']
51-
ts: ['4.2', '4.3', '4.4', '4.5', '4.6', '4.7', '4.8', '4.9.2-rc']
60+
ts: ['4.2', '4.3', '4.4', '4.5', '4.6', '4.7', '4.8', '4.9', '5.0']
5261
steps:
5362
- name: Checkout repo
5463
uses: actions/checkout@v2
@@ -78,9 +87,80 @@ jobs:
7887

7988
# Remove config line that points "reselect" to the `src` folder,
8089
# so that the typetest will use the installed version instead
81-
- run: sed -i -e /@remap-prod-remove-line/d ./typescript_test/tsconfig.json
90+
- run: sed -i -e /@remap-prod-remove-line/d ./typescript_test/tsconfig.json vitest.config.ts
8291

8392
- name: Test types
8493
run: |
8594
./node_modules/.bin/tsc --version
8695
yarn test:typescript
96+
97+
test-published-artifact:
98+
name: Test Published Artifact ${{ matrix.example }}
99+
100+
needs: [build]
101+
runs-on: ubuntu-latest
102+
strategy:
103+
fail-fast: false
104+
matrix:
105+
node: ['16.x']
106+
example:
107+
[
108+
'cra4',
109+
'cra5',
110+
'next',
111+
'vite',
112+
'node-standard',
113+
'node-esm',
114+
'are-the-types-wrong'
115+
]
116+
steps:
117+
- name: Checkout repo
118+
uses: actions/checkout@v2
119+
120+
- name: Use node ${{ matrix.node }}
121+
uses: actions/setup-node@v2
122+
with:
123+
node-version: ${{ matrix.node }}
124+
cache: 'yarn'
125+
126+
- name: Clone RTK repo
127+
run: git clone https://github.com/reduxjs/redux-toolkit.git ./redux-toolkit
128+
129+
- name: Check folder contents
130+
run: ls -l .
131+
132+
- name: Install deps
133+
working-directory: ./redux-toolkit/examples/publish-ci/${{ matrix.example }}
134+
run: yarn install
135+
136+
- uses: actions/download-artifact@v2
137+
with:
138+
name: package
139+
path: ./redux-toolkit/examples/publish-ci/${{ matrix.example }}
140+
141+
- name: Check folder contents
142+
working-directory: ./redux-toolkit/examples/publish-ci/${{ matrix.example }}
143+
run: ls -l .
144+
145+
- name: Install build artifact
146+
working-directory: ./redux-toolkit/examples/publish-ci/${{ matrix.example }}
147+
run: yarn add ./package.tgz
148+
149+
- name: Show installed package versions
150+
working-directory: ./redux-toolkit/examples/publish-ci/${{ matrix.example }}
151+
run: yarn info reselect && yarn why reselect
152+
153+
- name: Build example
154+
working-directory: ./redux-toolkit/examples/publish-ci/${{ matrix.example }}
155+
run: yarn build
156+
157+
- name: Run test step
158+
working-directory: ./redux-toolkit/examples/publish-ci/${{ matrix.example }}
159+
run: yarn test
160+
if: matrix.example != 'are-the-types-wrong'
161+
162+
- name: Run test step (attw)
163+
working-directory: ./redux-toolkit/examples/publish-ci/${{ matrix.example }}
164+
# Ignore "FalseCJS" errors in the `attw` job
165+
run: yarn test -n FalseCJS
166+
if: matrix.example == 'are-the-types-wrong'

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"clean": "rimraf dist",
3434
"format": "prettier --write \"{src,test}/**/*.{js,ts}\" \"docs/**/*.md\"",
3535
"lint": "eslint src test",
36-
"prepublishOnly": "yarn build",
36+
"prepack": "yarn build",
3737
"test": "vitest run",
3838
"test:cov": "vitest run --coverage",
3939
"test:typescript": "tsc --noEmit -p typescript_test/tsconfig.json"

scripts/writeGitVersion.mjs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import path from 'path'
2+
import fs from 'fs'
3+
import { fileURLToPath } from 'node:url'
4+
5+
const __filename = fileURLToPath(import.meta.url)
6+
const __dirname = path.dirname(__filename)
7+
8+
const gitRev = process.argv[2]
9+
10+
const packagePath = path.join(__dirname, '../package.json')
11+
const pkg = JSON.parse(fs.readFileSync(packagePath))
12+
13+
pkg.version = `${pkg.version}-${gitRev}`
14+
fs.writeFileSync(packagePath, JSON.stringify(pkg, null, 2))

0 commit comments

Comments
 (0)