Skip to content

backend

backend #11333

Workflow file for this run

name: backend
on:
push:
paths:
- "backend/**"
- "**.py"
- "**.sh"
- "**.ya?ml"
- "go.mod"
- "go.sum"
- ".github/workflows/backend.yaml"
- "VERSION_HASH.txt"
workflow_run:
workflows:
- "frontend"
types:
- "completed"
env:
CACHE_VERSION: 4
GOPATH: /home/runner/go
jobs:
test:
name: test
runs-on: ubuntu-latest
services:
mysql:
image: mysql:8.0
env:
MYSQL_ALLOW_EMPTY_PASSWORD: true
MYSQL_ROOT_PASSWORD: root
ports:
- 3306:3306
options: >-
--health-cmd="mysqladmin ping"
--health-interval=10s
--health-timeout=5s
--health-retries=3
env:
ENABLE_TRACE: "false"
GO111MODULE: "on"
MYSQL_ALLOW_EMPTY_PASSWORD: true
MYSQL_USER: "lekcije"
MYSQL_PASSWORD: "lekcije"
MYSQL_HOST: "127.0.0.1"
MYSQL_PORT: "3306"
MYSQL_DATABASE: "lekcije_test"
MYSQL_DATABASE_TEST: "lekcije_test"
E2E_WEB_DRIVER: "PhantomJS"
VERSION_HASH: "_version_"
NODE_ENV: "test"
LEKCIJE_ENV: "test"
defaults:
run:
working-directory: backend
timeout-minutes: 20
steps:
- uses: actions/checkout@v4
- uses: styfle/cancel-workflow-action@0.11.0
with:
access_token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-test-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-test
- id: go
uses: actions/setup-go@v4
with:
cache: false
go-version-file: "go.mod"
- name: Sync go.mod
run: |
make sync-go-mod-from-root
- name: Install tools
run: |
ls -l $GOPATH/bin || true
if [ ! -e $GOPATH/bin/goose ]; then
make setup
fi
- name: Create database
run: |
mysql -h${MYSQL_HOST} -uroot -proot -e "SET GLOBAL sql_mode = 'NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES'"
mysql -h${MYSQL_HOST} -uroot -proot < ./db/docker-entrypoint-initdb.d/create_database.sql
- name: Apply database migrations
run: |
export PATH=${PATH}:${GOPATH}/bin
make test/db/goose/up
- name: Run go/test
run: |
make go/test GO_TEST="gotestsum -- -v -race -coverprofile=coverage.txt -covermode=atomic -p=1"
- name: Upload coverage to codecov
uses: codecov/codecov-action@v3.1.4
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./backend/coverage.txt
fail_ci_if_error: false
flags: backend
lint:
name: lint
runs-on: ubuntu-latest
timeout-minutes: 20
env:
GOPATH: /home/runner/work/go
GOBIN: /home/runner/work/go/bin
defaults:
run:
working-directory: backend
steps:
- uses: actions/checkout@v4
- uses: styfle/cancel-workflow-action@0.11.0
with:
access_token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Go
id: go
uses: actions/setup-go@v4
with:
cache: true
cache-dependency-path: "go.sum"
go-version-file: "go.mod"
- name: Sync go.mod
run: |
make sync-go-mod-from-root
- name: Build
run: |
make build
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.52.2
working-directory: backend
skip-go-installation: true
skip-pkg-cache: true
skip-build-cache: true
# deploy-gae:
# name: deploy-gae
# if: github.ref == 'refs/heads/main'
# runs-on: ubuntu-latest
# permissions:
# actions: write
# id-token: write
# contents: read
# timeout-minutes: 20
# steps:
# - uses: actions/checkout@v3
# - name: Cancel previous runs
# uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 # 0.11.0
# with:
# access_token: ${{ secrets.GITHUB_TOKEN }}
# - uses: "google-github-actions/auth@v1"
# with:
# workload_identity_provider: "${{ secrets.GCP_WORKLOAD_IDENTITY_PROVIDER }}"
# service_account: "${{ secrets.GCP_SERVICE_ACCOUNT_EMAIL }}"
# - uses: google-github-actions/setup-gcloud@v1
# with:
# install_components: "app-engine-go"
# - uses: actions/setup-go@v3
# with:
# cache: true
# cache-dependency-path: "go.sum"
# go-version-file: "go.mod"
# - name: Set env VERSION_HASH
# run: |
# VERSION_HASH=$(cat ../VERSION_HASH.txt)
# echo "VERSION_HASH=$VERSION_HASH" >> $GITHUB_ENV
# working-directory: backend
# - name: Generate secret.yaml
# run: |
# cat cmd/server/secret.template.yaml | sed -e 's!<NEW_GCP_PROJECT_ID>!${{ secrets.GCP_PROJECT_ID }}!g; s!<GOOGLE_ANALYTICS_ID>!${{ secrets.GOOGLE_ANALYTICS_ID }}!g; s!<GOOGLE_CLIENT_ID>!${{ secrets.GOOGLE_CLIENT_ID }}!g; s!<GOOGLE_CLIENT_SECRET>!${{ secrets.GOOGLE_CLIENT_SECRET }}!g; s!<ROLLBAR_ACCESS_TOKEN>!${{ secrets.ROLLBAR_ACCESS_TOKEN }}!g; s!<SENDGRID_API_KEY>!${{ secrets.SENDGRID_API_KEY }}!g; s!<VERSION_HASH>!${{ env.VERSION_HASH }}!g;' > cmd/server/secret.yaml
# working-directory: backend
# - name: Show upload files
# run: |
# gcloud meta list-files-for-upload
# working-directory: backend
# - name: Deploy
# id: deploy
# uses: google-github-actions/deploy-appengine@v1
# with:
# deliverables: "cmd/server/app.yaml cmd/server/dispatch.yaml"
# project_id: ${{ secrets.NEW_GCP_PROJECT_ID }}
# promote: true
# version: ${{ env.VERSION_HASH }}
# working_directory: backend
# - name: Check the deployed URL with curl
# run: |
# curl -f "${{ steps.deploy.outputs.url }}/api/status"