-
Notifications
You must be signed in to change notification settings - Fork 0
89 lines (84 loc) · 2.63 KB
/
ci.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
name: Continuous Integration
on:
pull_request:
push:
branches: ["main"]
# These are the IDs for https://github.com/organizations/w3ctag/settings/apps/w3c-tag-bot.
env:
APP_ID: "1013567"
CLIENT_ID: "Iv23liXTAsX4IYm9H6lc"
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup pnpm
uses: pnpm/action-setup@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version-file: "package.json"
cache: pnpm
- run: pnpm install
- run: pnpm test
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup pnpm
uses: pnpm/action-setup@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version-file: "package.json"
cache: pnpm
- run: pnpm install
- run: pnpm build
- run: rm -rf node_modules
- run: pnpm install --prod
- run: pnpm prisma generate
- run: tar -cf built-server.tar package.json dist node_modules prisma
- uses: actions/upload-artifact@v4
with:
name: built-server
path: built-server.tar
if-no-files-found: error
deploy:
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
needs: [test, build]
environment:
name: production
url: "https://github-bot.w3ctag.org/"
concurrency:
group: production
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
with:
name: built-server
- name: Extract the built server
run: |
cd built-server
tar -xf built-server.tar
rm built-server.tar
- name: Store ssh private key
run: |
mkdir ~/.ssh
echo "$SSH_KEY" > ~/.ssh/deploy_key
chmod 700 ~/.ssh
chmod 600 ~/.ssh/deploy_key
env:
SSH_KEY: ${{ secrets.SSH_KEY }}
- name: Upload
run: rsync -e "ssh -p $SSH_PORT" -azv --safe-links --hard-links --progress --delete built-server/ "$SSH_USER@$SSH_HOST:$DEPLOY_PATH"
env:
SSH_PORT: ${{ vars.SSH_PORT }}
SSH_HOST: ${{ vars.SSH_HOST }}
SSH_USER: ${{ vars.SSH_USER }}
DEPLOY_PATH: ${{ vars.DEPLOY_PATH }}
- name: Update and Restart
run: 'ssh -p $SSH_PORT "$SSH_USER@$SSH_HOST" sh -c "DATABASE_URL=file:/var/local/github-bot/prod.db node_modules/.bin/prisma migrate deploy && sudo /usr/bin/systemctl restart github-bot"'
env:
SSH_PORT: ${{ vars.SSH_PORT }}
SSH_HOST: ${{ vars.SSH_HOST }}
SSH_USER: ${{ vars.SSH_USER }}