-
Notifications
You must be signed in to change notification settings - Fork 24
170 lines (154 loc) · 4.9 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
## This workflow has been disabled for now, because the CKAN API is blocking our requests.
## Re-enable when we can package test data inside this repository.
name: "tests"
on:
# pull_request:
# branches:
# - main
# paths:
# - 'src/**/*.ts'
# - 'e2e/**/*.ts'
# - '*.json'
# - '*.js'
# - '*.mjs'
push:
branches:
- main
- develop
paths:
- 'src/**/*.ts'
- 'e2e/**/*.ts'
- '*.json'
- '*.js'
- '*.mjs'
workflow_dispatch:
jobs:
#
# 監視対象のファイルに変化があるかチェック
#
check-changes:
runs-on: ubuntu-latest
outputs:
has_changes: ${{ steps.check.outputs.has_changes }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 2 # 過去2つのコミットを取得
- name: Check if there are changes in specific paths
id: check
run: |
if git diff --quiet HEAD^ HEAD -- 'src/**/*.ts' 'e2e/**/*.ts' './*.json' './*.js' './*.mjs'; then
# ソースコードに変化がなければ false
echo "has_changes=false" >> $GITHUB_ENV
echo "::set-output name=has_changes::false"
echo "has_changes=false"
else
# ソースコードに変化があれば true
echo "has_changes=true" >> $GITHUB_ENV
echo "::set-output name=has_changes::true"
echo "has_changes=true"
fi
#
# 変化があった場合のみテストを行う
#
tests:
runs-on: ubuntu-latest
needs: check-changes
if: ${{ needs.check-changes.outputs.has_changes == 'true' }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 20
#
# src以下のファイルが変化していなければ、buildをrestoreする
#
- uses: actions/cache@v4
name: build_cache
id: build_cache
with:
path: |
build/
key: ${{ github.head_ref }}-build-${{ hashFiles('src/**/*.ts') }}
restore-keys: |
${{ github.head_ref }}-build-${{ hashFiles('src/**/*.ts') }}
#
# e2e/test-runner.ts に変化がなければ、db/downloadディレクトリのキャッシュをrestoreする
# jobが終了すると自動的にキャッシュされる
#
- uses: actions/cache@v4
name: e2e Download cache
id: e2e_download
with:
path: |
db/download
key: ${{ github.head_ref }}-e2e-${{ hashFiles('e2e/test-runner.ts') }}
restore-keys: |
${{ github.head_ref }}-e2e-${{ hashFiles('e2e/test-runner.ts') }}
#
# package.json に変化がなければ、node_modulesのキャッシュをrestoreする。
# jobが終了すると自動的にキャッシュされる
#
- uses: actions/cache@v4
name: Setup npm cache
id: node_modules
with:
path: |
node_modules/
key: ${{ github.head_ref }}-npm-${{ hashFiles('**/package.json') }}
restore-keys: |
${{ github.head_ref }}-npm-${{ hashFiles('**/package.json') }}
#
# node_modules のキャッシュキーがヒットしていなければ
# package.json に従ってインストールする
#
- name: Install dependencies
if: steps.node_modules.outputs.cache-hit != 'true'
run: |
npm install --global yarn
yarn install
#
# ESLintでコードの静的チェック
#
- name: Run eslint
uses: sibiraj-s/action-eslint@v3
with:
extensions: 'ts'
ignore-path: .eslintignore
ignore-patterns: |
build/
node_modules/
token: ${{ secrets.G_ACTIONS_TOKEN_FOR_PR }}
#
# Jestでユニットテスト
#
- name: Run tests
timeout-minutes: 3 # 3分でタイムアウト
run: npm run test
#
# e2eテスト (ビルドも含む)
#
- name: run e2e test
timeout-minutes: 10 # 10分でタイムアウト
run: npm run test:e2e
#
# コードカバレッジのレポートを作成
#
- name: create test report
uses: MishaKav/jest-coverage-comment@main
with:
github-token: ${{ secrets.G_ACTIONS_TOKEN_FOR_PR }}
summary-title: Coverage Summary
badge-title: Coverage
hide-comment: false
create-new-comment: false
hide-summary: false
coverage-summary-path: ./coverage/coverage-summary.json
junitxml-title: JUnit
junitxml-path: ./coverage/junit.xml
coverage-title: Coverage Details
coverage-path: ./coverage/coverage.txt
coverage-path-prefix: './src/'