-
-
Notifications
You must be signed in to change notification settings - Fork 678
209 lines (178 loc) · 5.81 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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
name: ci
on:
push:
branches: [master]
tags: ['^v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$']
pull_request:
branches: [master]
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
version:
name: Ensure package version match
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Read package.json version
uses: sergeysova/jq-action@v2
id: version_package
with:
cmd: jq --raw-output .version package.json
- name: Read GitHub version
uses: pozetroninc/github-action-get-latest-release@master
id: version_v_github
with:
owner: MichalLytek
repo: type-graphql
excludes: prerelease, draft
- name: Remove leading v* from GitHub version
id: version_github
run: |
_version="${{ steps.version_v_github.outputs.release }}"
printf 'value=%s\n' "${_version#?}" >> "$GITHUB_OUTPUT"
- name: Read Git tag version
id: version_gittag
run: |
_version="${{ github.ref_name }}"
printf 'value=%s\n' "${_version#?}" >> "$GITHUB_OUTPUT"
- name: Compare package.json with Git tag
uses: madhead/semver-utils@latest
id: comparison_package_gittag
with:
version: ${{ steps.version_package.outputs.value }}
compare-to: ${{ steps.version_gittag.outputs.value }}
lenient: false
- name: Compare Git tag with GitHub
uses: madhead/semver-utils@latest
id: comparison_gittag_github
with:
version: ${{ steps.version_gittag.outputs.value }}
compare-to: ${{ steps.version_github.outputs.value }}
lenient: false
- name: Check package.json == Git tag
run: |
if [ ! "${{ steps.comparison_package_gittag.outputs.comparison-result }}" = "=" ]; then
printf '[ERROR]: package.json (%s) != Git tag (%s)\n' "${{ steps.version_package.outputs.value }}" "${{ steps.version_gittag.outputs.value }}"
exit 1
fi
- name: Check Git tag > GitHub
run: |
if [ ! "${{ steps.comparison_gittag_github.outputs.comparison-result }}" = ">" ]; then
printf '[ERROR]: Git tag (%s) !> GitHub (%s)\n' "${{ steps.version_gittag.outputs.value }}" "${{ steps.version_github.outputs.value }}"
exit 1
fi
check:
name: Build & Lint & Tests
needs: version
if: always() && (needs.version.result == 'success' || needs.version.result == 'skipped')
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
node-version: [16.x, 18.x, 20.x]
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Install Dependencies
run: |
npm ci
- name: Build
run: |
npm run build
npm run build:benchmarks
- name: Check
run: |
npm run check
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Test
run: npm run test:ci
env:
CI: true
- name: Upload code coverage
uses: codecov/codecov-action@v3
if: matrix.node-version == '18.x'
release:
name: Release package on NPM
needs: check
if: needs.check.result == 'success' && startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: "18.x"
registry-url: "https://registry.npmjs.org"
- name: Install latest npm
run: |
npm install -g npm@latest
- name: Install Dependencies
run: |
npm ci
- name: Prepare package
run: |
npm run prepublishOnly
env:
TYPE_GRAPHQL_REF: ${{ github.ref_name }}
- name: Build Changelog
id: changelog
uses: mikepenz/release-changelog-builder-action@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
configuration: "./.github/configs/changelog.json"
owner: MichalLytek
repo: type-graphql
failOnError: true
- name: Release
uses: softprops/action-gh-release@v1
with:
body: ${{ steps.changelog.outputs.changelog }}
- name: Publish
run: |
npm publish --ignore-scripts
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
website:
name: Publish website
needs: check
if: needs.check.result == 'success' && github.event_name == 'push' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v'))
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: "18.x"
- name: Install Dependencies
run: |
npm ci
npm ci --prefix ./website
- name: Build
run: |
npm run build --prefix ./website
- name: Publish
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./website/build/type-graphql
user_name: "github-actions[bot]"
user_email: "github-actions[bot]@users.noreply.github.com"
full_commit_message: |
Deploy website based on ${{ github.sha }}