-
Notifications
You must be signed in to change notification settings - Fork 0
106 lines (88 loc) · 2.86 KB
/
cd.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
name: CD pipeline — build, test, deploy
on:
push:
branches: [master]
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Node.js environment
uses: actions/setup-node@v3
with:
node-version: 'lts/hydrogen'
# https://github.com/actions/cache/blob/main/examples.md
- name: Get yarn cache directory path for ui
id: yarn-cache-dir-path
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
- name: Cache yarn dependencies
id: yarn-cache
uses: actions/cache@v3
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install yarn dependencies
run: yarn
- name: Cache fonts
id: fonts-cache
uses: actions/cache@v3
with:
path: 'public/font'
key: ${{ runner.os }}-fonts-${{ hashFiles('public/font/font.list') }}
restore-keys: |
${{ runner.os }}-fonts-
- name: Download fonts
if: steps.fonts-cache.outputs.cache-hit != 'true'
run: yarn fonts
- name: Test
run: yarn test
- name: Build
run: yarn build
- name: Compress
run: yarn tar
- name: Archive compressed dist artifact
uses: actions/upload-artifact@v3
with:
name: blog-sewera-dev-dist-archive
path: |
dist.tar
deploy:
needs: build
environment: production
concurrency: production
runs-on: ubuntu-latest
steps:
- name: Add SSH key
env:
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
run: |
mkdir -p /home/runner/.ssh
ssh-keyscan sewera.dev >> /home/runner/.ssh/known_hosts
echo "${{ secrets.BLOG_PROD_KEY }}" > /home/runner/.ssh/github_actions
chmod 600 /home/runner/.ssh/github_actions
ssh-agent -a $SSH_AUTH_SOCK > /dev/null
ssh-add /home/runner/.ssh/github_actions
- name: Get built artifact
uses: actions/download-artifact@v3
with:
name: blog-sewera-dev-dist-archive
- name: Prepare and upload artifact
env:
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
run: |
tar -xf dist.tar && \
rm dist.tar && \
tar -czf blog-sewera-dev-dist-archive.zip dist && \
scp -i /home/runner/.ssh/github_actions \
blog-sewera-dev-dist-archive.zip \
${{ secrets.BLOG_PROD_USER }}@sewera.dev:~/blog/
- name: Deploy to production
env:
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
run: |
ssh -i /home/runner/.ssh/github_actions \
${{ secrets.BLOG_PROD_USER }}@sewera.dev \
'./DEPLOY_BLOG'