Repository navigation
66 lines (57 loc) · 1.96 KB
/
Copy pathdeploy.yml
File metadata and controls
66 lines (57 loc) · 1.96 KB
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
name: Deploy
on:
push:
branches: [main]
workflow_dispatch:
jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache-dependency-path: go.mod
- run: go test ./...
deploy:
name: Deploy
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache-dependency-path: go.mod
- name: Build
run: CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o redirect-name .
- name: Set up SSH
run: |
mkdir -p ~/.ssh
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/deploy_key
chmod 600 ~/.ssh/deploy_key
ssh-keyscan -H "${{ secrets.DROPLET_IP }}" >> ~/.ssh/known_hosts
- name: Write blocklist
run: printf 'BLOCKLIST=%s\n' "$(echo "$BLOCKLIST" | tr '\n' ',' | sed 's/,$//')" > blocklist.env
env:
BLOCKLIST: ${{ secrets.BLOCKLIST }}
- name: Deploy
env:
DROPLET_IP: ${{ secrets.DROPLET_IP }}
run: |
scp -i ~/.ssh/deploy_key redirect-name root@$DROPLET_IP:/tmp/redirect-name
scp -i ~/.ssh/deploy_key redirect-name.service root@$DROPLET_IP:/etc/systemd/system/redirect-name.service
scp -i ~/.ssh/deploy_key blocklist.env root@$DROPLET_IP:/tmp/blocklist.env
ssh -i ~/.ssh/deploy_key root@$DROPLET_IP "
install -m 755 /tmp/redirect-name /usr/local/bin/redirect-name &&
install -d -m 755 /usr/local/etc/redirect-name &&
install -m 644 /tmp/blocklist.env /usr/local/etc/redirect-name/blocklist.env &&
systemctl daemon-reload &&
systemctl enable redirect-name &&
systemctl restart redirect-name
"
- name: Smoke test
run: |
sleep 3
go test -tags e2e -v ./...