-
-
Notifications
You must be signed in to change notification settings - Fork 33
154 lines (134 loc) · 4.51 KB
/
nodejs.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
name: 'tests'
on:
push:
branches:
- develop
pull_request:
release:
types: [published]
jobs:
# deploy to staging by commiting to api-server-deployment repo
deploy-staging:
runs-on: ubuntu-22.04
if: github.ref_name == 'develop'
needs: docker
steps:
- name: 'Checkout Project'
uses: 'actions/checkout@v4'
with:
fetch-depth: 1
repository: 'openbeta/api-server-deployment'
token: ${{ secrets.GH_DEPLOYMENT_REPO_TOKEN }}
ref: main
- uses: imranismail/setup-kustomize@v2
- run: |
cd stage
kustomize edit set image vnguyen/openbeta-graph-api:sha-${GITHUB_SHA}
- name: Check if there is any change
id: get_changes
run: echo "changed=$(git status --porcelain | wc -l)" >> $GITHUB_OUTPUT
- name: Push if tag has changes
if: steps.get_changes.outputs.changed != 0
run: |
git config user.name github-actions
git config user.email [email protected]
git commit -am "Update deployment. Code=${GITHUB_SHA}"
git push
# deploy to prod by commiting to api-server-deployment repo
deploy-prod:
runs-on: ubuntu-22.04
if: startsWith(github.ref, 'refs/tags/v')
needs: docker
steps:
- name: 'Checkout Project'
uses: 'actions/checkout@v4'
with:
fetch-depth: 1
repository: 'openbeta/api-server-deployment'
token: ${{ secrets.GH_DEPLOYMENT_REPO_TOKEN }}
ref: main
- uses: imranismail/setup-kustomize@v2
- run: |
cd prod
kustomize edit set image vnguyen/openbeta-graph-api:${GITHUB_REF}
- name: Check if there is any change
id: get_changes
run: echo "changed=$(git status --porcelain | wc -l)" >> $GITHUB_OUTPUT
- name: Push if tag has changes
if: steps.get_changes.outputs.changed != 0
run: |
git config user.name github-actions
git config user.email [email protected]
git commit -am "Update deployment. Code=${GITHUB_REF}"
git push
# build docker image and push to registry
docker:
runs-on: ubuntu-22.04
needs: test
steps:
- name: 'Checkout Project'
uses: 'actions/checkout@v3'
with:
fetch-depth: 1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
vnguyen/openbeta-graph-api
tags: |
type=ref,event=branch
type=semver,pattern={{raw}}
type=sha,format=long
- name: Build docker image
uses: docker/build-push-action@v2
with:
context: ./
file: ./Dockerfile
builder: ${{ steps.buildx.outputs.name }}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
# setup basic machine to run all kinds of tests: lint, unit, integration, types
test:
runs-on: 'ubuntu-22.04'
steps:
- name: 'Checkout Project'
uses: 'actions/checkout@v3'
with:
fetch-depth: 1
- name: Setup Node.js environment
uses: actions/setup-node@v3
with:
node-version: '16.15'
cache: 'yarn'
- name: Start MongoDB
uses: supercharge/[email protected]
with:
mongodb-version: 5
mongodb-replica-set: rs0
- name: Install dependencies
run: yarn install --immutable
- name: Lint code
run: yarn lint
- name: Wait for the database to start
run: wget -qO- https://raw.githubusercontent.com/eficode/wait-for/$WAIT_FOR_VERSION/wait-for | sh -s -- localhost:27017 -- echo "Database is up"
env:
WAIT_FOR_VERSION: 4df3f9262d84cab0039c07bf861045fbb3c20ab7 # v2.2.3
- name: Setup test user
run: |
source .env && \
docker exec mongodb mongosh admin --eval "db.createUser({user: '${MONGO_INITDB_ROOT_USERNAME}', pwd: '${MONGO_INITDB_ROOT_PASSWORD}', roles: ['readWrite']})"
- name: Restart mongo
run: |
docker container restart mongodb
- name: Run tests
run: yarn test --ci
- name: Build sources
run: yarn build-release --noEmit