ci: add GitHub Actions auto deploy workflow #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Deploy Backend | |
| on: | |
| workflow_dispatch: | |
| push: | |
| branches: [main] | |
| paths: | |
| - 'cmd/**' | |
| - 'internal/**' | |
| - 'go.mod' | |
| - 'go.sum' | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Setup Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: '1.23' | |
| - name: Build | |
| run: CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o linkbridge-backend ./cmd/api | |
| - name: Upload to server | |
| uses: appleboy/scp-action@v0.1.7 | |
| with: | |
| host: ${{ secrets.SERVER_HOST }} | |
| username: ${{ secrets.SERVER_USER }} | |
| key: ${{ secrets.SSH_PRIVATE_KEY }} | |
| source: linkbridge-backend | |
| target: /tmp/ | |
| - name: Deploy and restart | |
| uses: appleboy/ssh-action@v1 | |
| with: | |
| host: ${{ secrets.SERVER_HOST }} | |
| username: ${{ secrets.SERVER_USER }} | |
| key: ${{ secrets.SSH_PRIVATE_KEY }} | |
| script: | | |
| sudo systemctl stop linkbridge || true | |
| sudo mv /tmp/linkbridge-backend /opt/linkbridge-backend | |
| sudo chmod +x /opt/linkbridge-backend | |
| sudo systemctl start linkbridge | |
| sleep 2 | |
| sudo systemctl status linkbridge --no-pager |