Skip to content

Commit fe813e1

Browse files
authored
ci(): Refactor GHA for reuse and caching (#9029)
1 parent 48cbf2f commit fe813e1

File tree

7 files changed

+151
-59
lines changed

7 files changed

+151
-59
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: 'Build fabric'
2+
description: 'Build fabric and cache result per commit'
3+
runs:
4+
using: 'composite'
5+
steps:
6+
- name: Get cache build
7+
id: build-cache
8+
uses: actions/cache@v3
9+
with:
10+
path: ./dist
11+
key: npm-${{ github.event.pull_request.head.sha }}
12+
- name: Build fabric.js dist folder
13+
if: steps.build-cache.outputs.cache-hit != 'true'
14+
run: npm run build -- -f
15+
shell: bash
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: 'Install fabric'
2+
description: 'Install dependencies from cache between different node versions'
3+
inputs:
4+
node-version:
5+
required: true
6+
description: 'the node version'
7+
install-system-deps:
8+
description: 'install node-canvas deps with apt-get'
9+
runs:
10+
using: 'composite'
11+
steps:
12+
- name: Install system deps for node canvas
13+
if: inputs.install-system-deps == 'true'
14+
run: sudo apt-get install libgif-dev libpng-dev libpango1.0-dev libjpeg8-dev librsvg2-dev libcairo2-dev
15+
shell: bash
16+
- name: Use Node.js v${{ inputs.node-version }}
17+
uses: actions/setup-node@v3
18+
with:
19+
node-version: ${{ inputs.node-version }}
20+
- name: Get npm cache directory
21+
id: npm-cache-dir
22+
run: |
23+
echo "dir=$(npm config get cache)" >> $GITHUB_OUTPUT
24+
shell: bash
25+
- name: Cache dependencies
26+
uses: actions/cache@v3
27+
with:
28+
path: ${{ steps.npm-cache-dir.outputs.dir }}
29+
key: npm-${{ inputs.node-version }}-${{ hashFiles('package-lock.json') }}
30+
restore-keys: npm-${{ inputs.node-version }}
31+
- run: npm ci --audit false --fund false
32+
shell: bash

.github/workflows/build.yml

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@ jobs:
99
build:
1010
runs-on: ubuntu-latest
1111
steps:
12-
- uses: actions/checkout@v3
1312
- name: Uglified build
14-
uses: actions/setup-node@v1
13+
uses: actions/checkout@v3
14+
- uses: ./.github/actions/cached-install
1515
with:
1616
node-version: 18.x
17-
- run: npm ci
1817
- run: npm run build
1918
stats:
2019
name: Build stats
@@ -72,38 +71,18 @@ jobs:
7271
lint:
7372
runs-on: ubuntu-latest
7473
steps:
75-
- uses: actions/checkout@v2
7674
- name: Linting
77-
uses: actions/setup-node@v1
75+
uses: actions/checkout@v3
76+
- uses: ./.github/actions/cached-install
7877
with:
7978
node-version: 18.x
80-
- run: npm ci
8179
- run: npm run lint
8280
prettier:
8381
runs-on: ubuntu-latest
8482
steps:
85-
- uses: actions/checkout@v2
8683
- name: Prettier check
87-
uses: actions/setup-node@v1
84+
uses: actions/checkout@v3
85+
- uses: ./.github/actions/cached-install
8886
with:
8987
node-version: 18.x
90-
- run: npm ci
9188
- run: npm run prettier:check
92-
coverage:
93-
if: ${{ always() }}
94-
runs-on: ubuntu-latest
95-
steps:
96-
- uses: actions/checkout@v2
97-
- name: Code Coverage Report Updater
98-
uses: actions/setup-node@v1
99-
with:
100-
node-version: 18.x
101-
- run: npm ci
102-
- run: npm run build -- -f
103-
- run: npm run test:coverage && npm run test:visual:coverage
104-
- run: npm run coverage:report
105-
- uses: ShaMan123/[email protected]
106-
with:
107-
github-token: ${{ secrets.GITHUB_TOKEN }}
108-
delete-old-comments: true
109-
update-comment: true

.github/workflows/tests.yml

Lines changed: 90 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,49 @@ on:
88
paths-ignore: [CHANGELOG.md]
99

1010
jobs:
11+
prime-build:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v3
15+
- name: Install dependencies
16+
uses: ./.github/actions/cached-install
17+
with:
18+
node-version: 18.x
19+
install-system-deps: true
20+
- name: Build fabric.js
21+
uses: ./.github/actions/build-fabric-cached
22+
node-coverage:
23+
needs: [prime-build]
24+
runs-on: ubuntu-latest
25+
name: Node 18.x ${{ matrix.suite }} tests
26+
strategy:
27+
fail-fast: false
28+
matrix:
29+
# For more information see:
30+
# https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
31+
# supported Node.js release schedule: https://nodejs.org/en/about/releases/
32+
suite: [unit, visual]
33+
steps:
34+
- uses: actions/checkout@v3
35+
- uses: ./.github/actions/cached-install
36+
with:
37+
node-version: 18.x
38+
install-system-deps: true
39+
- name: Build fabric.js
40+
uses: ./.github/actions/build-fabric-cached
41+
- name: Run ${{ matrix.suite }} tests with coverage
42+
if: matrix.suite == 'unit'
43+
run: npm run test:coverage
44+
- name: Run ${{ matrix.suite }} tests with coverage
45+
if: matrix.suite == 'visual'
46+
run: npm run test:visual:coverage
47+
- name: Upload test coverage
48+
uses: actions/upload-artifact@v3
49+
with:
50+
name: coverage-${{ matrix.suite }}
51+
path: .nyc_output/*.json
1152
browser:
53+
needs: [prime-build]
1254
name: ${{ matrix.target }} ${{ matrix.suite }} tests
1355
runs-on: ubuntu-latest
1456
strategy:
@@ -18,18 +60,19 @@ jobs:
1860
suite: [unit, visual]
1961
fail-fast: false
2062
steps:
21-
- uses: actions/checkout@v2
22-
- name: Unit tests on Chrome
23-
uses: actions/setup-node@v1
63+
- name: Unit tests on browser ${{ matrix.target }}
64+
uses: actions/checkout@v3
65+
- uses: ./.github/actions/cached-install
2466
with:
2567
node-version: ${{ matrix.node-version }}
26-
- run: npm ci
27-
- run: npm run build -- -f
68+
- name: Build fabric.js
69+
uses: ./.github/actions/build-fabric-cached
2870
- name: Run ${{ matrix.target }} ${{ matrix.suite }} headless test
29-
uses: GabrielBB/xvfb-action@v1
71+
uses: coactions/setup-xvfb@v1
3072
with:
3173
run: npm run test -- -c ${{ matrix.target }} -s ${{ matrix.suite }}
3274
node:
75+
needs: [prime-build]
3376
runs-on: ubuntu-latest
3477
name: Node ${{ matrix.node-version }} ${{ matrix.suite }} tests
3578
strategy:
@@ -38,32 +81,56 @@ jobs:
3881
# For more information see:
3982
# https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
4083
# supported Node.js release schedule: https://nodejs.org/en/about/releases/
41-
node-version: [14.x, 16.x, 18.x]
84+
node-version: [14.x, 16.x, 20.x]
4285
suite: [unit, visual]
4386
steps:
44-
- uses: actions/checkout@v2
45-
- name: Install node-canvas
46-
run: sudo apt-get install libgif-dev libpng-dev libpango1.0-dev libjpeg8-dev librsvg2-dev libcairo2-dev
47-
- name: Use Node.js ${{ matrix.node-version }}
48-
uses: actions/setup-node@v1
87+
- uses: actions/checkout@v3
88+
- uses: ./.github/actions/cached-install
4989
with:
5090
node-version: ${{ matrix.node-version }}
51-
- run: npm ci
52-
- name: Build
53-
run: npm run build -- -f
91+
install-system-deps: true
92+
- name: Build fabric.js
93+
uses: ./.github/actions/build-fabric-cached
5494
- name: Run ${{ matrix.suite }} tests
5595
run: npm run test -- -c node -s ${{ matrix.suite }}
5696
jest:
5797
name: Jest tests
5898
runs-on: ubuntu-latest
5999
steps:
60-
- uses: actions/checkout@v2
61-
- name: Install node-canvas
62-
run: sudo apt-get install libgif-dev libpng-dev libpango1.0-dev libjpeg8-dev librsvg2-dev libcairo2-dev
63-
- name: Use Node.js v18
64-
uses: actions/setup-node@v1
100+
- uses: actions/checkout@v3
101+
- uses: ./.github/actions/cached-install
65102
with:
66-
node-version: 18
67-
- run: npm ci
103+
node-version: 18.x
104+
install-system-deps: true
68105
- name: Run Jest unit test
69-
run: npm run test:jest
106+
run: npm run test:jest:coverage
107+
- name: Upload test coverage
108+
uses: actions/upload-artifact@v3
109+
with:
110+
name: coverage-jest
111+
path: .nyc_output/*.json
112+
coverage:
113+
needs: [node-coverage]
114+
name: Coverage reporting
115+
runs-on: ubuntu-latest
116+
steps:
117+
- uses: actions/checkout@v3
118+
- uses: ./.github/actions/cached-install
119+
with:
120+
node-version: 18.x
121+
install-system-deps: false
122+
- uses: actions/download-artifact@v3
123+
with:
124+
name: coverage-unit
125+
path: .nyc_output
126+
- uses: actions/download-artifact@v3
127+
with:
128+
name: coverage-visual
129+
path: .nyc_output
130+
- run: ls -l .nyc_output
131+
- run: npm run coverage:report
132+
- uses: ShaMan123/[email protected]
133+
with:
134+
github-token: ${{ secrets.GITHUB_TOKEN }}
135+
delete-old-comments: true
136+
update-comment: true

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## [next]
44

5+
- ci() Refactor GHA actions for caching and reuse [#9029](https://github.com/fabricjs/fabric.js/pull/9029)
56
- ci(): install dev deps types [#9039](https://github.com/fabricjs/fabric.js/pull/9039)
67

78
## [6.0.0-beta10]

jest.config.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,16 @@ module.exports = {
2020
collectCoverage: false,
2121

2222
// An array of glob patterns indicating a set of files for which coverage information should be collected
23-
// collectCoverageFrom: undefined,
23+
collectCoverageFrom: undefined,
2424

2525
// The directory where Jest should output its coverage files
26-
coverageDirectory: 'coverage',
26+
coverageDirectory: '.nyc_output',
2727

2828
// An array of regexp pattern strings used to skip coverage collection
29-
// coveragePathIgnorePatterns: [
30-
// "/node_modules/"
31-
// ],
29+
coveragePathIgnorePatterns: ['/node_modules/'],
3230

33-
// Indicates which provider should be used to instrument code for coverage
34-
// coverageProvider: "babel",
31+
// Indicates which provider should be used to instrument code for coverage (babel)
32+
coverageProvider: 'v8',
3533

3634
// A list of reporter names that Jest uses when writing coverage reports
3735
coverageReporters: [

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@
5757
"test:visual-browser": "npm run test -- -s visual -p 8081 -l -c chrome firefox",
5858
"test:coverage": "nyc --silent qunit test/node_test_setup.js test/lib test/unit",
5959
"test:visual:coverage": "nyc --silent --no-clean qunit test/node_test_setup.js test/lib test/visual",
60-
"test:jest:coverage": "jest --coverage=true --coverageDirectory=./.temp_coverage",
61-
"coverage:merge": "nyc merge .temp_coverage .nyc_output/merged-coverage.json",
60+
"test:jest:coverage": "jest --coverage=true",
61+
"coverage:merge": "nyc merge coveragefiles .nyc_output/merged-coverage.json",
6262
"local-server": "http-server ./ -d=false",
6363
"test:e2e": "npx playwright test --headed",
6464
"coverage:report": "nyc report --reporter=lcov --reporter=text",

0 commit comments

Comments
 (0)