Skip to content

Commit

Permalink
build: add github actions for building and deploying (#16)
Browse files Browse the repository at this point in the history
* build: add github actions for building and deploying

* feat: added types to pull_request in github actions

* fix: lowercase job names

* fix: remove pull_request triggers
  • Loading branch information
NicolasRampoldi authored Apr 2, 2024
1 parent 439da4d commit e051a1b
Showing 1 changed file with 50 additions and 0 deletions.
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:
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} "

0 comments on commit e051a1b

Please sign in to comment.