Skip to content

Backend

Backend #290

Workflow file for this run

name: Backend
on:
push:
branches:
- '*'
pull_request:
branches:
- main
schedule:
- cron: '0 10 * * 1'
workflow_call:
inputs:
skipTests:
description: 'Skip tests, useful when there is a dedicated CI job for tests'
default: false
required: false
type: boolean
jobs:
test:
name: Go Test
timeout-minutes: 4
strategy:
fail-fast: true
matrix:
go: ['1.20.x']
os: ['ubuntu-20.04']
runs-on: ${{ matrix.os }}
services:
mysql:
image: mysql:8.0
env:
MYSQL_USER: wwapp_dev
MYSQL_PASSWORD: WWApp-dev-pwd-0
MYSQL_DATABASE: wwapp_dev_db_test
MYSQL_ROOT_PASSWORD: WWApp-dev-pwd-0
ports:
- 3306:3306
options: >-
--health-cmd="mysqladmin ping"
--health-interval=10s
--health-timeout=5s
--health-retries=3
steps:
- name: Check out code
uses: actions/checkout@v3
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go }}
check-latest: true
- name: Test
if: ${{ !inputs.skipTests }}
working-directory: backend
run: go test -v -count=1 -race -shuffle=on -coverprofile=coverage.txt ./...
- name: Benchmark
if: ${{ !inputs.skipTests }}
working-directory: backend
run: go test -v -shuffle=on -run=- -bench=. -benchtime=1x ./...
check:
name: Go Code Checks
timeout-minutes: 2
strategy:
fail-fast: true
matrix:
go: ['1.20.x']
os: ['ubuntu-20.04']
runs-on: ${{ matrix.os }}
steps:
- name: Check out code
uses: actions/checkout@v3
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go }}
check-latest: true
- name: Go Format
working-directory: backend
run: gofmt -s -w . && git diff --exit-code
- name: Go Vet
working-directory: backend
run: go vet ./...
- name: Go Tidy
working-directory: backend
run: go mod tidy && git diff --exit-code
- name: Go Mod
working-directory: backend
run: go mod download
- name: Go Mod Verify
working-directory: backend
run: go mod verify
- name: Go Generate
working-directory: backend
run: go generate ./... && git diff --exit-code
build:
name: Go Build
timeout-minutes: 2
strategy:
fail-fast: true
matrix:
go: ['1.20.x']
os: ['ubuntu-20.04']
runs-on: ${{ matrix.os }}
steps:
- name: Check out code
uses: actions/checkout@v3
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go }}
check-latest: true
- name: Go Build
working-directory: backend
run: go build -o /dev/null ./...
deploy:
name: Deploy Backend
needs: [check, build, test]
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
runs-on: ubuntu-20.04
strategy:
fail-fast: true
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Server 1
uses: appleboy/ssh-action@master
env:
BE_EXEC: ${{ secrets.BE_EXEC }}
with:
host: ${{ secrets.BE_SERVER_01 }}
username: ${{ secrets.DEPLOY_USER }}
key: ${{ secrets.DEPLOY_PRIVATE_KEY }}
script_stop: true
envs: BE_EXEC
script: |
if [[ ! -d webapp ]]; then
git clone https://github.com/wigit-ng/webapp.git
fi
cd webapp
git stash && git checkout main && git pull origin --rebase
cd backend
chmod +x ./scripts/deploy.sh
./scripts/deploy.sh