Merge pull request #45 from linycken013127/infra/tweak-github-action #44
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: ⚙️ Backend CI | |
on: | |
push: | |
paths: | |
- Backend/** | |
- .github/workflows/test-go-unit.yml | |
pull_request: | |
paths: | |
- Backend/** | |
- .github/workflows/test-go-unit.yml | |
env: | |
GO_VERSION: 1.21 | |
jobs: | |
build: | |
runs-on: ubuntu-22.04 | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up Go | |
uses: actions/setup-go@v4 | |
with: | |
go-version: ${{ env.GO_VERSION }} | |
- name: Env handle | |
working-directory: ./Backend | |
run: cp env .env | |
- name: Build | |
working-directory: ./Backend | |
run: go build -v ./... | |
unit_test: | |
needs: build | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Setup Go environment | |
uses: actions/setup-go@v2 | |
with: | |
go-version: ${{ env.GO_VERSION }} | |
- name: 🧪 Test | |
working-directory: ./Backend | |
run: go test $(go list ./... | grep -v /tests/) -count=1 -v -coverprofile=unit_test_coverage.out | |
- name: Upload unit test coverage report as artifact | |
uses: actions/upload-artifact@v2 | |
with: | |
name: unit-test-coverage-report | |
path: ./Backend/unit_test_coverage.out | |
acceptance_test: | |
needs: unit_test | |
if: github.event_name == 'push' | |
services: | |
mysql: | |
image: mysql:8.1.0 | |
env: | |
MYSQL_ROOT_PASSWORD: ${{ secrets.DB_ROOT_PASSWORD }} | |
MYSQL_DATABASE: test | |
MYSQL_USER: user | |
MYSQL_PASSWORD: ${{ secrets.DB_PASSWORD }} | |
ports: | |
- "3306:3306" | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Setup Go environment | |
uses: actions/setup-go@v2 | |
with: | |
go-version: ${{ env.GO_VERSION }} | |
- name: Env handle | |
working-directory: ./Backend | |
run: cp env .env | |
- name: Migration | |
working-directory: ./Backend | |
run: go run ./cmd/migrate/migrate.go | |
- name: 🎯 Acceptance test | |
working-directory: ./Backend | |
run: go test ./... -v -count=1 -coverprofile=coverage.out | |
- name: Upload acceptance test coverage report as artifact | |
uses: actions/upload-artifact@v2 | |
with: | |
name: acceptance-test-coverage-report | |
path: ./Backend/coverage.out |