Skip to content

Deploy:Server:Core

Deploy:Server:Core #99

Workflow file for this run

name: "Deploy:Server:Core"
on:
pull_request:
paths:
- "server/core/**"
- "!server/core/**.md"
- "!server/core/fig/**"
- "!server/core/Makefile"
push:
branches:
- master
paths:
- "server/core/**"
- "!server/core/**.md"
- "!server/core/fig/**"
- "!server/core/Makefile"
workflow_dispatch:
permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout
jobs:
list_modules:
defaults:
run:
working-directory: "server/core"
runs-on: ubuntu-latest
name: "List modules"
outputs:
modules: ${{ steps.ls.outputs.modules }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 1
- name: ls
id: ls
run: echo "modules=$(python3 ../../.github/workflows/scripts/ls_modules.py -p .)" >> $GITHUB_OUTPUT
unittest:
defaults:
run:
working-directory: "server/core"
runs-on: ubuntu-latest
name: "Unittest"
needs:
- list_modules
strategy:
matrix:
module: ${{ fromJSON(needs.list_modules.outputs.modules) }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19
- name: Unittests
run: |
cd ${{ matrix.module.path }}
go mod tidy
go test -race -coverprofile=${{ matrix.module.flag }}.txt -covermode=atomic ./...
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
flags: ${{ matrix.module.flag }}
files: ${{ matrix.module.flag }}.txt
lint:
runs-on: ubuntu-latest
name: "Lint"
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: 1.19
- uses: golangci/golangci-lint-action@v3
with:
version: latest
working-directory: "server/core"
deploy-stage:
if: github.event_name != 'pull_request'
runs-on: ubuntu-latest
environment:
name: "staging:server:core"
needs:
- unittest
- lint
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Authenticate with GCP
id: auth
uses: 'google-github-actions/auth@v1'
with:
workload_identity_provider: 'projects/619195795350/locations/global/workloadIdentityPools/github-access-pool/providers/github-oidc'
service_account: '[email protected]'
access_token_lifetime: '300s'
token_format: 'access_token'
- name: Auth with docker registry
run: echo '${{ steps.auth.outputs.access_token }}' | docker login -u oauth2accesstoken --password-stdin https://gcr.io
- name: Build&Push docker image
working-directory: "server/core"
run: |
make docker-build IMAGE=gcr.io/diagramastext-stage/core
make docker-push IMAGE=gcr.io/diagramastext-stage/core
- name: Setup Terraform CLI
uses: hashicorp/[email protected]
- name: Deploy
working-directory: "server/deployment/gcp/stage"
run: |
terraform init
terraform validate
export TF_VAR_imagetag=$(git rev-parse --short HEAD)
terraform plan -lock-timeout=120s
terraform apply -auto-approve
deploy-prod:
if: github.event_name != 'pull_request'
runs-on: ubuntu-latest
environment:
name: "production:server:core"
needs:
- deploy-stage
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Authenticate with GCP
id: auth
uses: 'google-github-actions/auth@v1'
with:
workload_identity_provider: 'projects/677209864825/locations/global/workloadIdentityPools/github-access-pool/providers/github-oidc'
service_account: '[email protected]'
access_token_lifetime: '300s'
token_format: 'access_token'
- name: Auth with docker registry
run: echo '${{ steps.auth.outputs.access_token }}' | docker login -u oauth2accesstoken --password-stdin https://gcr.io
- name: Build&Push docker image
working-directory: "server/core"
run: |
make docker-build IMAGE=gcr.io/diagramastext-prod/core
make docker-push IMAGE=gcr.io/diagramastext-prod/core
- name: Setup Terraform CLI
uses: hashicorp/[email protected]
- name: Deploy
working-directory: "server/deployment/gcp/prod"
run: |
terraform init
terraform validate
export TF_VAR_imagetag=$(git rev-parse --short HEAD)
terraform plan -lock-timeout=120s
terraform apply -auto-approve