-
-
Notifications
You must be signed in to change notification settings - Fork 1
139 lines (118 loc) · 3.7 KB
/
deploy-site.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
name: Deploy site
on:
push:
branches:
- main
pull_request_target:
branches:
- main
jobs:
build:
name: Build site
runs-on: ubuntu-latest
steps:
- name: Check-out (Production)
uses: actions/checkout@v4
if: github.event_name == 'push'
- name: Check-out (Staging)
uses: actions/checkout@v4
if: github.event_name == 'pull_request_target'
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "22"
- name: Install pnpm
run: npm install -g pnpm
- name: Install dependencies
run: pnpm install
- name: Build
run: pnpm run build
- uses: actions/upload-artifact@v4
with:
name: site-build
path: dist
if-no-files-found: error
include-hidden-files: true
deploy-production:
name: Deploy to Production
needs: [build]
if: ${{ (github.ref == 'refs/heads/main') && (github.event_name == 'push') }}
runs-on: ubuntu-latest
environment:
name: production
url: "https://jb3.dev/"
steps:
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: site-build
path: dist
- name: Tailscale
uses: tailscale/github-action@v2
with:
oauth-client-id: ${{ secrets.TAILSCALE_OAUTH_CLIENT_ID }}
oauth-secret: ${{ secrets.TAILSCALE_OAUTH_CLIENT_SECRET }}
tags: tag:ci
- name: Configure SSH
run: |
mkdir -p ~/.ssh/
echo "$SSH_KEY" > ~/.ssh/production.key
chmod 600 ~/.ssh/production.key
cat >>~/.ssh/config <<END
Host production
HostName $SSH_HOST
User ci
IdentityFile ~/.ssh/production.key
StrictHostKeyChecking no
END
env:
SSH_KEY: ${{ secrets.DEPLOYMENT_SSH_KEY }}
SSH_HOST: ${{ vars.DEPLOYMENT_HOST }}
- name: Deploy to deployment host
run: rsync -a --delete dist/ production:/usr/share/nginx/jb3.dev/
- name: Logout from Tailscale & delete ephemeral node
run: sudo tailscale logout
deploy-staging:
name: Deploy to Staging
needs: [build]
runs-on: ubuntu-latest
if: github.event_name == 'pull_request_target'
environment:
name: staging
url: "https://${{ steps.slug.outputs.branch-name-slug }}.blog-staging.jb3.dev/"
steps:
- name: Generate slug for deployment name
uses: gacts/github-slug@v1
id: slug
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: site-build
path: dist
- name: Tailscale
uses: tailscale/github-action@v2
with:
oauth-client-id: ${{ secrets.TAILSCALE_OAUTH_CLIENT_ID }}
oauth-secret: ${{ secrets.TAILSCALE_OAUTH_CLIENT_SECRET }}
tags: tag:ci
- name: Configure SSH
run: |
mkdir -p ~/.ssh/
echo "$SSH_KEY" > ~/.ssh/production.key
chmod 600 ~/.ssh/production.key
cat >>~/.ssh/config <<END
Host production
HostName $SSH_HOST
User ci
IdentityFile ~/.ssh/production.key
StrictHostKeyChecking no
END
env:
SSH_KEY: ${{ secrets.DEPLOYMENT_SSH_KEY }}
SSH_HOST: ${{ vars.DEPLOYMENT_HOST }}
- name: Deploy to deployment host
run: rsync -a --delete dist/ production:/usr/share/nginx/jb3.dev-staging/${{ steps.slug.outputs.branch-name-slug }}
- name: Logout from Tailscale & delete ephemeral node
run: sudo tailscale logout