Skip to content

Commit bd4434d

Browse files
committed
create deployment workflow
1 parent 22866ef commit bd4434d

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

.github/workflows/go.yml

+43
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,46 @@ jobs:
3232
with:
3333
name: hkgi.tar.gz
3434
path: hkgi.tar.gz
35+
36+
deploy:
37+
runs-on: ubuntu-latest
38+
environment: production
39+
if:
40+
contains('refs/heads/master', github.ref)
41+
steps:
42+
- name: Download latest package
43+
uses: actions/download-artifact@v3
44+
with:
45+
name: hkgi.tar.gz
46+
47+
- name: Deploy with SCP
48+
uses: i3h/deploy-with-scp@v1
49+
with:
50+
src: ./hkgi.tar.gz
51+
dest: ${{ secrets.SSH_DIR }}/hkgi-new.tar.gz
52+
username: ${{ secrets.SSH_USER }}
53+
server-ip: ${{ secrets.SSH_HOST }}
54+
ssh-key: ${{ secrets.SSH_KEY }}
55+
56+
- name: Configure SSH
57+
run: |
58+
mkdir -p ~/.ssh
59+
echo "$SSH_KEY" >> ~/.ssh/id_rsa
60+
chmod 0600 ~/.ssh/id_rsa
61+
cat >>~/.ssh/config <<END
62+
Host production
63+
Hostname $SSH_HOST
64+
User $SSH_USER
65+
IdentityFile ~/.ssh/id_rsa
66+
StrictHostKeyChecking no
67+
END
68+
env:
69+
SSH_USER: ${{ secrets.SSH_USER }}
70+
SSH_HOST: ${{ secrets.SSH_HOST }}
71+
SSH_KEY: ${{ secrest.SSH_KEY }}
72+
73+
- name: Extract tarball on production host
74+
run: ssh staging tar xzvf "$SSH_DIR/hkgi-new.tar.gz" -C "$SSH_DIR"
75+
76+
- name: Restart service on production host
77+
run: ssh staging /usr/bin/sudo /usr/bin/systemctl restart hkgi

0 commit comments

Comments
 (0)