-
-
Notifications
You must be signed in to change notification settings - Fork 13
270 lines (262 loc) · 8.82 KB
/
continuous-deployment.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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
name: Continuous Deployment
on:
push:
branches:
- main
paths:
- src/**
- .github/workflows/continuous-deployment.yml
- README.md
- Dockerfile
workflow_dispatch:
inputs:
skip-publish:
description: Whether to skip publishing typings to NPM
required: false
type: boolean
jobs:
Publish:
name: Publish image to container registries
runs-on: ubuntu-latest
if: ${{ ! contains(github.event.head_commit.message, '[skip docker]') }}
steps:
- name: Checkout Project
uses: actions/checkout@v4
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3.7.1
- name: Login to DockerHub
uses: docker/login-action@v3.3.0
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v3.3.0
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@v6.10.0
with:
push: true
context: .
cache-from: type=gha
cache-to: type=gha,mode=max
platforms: |
linux/amd64
linux/arm64
tags: |
favware/graphql-pokemon:latest
ghcr.io/favware/graphql-pokemon:latest
- name: Update repo description
uses: peter-evans/dockerhub-description@v4
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
repository: favware/graphql-pokemon
enable-url-completion: true
short-description: Extensive Pokemon GraphQL API
ValidateAllData:
name: Validate all data
runs-on: ubuntu-latest
if: ${{ ! contains(github.event.head_commit.message, '[skip docker]') }}
needs: Publish
services:
pokedex:
image: ghcr.io/favware/graphql-pokemon:latest
options: >-
--health-cmd "nc -z localhost 4000"
--health-interval 10s
--health-timeout 10s
--health-retries 6
--health-start-period 5s
ports:
- 4000:4000
steps:
- name: Checkout Project
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
cache: pip
- name: Install Dependencies
working-directory: ./scripts/manual-tests
run: pip install -r requirements.txt
- name: Run get-all-data
working-directory: ./scripts/manual-tests
run: python get-all-data.py
UpdateOnServer:
name: Update running container on server
runs-on: ubuntu-latest
if: ${{ ! contains(github.event.head_commit.message, '[skip docker]') }}
needs: ValidateAllData
steps:
- name: Update container on server
uses: favware/ssh-remote-action@v1
with:
host: ${{ secrets.SSH_HOST }}
port: ${{ secrets.SSH_PORT }}
key: ${{ secrets.SSH_KEY }}
passphrase: ${{ secrets.SSH_KEY_PASSPHRASE }}
username: ${{ secrets.SSH_USERNAME }}
command: ${{ secrets.SSH_COMMAND }}
silent: true
GeneratePackage:
name: Generate JavaScript companion library
runs-on: ubuntu-latest
if: ${{ ! contains(github.event.head_commit.message, '[skip publish]') || github.event.inputs.skip-publish == true }}
needs: ValidateAllData
services:
pokedex:
image: ghcr.io/favware/graphql-pokemon:latest
options: >-
--health-cmd "nc -z localhost 4000"
--health-interval 10s
--health-timeout 10s
--health-retries 6
--health-start-period 5s
ports:
- 4000:4000
steps:
- name: Checkout Project
uses: actions/checkout@v4
- name: Add problem matchers
run: echo "::add-matcher::.github/problemMatchers/tsc.json"
- name: Use Node.js v20
uses: actions/setup-node@v4
with:
node-version: 20
cache: yarn
registry-url: https://registry.yarnpkg.com/
- name: Install Dependencies
run: yarn --immutable
- name: Generate library code
run: yarn package
- name: Upload typescript bundle to artifacts
uses: actions/upload-artifact@v4
with:
name: package_bundle
path: dist/
if-no-files-found: error
GitHubMakeRelease:
name: Make release on GitHub
runs-on: ubuntu-latest
if: ${{ ! contains(github.event.head_commit.message, '[skip publish]') || github.event.inputs.skip-publish == true }}
needs: GeneratePackage
steps:
- name: Checkout Project
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.BOT_TOKEN }}
- name: Use Node.js v20
uses: actions/setup-node@v4
with:
node-version: 20
cache: yarn
registry-url: https://registry.yarnpkg.com/
- name: Install Dependencies
run: yarn --immutable
- name: Configure Git
run: |
git remote set-url origin "https://${GITHUB_TOKEN}:x-oauth-basic@github.com/${GITHUB_REPOSITORY}.git"
git config --local user.email "${GITHUB_EMAIL}"
git config --local user.name "${GITHUB_USER}"
env:
GITHUB_USER: github-actions[bot]
GITHUB_EMAIL: 41898282+github-actions[bot]@users.noreply.github.com
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Bump semver
if: ${{ ! contains(github.event.head_commit.message, '[skip bump]') }}
run: yarn bump
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Store bumped package.json
uses: actions/upload-artifact@v4
with:
name: package_json
path: package.json
if-no-files-found: error
- name: Store bumped changelog.md
uses: actions/upload-artifact@v4
with:
name: changelog_md
path: CHANGELOG.md
if-no-files-found: error
- name: Push changes
if: ${{ ! contains(github.event.head_commit.message, '[skip bump]') }}
run: git push origin main && git push --tags origin main
NPMPublish:
name: Publishing release to NPM
runs-on: ubuntu-latest
if: ${{ ! contains(github.event.head_commit.message, '[skip publish]') || github.event.inputs.skip-publish == true }}
needs: GitHubMakeRelease
steps:
- name: Checkout Project
uses: actions/checkout@v4
- name: Download generated typings artifact
uses: actions/download-artifact@v4
with:
name: package_bundle
path: dist/
- name: Download stored package.json
uses: actions/download-artifact@v4
with:
name: package_json
- name: Download stored changelog.md
uses: actions/download-artifact@v4
with:
name: changelog_md
- name: Setup Node for publishing to NPM
uses: actions/setup-node@v4
with:
node-version: 20
cache: yarn
registry-url: https://registry.yarnpkg.com/
- name: Install Dependencies
run: yarn --immutable
- name: Publish to NPM
run: |
yarn config set npmAuthToken ${NODE_AUTH_TOKEN}
yarn config set npmPublishRegistry "https://registry.yarnpkg.com"
yarn npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
Github-Package-Registry-Node:
name: Publishing release to Github Package Registry
runs-on: ubuntu-latest
if: ${{ ! contains(github.event.head_commit.message, '[skip publish]') || github.event.inputs.skip-publish == true }}
needs: GitHubMakeRelease
steps:
- name: Checkout Project
uses: actions/checkout@v4
- name: Setup Node for publishing to Github
uses: actions/setup-node@v4
with:
node-version: 20
registry-url: 'https://npm.pkg.github.com'
scope: '@favware'
cache: yarn
- name: Download generated typings artifact
uses: actions/download-artifact@v4
with:
name: package_bundle
path: dist/
- name: Download stored package.json
uses: actions/download-artifact@v4
with:
name: package_json
- name: Download stored changelog.md
uses: actions/download-artifact@v4
with:
name: changelog_md
- name: Install Dependencies
run: yarn --immutable
- name: Publish to Github
run: |
yarn config set npmAuthToken ${NODE_AUTH_TOKEN}
yarn config set npmPublishRegistry "https://npm.pkg.github.com"
yarn npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}