-
Notifications
You must be signed in to change notification settings - Fork 28
155 lines (128 loc) · 4.8 KB
/
test-publish.yaml
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
name: Test and Conditionally Publish
on:
push:
paths-ignore:
- '.anylint'
- '.editorconfig'
- '.env.example'
- '.gitattributes'
- '.gitignore'
- 'commitlint.config.js'
- 'LICENSE'
pull_request:
branches:
- master
paths-ignore:
- '.anylint'
- '.editorconfig'
- '.env.example'
- '.gitattributes'
- '.gitignore'
- 'commitlint.config.js'
- 'LICENSE'
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up pnpm
uses: pnpm/action-setup@v2
with:
run_install: false # For cache
# pnpm should be installed before the setup-node action. REF: https://github.com/actions/setup-node/issues/530
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: pnpm
- name: Install Dependencies
run: pnpm install --silent --frozen-lockfile --ignore-scripts
- name: Test
run: pnpm test
- name: Lint
run: pnpm eslint .
- name: Lint Markdown
run: pnpm markdownlint .
e2etest:
needs: test
runs-on: ${{ matrix.os }}
strategy:
matrix:
node-version: [18, 20, 22]
# [REF]: https://github.com/actions/runner-images
# Q. Why `macos-latest-large`(x86-64) instead of `macos-latest`(arm64)?
# A. Apple silicon does not support 'nested virtualization' yet,
# though support *will* be added from M3 + macOS 15.
# [REF]: https://github.com/douglascamata/setup-docker-macos-action
os: [ubuntu-latest, macos-latest-large, windows-latest, windows-2019]
steps:
- uses: actions/checkout@v4
- name: Set up pnpm
uses: pnpm/action-setup@v2
with:
run_install: false # For cache
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: pnpm
- name: Install Dependencies
run: pnpm install --silent --frozen-lockfile --ignore-scripts
- name: Setup Docker on macOS
# Currently, docker is not preinstalled on macos runner images.
if: startsWith(matrix.os, 'macos')
uses: douglascamata/setup-docker-macos-action@v1-alpha
- name: Run Local Npm Registry (Verdaccio) On Linux and macOS
if: startsWith(matrix.os, 'windows') == false
# verdaccio is private npm registry. [link](https://github.com/verdaccio/verdaccio/)
run: docker compose -f verdaccio/docker-compose.yaml up --wait
- name: Run Local Npm Registry (Verdaccio) On Windows
if: startsWith(matrix.os, 'windows')
# Q. Why not using docker?
# A. [REF](https://github.com/verdaccio/verdaccio/issues/4808)
run: |
pnpm add --global forever verdaccio
forever start verdaccio --config ./verdaccio/config.yaml
- name: Publish To Local NPM Registry
run: |
# From npm v7, `npm adduser` is required before `npm publish`.
# (adduser REF: https://docs.npmjs.com/cli/v7/commands/npm-adduser)
# However, `npm adduser` is interactive
# and can be substituted by setting `_authToken`.
# By local verdaccio setting(verdaccio/conf/default.yaml),
# the _authToken can be any random string,
# and verdaccio is configured to allowing anyone to publish `hasura-cli`.
npm config set //localhost:4873/:_authToken helloworld
npm run prepublishOnly
npm publish --registry http://localhost:4873
- name: Test Installation
run: |
npm install --global hasura-cli --registry http://localhost:4873
hasura version --skip-update-check
- name: Test Uninstallation
if: startsWith(matrix.os, 'windows') == false
run: npm uninstall --global hasura-cli
publish:
needs: e2etest
if: startsWith(github.ref, 'refs/tags/v2.') && ( github.event.base_ref == 'refs/heads/master' )
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up pnpm
uses: pnpm/action-setup@v2
with:
run_install: false # For cache
- name: Set Up Node.js
uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: pnpm
- name: Install Dependencies
run: pnpm install --silent --frozen-lockfile --ignore-scripts
- name: Build and Publish
# only runs if name of git tag starts with 'v1.' and on branch master
run: |
pnpm run prepublishOnly # to prevent a mistake though there is already prepublishOnly lifecycle hook.
pnpm publish
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}