Skip to content

Commit

Permalink
Merge pull request #6 from Chatyx/feature/ci-improve
Browse files Browse the repository at this point in the history
Improve ci
  • Loading branch information
Mort4lis authored Feb 4, 2024
2 parents d8698b1 + a693c4c commit 6fc4dc0
Show file tree
Hide file tree
Showing 8 changed files with 175 additions and 99 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 }}
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
# Chatyx Backend

![Coverage](https://img.shields.io/badge/Coverage-70.7%25-brightgreen)
![ci](https://github.com/Mort4lis/scht-backend/actions/workflows/main.yml/badge.svg)
![license](https://img.shields.io/github/license/Chatyx/backend)
![go-version](https://img.shields.io/github/go-mod/go-version/Chatyx/backend)
![docker-pulls](https://img.shields.io/docker/pulls/mortalis/chatyx-backend)
![code-size](https://img.shields.io/github/languages/code-size/Chatyx/backend)
![total-lines](https://img.shields.io/tokei/lines/github/Chatyx/backend)
[![Go Report Card](https://goreportcard.com/badge/github.com/Chatyx/backend)](https://goreportcard.com/report/github.com/Chatyx/backend)

## 📖 Description

Expand All @@ -22,6 +20,7 @@ Already done:
* ✅ Block partners in dialogs

Not done yet:
* ❌ Support uploading images
* ❌ View unread messages
* ❌ Show online/offline statuses of users, as well as when the user was last online
* ❌ Notifications if user isn't online
Expand Down

0 comments on commit 6fc4dc0

Please sign in to comment.