forked from apache/echarts
-
Notifications
You must be signed in to change notification settings - Fork 0
129 lines (105 loc) · 3.6 KB
/
ci.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
123
124
125
126
127
128
129
name: Node CI
on:
pull_request:
types: [opened, reopened, synchronize]
concurrency:
# Note that the `teardown-pr-preview` workflow needs the same group name
# to cancel the running `ci` workflows
group: ${{ github.workflow }}-${{ github.event.number }}
cancel-in-progress: true
jobs:
lint:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x]
steps:
- name: Fetch commit count
env:
PR_COMMIT_COUNT: ${{ github.event.pull_request.commits }}
run: |
echo "FETCH_DEPTH=$(($PR_COMMIT_COUNT + 1))" >> $GITHUB_ENV
- uses: actions/checkout@v4
with:
fetch-depth: ${{ env.FETCH_DEPTH }}
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Cache node modules
id: cache-dep
uses: actions/cache@v3
env:
cache-name: cache-node-modules
with:
path: node_modules
key: ${{ runner.os }}-lint-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
- name: Install dependencies
if: steps.cache-dep.outputs.cache-hit != 'true'
run: npm ci
- name: Collect changed files
run: |
mkdir ~/tmp/
git diff ${{ github.event.pull_request.base.sha }} ${{ github.sha }} --diff-filter=ACM --name-only --relative '*src/**/*.ts' > ~/tmp/changed_files
echo -e "Changed files: \n$(cat ~/tmp/changed_files)"
- name: Lint
run: npx eslint $(cat ~/tmp/changed_files)
- name: Check types
run: npm run checktype
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x]
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Cache node modules
id: cache-dep
uses: actions/cache@v3
env:
cache-name: cache-node-modules
with:
path: node_modules
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
- name: Install dependencies
if: steps.cache-dep.outputs.cache-hit != 'true'
run: npm ci
- name: Unit Test
run: npm run test
- name: Build release
run: npm run release
- name: Test generated DTS
run: npm run test:dts
- name: Pack npm tarball
if: ${{ github.repository_owner == 'apache' }}
id: pack-tarball
run: |
export PR_PREVIEW_DIR='echarts-pr-preview'
mkdir -p $PR_PREVIEW_DIR
npm pack -pack-destination $PR_PREVIEW_DIR
echo "PR_PREVIEW_DIR=$PR_PREVIEW_DIR" >> $GITHUB_ENV
- name: Save PR metadata and dist files
if: ${{ steps.pack-tarball.outcome == 'success' }}
id: save-pr-data
env:
PR_NUMBER: ${{ github.event.number }}
PR_COMMIT_SHA: ${{ github.event.pull_request.head.sha }}
PR_PREVIEW_DIR: ${{ env.PR_PREVIEW_DIR }}
run: |
cd $PR_PREVIEW_DIR
echo $PR_NUMBER > ./pr_number
echo $PR_COMMIT_SHA > ./pr_commit_sha
find . -type f -regex ".*\.tgz" -exec tar xvzf {} \;
rm -f *.tgz
echo -e "Dist files: \n$(ls -l)"
- uses: actions/upload-artifact@v3
if: ${{ steps.save-pr-data.outcome == 'success' }}
with:
name: pr_preview
path: ${{ env.PR_PREVIEW_DIR }}
retention-days: 1
if-no-files-found: error