-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from kynmh69/17-feature-add-to-get-code-coverage
feature add to get code coverage #17 create coverage action
- Loading branch information
Showing
2 changed files
with
112 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters