Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: add github actions for building and deploying #16

Merged
merged 4 commits into from
Apr 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions .github/workflows/production-workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: "Production Build"

on:
NicolasRampoldi marked this conversation as resolved.
Show resolved Hide resolved
push:
branches: [ "main" ]
workflow_dispatch:

jobs:

Build:
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: [Build]
if: ${{ github.ref == 'refs/heads/main' && github.event_name == 'push' }}

steps:
- name: Deploy to server
env:
PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
HOST_NAME: ${{ secrets.HOST_NAME }}
USER_NAME: ${{ secrets.USER_NAME }}
APP_DIR: ${{ secrets.APP_DIR }}
SERVICE_NAME: ${{ secrets.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 &&
sudo systemctl start ${SERVICE_NAME} "