-
Notifications
You must be signed in to change notification settings - Fork 57
192 lines (168 loc) · 5.31 KB
/
lib-ms.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
name: Library microservice
on:
push:
paths:
- 'servers/lib/**'
pull_request:
paths:
- 'servers/lib/**'
workflow_dispatch:
env:
NODE_VERSION: 20
jobs:
test-lib-ms:
name: Test library microservice
strategy:
matrix:
os: [windows-latest, ubuntu-latest]
runs-on: ${{ matrix.os }}
defaults:
run:
working-directory: servers/lib
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup node
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: "yarn"
cache-dependency-path: "**/yarn.lock"
- name: Install pm2 and jest
run: |
npm install -g pm2
npm install -g jest
- name: Run the linting checks and formatting
run: |
yarn install
yarn syntax
yarn format
- name: Build the lib microservice
run: |
yarn build
- name: Run all tests
env:
PORT: 4001
LOCAL_PATH: ${{ github.workspace }}/files
MODE: local
LOG_LEVEL: debug
APOLLO_PATH: /lib
run: |
yarn build
yarn test:all
- name: Start http mode
env:
PORT: 4003
LOCAL_PATH: ${{ github.workspace }}/files
MODE: local
LOG_LEVEL: debug
APOLLO_PATH: /lib
run: |
yarn build
yarn start:pm2
- name: Check server is running (Windows)
if: runner.os == 'Windows'
env:
PORT: 4003
uses: nick-fields/retry@v3
with:
timeout_seconds: 10
max_attempts: 4
command: "Invoke-WebRequest -Uri http://localhost:${{ env.PORT }}/lib/files -Method Head -UseBasicParsing"
- name: Check server is running (Linux)
if: runner.os != 'Windows'
env:
PORT: 4003
uses: nick-fields/retry@v3
with:
timeout_seconds: 10
max_attempts: 4
command: "curl -f -LI http://localhost:${{ env.PORT }}/lib/files"
- name: Run http test
env:
PORT: 4003
LOCAL_PATH: ${{ github.workspace }}/files
MODE: local
LOG_LEVEL: debug
APOLLO_PATH: /lib
run: |
yarn test:http-github
- name: Stop http mode
run: |
yarn stop:pm2
- name: Upload test coverage to Codecov
uses: codecov/codecov-action@v3
with:
files: servers/lib/coverage/clover.xml
flags: lib-microservice-tests
get_version:
name: Get version and variables
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Install jq
run: sudo apt-get install -y jq
- name: get version
id: get_version
run: |
version=`cat ./servers/lib/package.json | jq -r '.version'`
echo "version=$version" >> $GITHUB_OUTPUT
echo "node-version=$NODE_VERSION" >> $GITHUB_OUTPUT
outputs:
version: ${{ steps.get_version.outputs.version }}
node-version: ${{ steps.get_version.outputs.node-version }}
publish-package-github:
if: |
(startsWith(github.ref, 'refs/heads/feature/') || startsWith(github.ref, 'refs/heads/release-v'))
name: Publish to GitHub Packages
needs: [get_version,test-lib-ms]
uses: ./.github/workflows/publish-npm.yml
with:
node-version: ${{ needs.get_version.outputs.node-version }}
registry-url: 'https://npm.pkg.github.com/'
directory: servers/lib
package-name: ${{ vars.NPM_LIBMS_PACKAGE_NAME || '' }}
secrets:
NPM_TOKEN: ${{ secrets.GITHUB_TOKEN }}
publish-package-npm:
if: |
(startsWith(github.ref, 'refs/heads/feature/') || startsWith(github.ref, 'refs/heads/release-v'))
name: Publish to NPM
needs: [get_version,test-lib-ms]
uses: ./.github/workflows/publish-npm.yml
with:
node-version: ${{ needs.get_version.outputs.node-version }}
registry-url: 'https://registry.npmjs.org'
directory: servers/lib
package-name: ${{ vars.NPM_LIBMS_PACKAGE_NAME || '' }}
secrets:
NPM_TOKEN: ${{ secrets.NPM_TOKEN}}
publish-docker-image-ghcr:
if: |
github.event_name == 'push' &&
(startsWith(github.ref, 'refs/heads/feature/') || startsWith(github.ref, 'refs/heads/release-v'))
name: Publish Docker image (GHCR)
needs: [get_version, test-lib-ms]
uses: ./.github/workflows/docker-ghcr.yml
with:
image-name: libms
version: ${{ needs.get_version.outputs.version }}
dockerfile: libms.dockerfile
secrets: inherit
publish-docker-image-dockerhub:
if: |
github.event_name == 'push' &&
(startsWith(github.ref, 'refs/heads/feature/') || startsWith(github.ref, 'refs/heads/release-v'))
name: Publish Docker image (DockerHub)
needs: [get_version, test-lib-ms]
uses: ./.github/workflows/docker-dockerhub.yml
with:
image-name: libms
version: ${{ needs.get_version.outputs.version }}
dockerfile: libms.dockerfile
readme-file: servers/lib/DOCKER.md
secrets:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_SCOPE: ${{ secrets.DOCKERHUB_SCOPE }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}