From 3aa2d1cd506019e4798ff41682f0013d27eadf7b Mon Sep 17 00:00:00 2001 From: Pavel Korchagin Date: Sat, 3 Feb 2024 23:21:21 +0300 Subject: [PATCH 1/2] chore: update README.md --- README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c1a33f1..4336aae 100644 --- a/README.md +++ b/README.md @@ -3,9 +3,7 @@ ![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 @@ -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 From ba23d355b5037eeb1ef337feb98dd9025d0d8ddb Mon Sep 17 00:00:00 2001 From: Pavel Korchagin Date: Sat, 3 Feb 2024 23:21:27 +0300 Subject: [PATCH 2/2] chore: improve ci --- .github/workflows/integration_test.yml | 50 ++++++++++++++ .github/workflows/lint.yml | 16 +++++ .github/workflows/main.yml | 95 -------------------------- .github/workflows/publish.yml | 31 +++++++++ .github/workflows/pull_request.yml | 16 +++++ .github/workflows/release.yml | 9 +++ .github/workflows/unit_test.yml | 50 ++++++++++++++ 7 files changed, 172 insertions(+), 95 deletions(-) create mode 100644 .github/workflows/integration_test.yml create mode 100644 .github/workflows/lint.yml delete mode 100644 .github/workflows/main.yml create mode 100644 .github/workflows/publish.yml create mode 100644 .github/workflows/pull_request.yml create mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/unit_test.yml diff --git a/.github/workflows/integration_test.yml b/.github/workflows/integration_test.yml new file mode 100644 index 0000000..1931d1d --- /dev/null +++ b/.github/workflows/integration_test.yml @@ -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 \ No newline at end of file diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..f3454c6 --- /dev/null +++ b/.github/workflows/lint.yml @@ -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 \ No newline at end of file diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml deleted file mode 100644 index b148a2f..0000000 --- a/.github/workflows/main.yml +++ /dev/null @@ -1,95 +0,0 @@ -name: CI -on: - push: - branches: - - master - pull_request: - branches: - - master - - workflow_dispatch: - -jobs: - lint: - runs-on: ubuntu-latest - steps: - - name: Check out repository code - uses: actions/checkout@v2 - - - name: Run golangci-lint - uses: golangci/golangci-lint-action@v2 - with: - version: v1.54.2 - - test: - needs: lint - 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@v2 - - - name: Install Go - uses: actions/setup-go@v2 - with: - go-version: 1.21 - - - name: Run unit tests - run: go test -v -coverprofile=cover.out ./internal/... ./pkg/... && go tool cover -func=cover.out - - - name: Run integration tests - run: go test -v ./test/... -run TestAppTestSuite - - publish: - needs: test - if: github.event_name == 'push' && github.ref == 'refs/heads/master' - runs-on: ubuntu-latest - - steps: - - name: Check out repository code - uses: actions/checkout@v2 - - - name: Login to Docker Hub - uses: docker/login-action@v1 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - - - name: Build docker image and push into registry - uses: docker/build-push-action@v2 - with: - push: true - context: . - tags: | - mortalis/chatyx-backend:0.1.0 - mortalis/chatyx-backend:latest diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..ced30d6 --- /dev/null +++ b/.github/workflows/publish.yml @@ -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 }} \ No newline at end of file diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml new file mode 100644 index 0000000..f6cd119 --- /dev/null +++ b/.github/workflows/pull_request.yml @@ -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 \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..c46888c --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,9 @@ +name: Release + +on: + release: + types: [ published ] + +jobs: + publish: + uses: ./.github/workflows/publish.yml \ No newline at end of file diff --git a/.github/workflows/unit_test.yml b/.github/workflows/unit_test.yml new file mode 100644 index 0000000..b53f0bc --- /dev/null +++ b/.github/workflows/unit_test.yml @@ -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 }} \ No newline at end of file