-
Notifications
You must be signed in to change notification settings - Fork 1
204 lines (180 loc) · 5.84 KB
/
build.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
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
name: Build and lint Backend
on:
push:
branches: main
paths:
- "backend/**/*.ts"
- "backend/**/*.js"
- "backend/**/*.json"
- "backend/yarn.lock"
- "backend/prisma/schema.prisma"
defaults:
run:
shell: bash
working-directory: ./backend
env:
APP_PATH: /opt/MTB
APP_NAME: bot
jobs:
format:
name: Run Prettier
runs-on: ubuntu-latest
steps:
- name: Check out Git repository
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 22
cache: "yarn"
cache-dependency-path: backend/yarn.lock
- name: Install Node.js dependencies
run: yarn --immutable --prefer-offline
- name: Running Prettier
run: yarn run format
- name: Check for changes and push changes to repository
if: always()
id: check_changes
run: |
if [[ -n $(git status --porcelain) ]]; then
git config --global user.email "${GITHUB_ACTOR_ID}+${GITHUB_ACTOR}@users.noreply.github.com"
git config --global user.name "${GITHUB_ACTOR}"
git add .
git commit -m "Fixed Prettier issues"
git pull origin main --rebase
git push
fi
linting:
name: Run linter
runs-on: ubuntu-latest
steps:
- name: Check out Git repository
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 22
cache: "yarn"
cache-dependency-path: backend/yarn.lock
- name: Install Node.js dependencies
run: yarn --immutable --prefer-offline
- name: Running ESLint
run: yarn run lint
- name: Check for changes and push changes to repository
if: always()
id: check_changes
run: |
if [[ -n $(git status --porcelain) ]]; then
git config --global user.email "${GITHUB_ACTOR_ID}+${GITHUB_ACTOR}@users.noreply.github.com"
git config --global user.name "${GITHUB_ACTOR}"
git add .
git commit -m "Fixed ESLint issues"
git pull origin main --rebase
git push
fi
test:
name: Run tests
runs-on: ubuntu-latest
needs: [linting, format]
# For now we need to allow tests to fail
continue-on-error: true
steps:
- name: Check out Git repository
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 22
cache: "yarn"
cache-dependency-path: backend/yarn.lock
- name: Install Node.js dependencies and generate prisma client
run: yarn --frozen-lockfile --prefer-offline && yarn run prisma:generate
- name: Run tests
run: yarn run test
build:
name: Build docker image
runs-on: ubuntu-latest
needs: [test]
steps:
- name: Check out Git repository
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 22
cache: "yarn"
cache-dependency-path: backend/yarn.lock
- name: Setup buildx
uses: docker/setup-buildx-action@v3
- name: Login to Github Packages
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set short git commit SHA
id: vars
run: |
calculatedSha=$(git rev-parse --short ${{ github.sha }})
echo "COMMIT_SHORT_SHA=$calculatedSha" >> $GITHUB_ENV
- name: Build image and push to GitHub Container Registry
uses: docker/build-push-action@v3
with:
context: "{{defaultContext}}:backend"
platforms: linux/amd64
push: true
tags: ghcr.io/89q12/mega-transformers-bot:${{ env.COMMIT_SHORT_SHA }}
cache-from: type=gha
cache-to: type=gha,mode=max
deploy:
name: Deploy
runs-on: ubuntu-latest
# Later also tests
needs: [build]
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set short git commit SHA
id: vars
run: |
calculatedSha=$(git rev-parse --short ${{ github.sha }})
echo "COMMIT_SHORT_SHA=$calculatedSha" >> $GITHUB_ENV
- name: Set up SSH key
run: |
env
mkdir -p ~/.ssh
echo "${{ secrets.ARTIFACT_SSH_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan -p 22 ${{ secrets.ARTIFACT_HOST }} >> ~/.ssh/known_hosts
- name: Deploy to server
run: |
ssh -i ~/.ssh/id_rsa -v -o StrictHostKeyChecking=no ${{ secrets.SSH_USER }}@${{ secrets.ARTIFACT_HOST }} <<'ENDSSH'
cd ${{ env.APP_PATH }}
sed -E -i'' "s/(.*mega-transformers-bot:).*/\1${{ env.COMMIT_SHORT_SHA }}/" 'docker-compose.yml'
docker compose pull ${{ env.APP_NAME }}
docker compose up -d
ENDSSH
docs:
name: Build and deploy documentation
runs-on: ubuntu-latest
# Reasoning: We dont want to deploy docs of broken code, therefore we depend on tests
needs: [test]
steps:
- name: Check out Git repository
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 22
cache: "yarn"
cache-dependency-path: backend/yarn.lock
- name: Install Node.js dependencies
run: yarn --immutable --prefer-offline
- name: Generate documentation
run: yarn run docs
- name: Deploy documentation
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./backend/docs
publish_branch: gh-pages