Skip to content

Commit

Permalink
Deploy Github action (#3)
Browse files Browse the repository at this point in the history
* Deploy Github action

* Upload binary via SCP

* Stop service before uploading, and overwrite with new binary

* Upload to tmp folder then copy

* Get service status after redeploy

* Upload server binary as Github actions artifact

* Don't deploy on pull_request

* Remove concurrency as we want record of builds from merged PRs
  • Loading branch information
michaelclapham authored Sep 7, 2024
1 parent a6156ae commit 3651d5e
Showing 1 changed file with 84 additions and 0 deletions.
84 changes: 84 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: 'Build & Deploy'

on:
workflow_dispatch:
push:
branches:
- main

permissions:
contents: read
pull-requests: read

jobs:
deploy:
runs-on: ["ubuntu-latest"]
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Go ${{ matrix.go-version }}
uses: actions/setup-go@v5
with:
go-version: '1.22'

- name: Go version
run: go version

- name: Go build
run: go build

- run: ls -l

- name: Stop service
uses: appleboy/[email protected]
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
password: ${{ secrets.SSH_PASSWORD }}
port: ${{ secrets.SSH_PORT }}
script: sudo /usr/bin/systemctl stop qrsync_server

- name: Upload binary as Github action artifact
uses: actions/upload-artifact@v4
with:
name: server
path: ./qrsync-server

- name: Upload new binary
uses: appleboy/[email protected]
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
password: ${{ secrets.SSH_PASSWORD }}
port: ${{ secrets.SSH_PORT }}
source: "qrsync-server"
target: /var/www/qrsync_server/tmp
overwrite: true

- name: Move binary from tmp folder
uses: appleboy/[email protected]
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
password: ${{ secrets.SSH_PASSWORD }}
port: ${{ secrets.SSH_PORT }}
script: cp "/var/www/qrsync_server/tmp/qrsync-server" /var/www/qrsync_server

- name: Restart service
uses: appleboy/[email protected]
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
password: ${{ secrets.SSH_PASSWORD }}
port: ${{ secrets.SSH_PORT }}
script: sudo /usr/bin/systemctl restart qrsync_server

- name: Get service status
uses: appleboy/[email protected]
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
password: ${{ secrets.SSH_PASSWORD }}
port: ${{ secrets.SSH_PORT }}
script: /usr/bin/systemctl status qrsync_server

0 comments on commit 3651d5e

Please sign in to comment.