Production Build #18
Workflow file for this run
This file contains 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: "Production Build" | |
on: | |
push: | |
branches: [ "main" ] | |
workflow_dispatch: | |
jobs: | |
Test: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up Go | |
uses: actions/setup-go@v4 | |
with: | |
go-version: '1.22' | |
- name: Install dependencies | |
run: go get -v ./... | |
- name: Build | |
run: go build -v ./... | |
- name: Test | |
run: go test -v ./... | |
Deploy: | |
name: Deploy to server | |
runs-on: ubuntu-latest | |
needs: [Test] | |
# if: ${{ github.ref == 'refs/heads/main' && github.event_name == 'push' }} | |
steps: | |
- name: Connect Tailscale | |
uses: tailscale/github-action@v2 | |
with: | |
oauth-client-id: ${{ vars.TS_OAUTH_CLIENT_ID }} | |
oauth-secret: ${{ secrets.TS_OAUTH_SECRET }} | |
tags: tag:ci | |
- name: Deploy to server | |
env: | |
PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} | |
HOST_NAME: ${{ vars.HOST_NAME }} | |
USER_NAME: ${{ secrets.USER_NAME }} | |
APP_DIR: ${{ vars.APP_DIR }} | |
SERVICE_NAME: ${{ vars.SERVICE_NAME }} | |
run: | |
echo "$PRIVATE_KEY" > private_key && | |
chmod 400 private_key && | |
ssh -o StrictHostKeyChecking=no -i private_key ${USER_NAME}@${HOST_NAME} " | |
cd ${APP_DIR} && | |
sudo systemctl stop ${SERVICE_NAME} && | |
git pull && | |
/usr/local/go/bin/go install ./... && | |
/usr/local/go/bin/go build -o yab-explorer ./cmd && | |
/home/ubuntu/go/bin/swag init -g ./cmd/main.go -o ./docs && | |
sudo systemctl start ${SERVICE_NAME} " |