Skip to content

Commit

Permalink
Merge pull request #20 from kynmh69/17-feature-add-to-get-code-coverage
Browse files Browse the repository at this point in the history
feature add to get code coverage #17 create coverage action
  • Loading branch information
kynmh69 authored Mar 20, 2024
2 parents 46480b2 + 55c4fd7 commit e48a83e
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 1 deletion.
111 changes: 111 additions & 0 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
name: "Codecov Go test"
on:
push:
branches:
- main
tags:
- 'v*.*.*'
pull_request:
branches:
- main
env:
UPDATER_DIR: "src/updater"
API_DIR: "src/api"

jobs:
coverage-updater:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:16
env:
POSTGRES_USER: app
POSTGRES_PASSWORD: password
POSTGRES_DB: unittest
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.22'
cache-dependency-path: |
src/go.sum
- name: Run migration
working-directory: ${{ env.UPDATER_DIR }}
shell: bash -l {0}
run: |
go install github.com/pressly/goose/v3/cmd/goose@latest
$(go env GOPATH)/bin/goose --dir database/migrations/ postgres "host=localhost user=app password=password dbname=unittest sslmode=disable" up
- name: Build
working-directory: ${{ env.UPDATER_DIR }}
run: go build -v ./...

- name: Test
working-directory: ${{ env.UPDATER_DIR }}
env:
COV_FILE_NAME: coverage.txt
MODE: atomic
run: go test -v -race -coverprofile=${{ env.COV_FILE_NAME }} -covermode=${{ env.MODE }} ./...

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
flags: smart-tests
verbose: true
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

coverage-api:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:16
env:
POSTGRES_USER: app
POSTGRES_PASSWORD: password
POSTGRES_DB: unittest
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.22'
cache-dependency-path: |
src/go.sum
- name: Run migration
working-directory: ${{ env.API_DIR }}
shell: bash -l {0}
run: |
go install github.com/pressly/goose/v3/cmd/goose@latest
$(go env GOPATH)/bin/goose --dir database/migrations/ postgres "host=localhost user=app password=password dbname=unittest sslmode=disable" up
- name: Build
working-directory: ${{ env.API_DIR }}
run: go build -v ./...

- name: Test
working-directory: ${{ env.API_DIR }}
env:
COV_FILE_NAME: coverage.txt
MODE: atomic
run: go test -v -race -coverprofile=${{ env.COV_FILE_NAME }} -covermode=${{ env.MODE }} ./...

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
flags: smart-tests
verbose: true
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/docker-publish-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
if: github.event_name != 'pull_request'
uses: sigstore/cosign-installer@v3 #v3.1.1
with:
cosign-release: 'v2.1.1'
cosign-release: 'v2.2.3'

# Set up BuildKit Docker container builder to be able to build
# multi-platform images and export cache
Expand Down

0 comments on commit e48a83e

Please sign in to comment.