Skip to content

Exponential base delay #1452

Exponential base delay

Exponential base delay #1452

Workflow file for this run

name: 💫 CI
on:
push:
branches: [master]
concurrency:
group: environment-${{ github.ref }}
cancel-in-progress: true
jobs:
setup_env:
name: ⚙️ Setup environment
runs-on: ubuntu-latest
steps:
- name: Add SHORT_SHA env property
run: echo "SHORT_SHA=`echo ${GITHUB_SHA::7}`" >> $GITHUB_ENV
- name: Put commit msg in environment
run: echo "COMMIT_MSG=${{ github.event.head_commit.message }}" >> $GITHUB_ENV
- name: Escape commit message
run: |
echo "COMMIT_MSG=$(echo $COMMIT_MSG | tr -d \'\\\")" >> $GITHUB_ENV
- name: Get branch name (merge)
if: github.event_name != 'pull_request'
shell: bash
run: echo "BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/} | tr / -)" >> $GITHUB_ENV
- name: Get branch name (pull request)
if: github.event_name == 'pull_request'
shell: bash
run: echo "BRANCH_NAME=$(echo ${GITHUB_HEAD_REF} | tr / -)" >> $GITHUB_ENV
outputs:
short_sha: ${{ env.SHORT_SHA }}
commit_msg: ${{ env.COMMIT_MSG }}
branch_name: ${{ env.BRANCH_NAME }}
test:
name: ☔️ Tests
runs-on: ubuntu-latest
needs: setup_env
# Setup postgres service for tests
services:
db:
image: postgres:15
env:
POSTGRES_DB: testing
POSTGRES_PASSWORD: postgres
POSTGRES_USER: postgres
ports:
- 5432:5432
# set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Check out code
uses: actions/checkout@v3
- name: Cache Go modules
uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-gotesst-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-gotest-
- name: Setup Go
uses: actions/setup-go@v3
with:
go-version-file: ./go.work
- name: Run Tests
env:
GITHUB_ACTIONS: true
POSTGRES_DB: testing
POSTGRES_PORT: 5432
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_HOST: localhost
run: |
go test -v -parallel 1 ./cron/...
go test -v -parallel 1 ./database/...
go test -v -parallel 1 ./log/...
go test -v -parallel 1 ./server/...
go test -v -parallel 1 ./shared/...
go test -v -parallel 1 ./utils/...
go test -v -parallel 1 ./uploadapi/...
- name: Send Discord Webhook
if: failure()
uses: ./.github/actions/discord-webhook
with:
context: prod
prod-webhook-url: ${{ secrets.DISCORD_WEBHOOK_PROD }}
qa-webhook-url: ${{ secrets.DISCORD_WEBHOOK }}
embed-color: 15548997
embed-title: "[GO Apps] ${{ needs.setup_env.outputs.commit_msg }} • ${{ needs.setup_env.outputs.short_sha }}"
embed-description: "```Tests Failed```"
build:
name: 🔨 Build Binaries and Docker Image
runs-on: ubuntu-latest
needs: setup_env
env:
GITHUB_RUN_ID: ${{ github.run_id }}
steps:
- uses: actions/checkout@v3
- name: Set build start in env variable
run: echo "BUILD_START=$(date +%s)" >> $GITHUB_ENV
- name: Send Discord Webhook
uses: ./.github/actions/discord-webhook
with:
context: prod
prod-webhook-url: ${{ secrets.DISCORD_WEBHOOK_PROD }}
qa-webhook-url: ${{ secrets.DISCORD_WEBHOOK }}
embed-color: 16776960
embed-title: "[GO Apps] ${{ needs.setup_env.outputs.commit_msg }} • ${{ needs.setup_env.outputs.short_sha }}"
embed-description: "```Build Started```"
- name: Cache Go modules
uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Setup Go with cache
uses: actions/setup-go@v3
with:
go-version-file: ./go.work
- name: Login to registry
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build GO Server Binary
run: |
cd server && GOARCH=arm64 go build -ldflags "-s -w -X main.Version=${{ needs.setup_env.outputs.short_sha }} -X \"main.CommitMsg=${{ needs.setup_env.outputs.commit_msg }}\" -X main.BuildStart=${{ env.BUILD_START }}" -o server && cd ..
- name: Build GO Cron Binary
run: |
cd cron && GOARCH=arm64 go build -ldflags "-s -w -X main.Version=${{ needs.setup_env.outputs.short_sha }} -X \"main.CommitMsg=${{ needs.setup_env.outputs.commit_msg }}\"" -o cron && cd ..
- name: Build GO Upload API Binary
run: |
cd uploadapi && GOARCH=arm64 go build -ldflags "-s -w -X main.Version=${{ needs.setup_env.outputs.short_sha }}" -o uploadapi && cd ..
- name: Build GO Lingua API Binary
run: |
cd language && GOARCH=arm64 go build -ldflags "-s -w -X main.Version=${{ needs.setup_env.outputs.short_sha }}" -o linguaapi && cd ..
- name: Build GO Discord Bot Binary
run: |
cd discobot && GOARCH=arm64 go build -ldflags "-s -w -X main.Version=${{ needs.setup_env.outputs.short_sha }}" -o discobot && cd ..
- name: Build and push image
if: success()
uses: docker/build-push-action@v3
with:
context: .
platforms: linux/arm64
push: true
file: ./Dockerfile.ci
tags: stablecog/sc-server:${{ needs.setup_env.outputs.branch_name }}-${{ env.GITHUB_RUN_ID }}
- name: Send Discord Webhook
if: failure()
uses: ./.github/actions/discord-webhook
with:
context: prod
prod-webhook-url: ${{ secrets.DISCORD_WEBHOOK_PROD }}
qa-webhook-url: ${{ secrets.DISCORD_WEBHOOK }}
embed-color: 15548997
embed-title: "[GO Apps] ${{ needs.setup_env.outputs.commit_msg }} • ${{ needs.setup_env.outputs.short_sha }}"
embed-description: "```🚨 Build FAILED 🚨```"
deploy_prod:
name: 🚀 Deploy Apps (PROD)
runs-on: ubuntu-latest
needs:
- setup_env
- test
- build
env:
GITHUB_RUN_ID: ${{ github.run_id }}
steps:
- uses: actions/checkout@v3
- name: Deploy
uses: ./.github/actions/k3s-deploy
with:
image: stablecog/sc-server:${{ needs.setup_env.outputs.branch_name}}-${{ env.GITHUB_RUN_ID }}
embed-title: "[GO Apps] ${{ needs.setup_env.outputs.commit_msg }} • ${{ needs.setup_env.outputs.short_sha }}"
prod-webhook-url: ${{ secrets.DISCORD_WEBHOOK_PROD }}
qa-webhook-url: ${{ secrets.DISCORD_WEBHOOK }}
kube_config: ${{ secrets.K3S_KUBE_CONFIG }}
env: prod
# release_pull_request:
# runs-on: ubuntu-latest
# name: 🚦 Create Release PR
# needs:
# - test
# - build
# steps:
# - uses: actions/checkout@v3
# with:
# fetch-depth: 0
# - name: Create/Update Pull Request
# uses: devops-infra/action-pull-request@v0.5.5
# with:
# github_token: ${{ secrets.GITHUB_TOKEN }}
# assignee: ${{ github.actor }}
# label: automatic,release
# target_branch: production
# template: .github/RELEASE_PR.md
# get_diff: true