Skip to content

Commit

Permalink
chore: improve ci
Browse files Browse the repository at this point in the history
  • Loading branch information
Mort4lis committed Feb 4, 2024
1 parent 3aa2d1c commit ba23d35
Show file tree
Hide file tree
Showing 7 changed files with 172 additions and 95 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/integration_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Integration test

on:
workflow_call:

jobs:
integration_test:
runs-on: ubuntu-latest
env:
TZ: Europe/Moscow
DB_USER: chatyx_user
DB_PASSWORD: chatyx_password
DB_NAME: chatyx_db_test

services:
postgres:
image: postgres:15.4
env:
POSTGRES_USER: ${{ env.DB_USER }}
POSTGRES_PASSWORD: ${{ env.DB_PASSWORD }}
POSTGRES_DB: ${{ env.DB_NAME }}
options: >-
--health-cmd "pg_isready"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 15432:5432

redis:
image: redis:7.2
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 16379:6379

steps:
- name: Check out repository code
uses: actions/checkout@v4

- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.21

- name: Run test
run: go test -v ./test/... -run TestAppTestSuite
16 changes: 16 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Lint

on:
workflow_call:

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Check out repository code
uses: actions/checkout@v4

- name: Run golangci-lint
uses: golangci/golangci-lint-action@v2
with:
version: v1.54.2
95 changes: 0 additions & 95 deletions .github/workflows/main.yml

This file was deleted.

31 changes: 31 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Publish Docker image

on:
workflow_call:

jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Check out repository code
uses: actions/checkout@v4

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: mortalis/chatyx-backend

- name: Build docker image and push into registry
uses: docker/build-push-action@v5
with:
push: true
context: .
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
16 changes: 16 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Pull request

on:
pull_request:
branches:
- master

jobs:
lint:
uses: ./.github/workflows/lint.yml
unit_test:
needs: lint
uses: ./.github/workflows/unit_test.yml
integration_test:
needs: unit_test
uses: ./.github/workflows/integration_test.yml
9 changes: 9 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: Release

on:
release:
types: [ published ]

jobs:
publish:
uses: ./.github/workflows/publish.yml
50 changes: 50 additions & 0 deletions .github/workflows/unit_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Unit test

on:
workflow_call:

jobs:
unit_test:
runs-on: ubuntu-latest
steps:
- name: Check out repository code
uses: actions/checkout@v4
with:
persist-credentials: false
fetch-depth: 0

- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.21

- name: Run test
run: |
go test -v ./internal/... ./pkg/... -covermode=count -coverprofile=coverage.out
go tool cover -func=coverage.out -o=coverage.out
- name: Go coverage badge
uses: tj-actions/coverage-badge-go@v2
with:
filename: coverage.out

- name: Verify changed files
uses: tj-actions/verify-changed-files@v16
id: verify-changed-files
with:
files: README.md

- name: Commit changes
if: steps.verify-changed-files.outputs.files_changed == 'true'
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add README.md
git commit -m "chore: update coverage badge"
- name: Push changes
if: steps.verify-changed-files.outputs.files_changed == 'true'
uses: ad-m/github-push-action@master
with:
github_token: ${{ github.token }}
branch: ${{ github.head_ref }}

0 comments on commit ba23d35

Please sign in to comment.