From 9fa164e94bc1dd924cbca02f52673878b78aed48 Mon Sep 17 00:00:00 2001 From: kynmh69 Date: Wed, 20 Mar 2024 15:14:15 +0900 Subject: [PATCH 1/2] feature add to get code coverage #17 create coverage action --- .github/workflows/codecov.yml | 111 +++++++++++++++++++++++ .github/workflows/docker-publish-api.yml | 2 +- 2 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/codecov.yml diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml new file mode 100644 index 0000000..9228694 --- /dev/null +++ b/.github/workflows/codecov.yml @@ -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 }} + + test-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 }} diff --git a/.github/workflows/docker-publish-api.yml b/.github/workflows/docker-publish-api.yml index 3d1fa5f..02aaaad 100644 --- a/.github/workflows/docker-publish-api.yml +++ b/.github/workflows/docker-publish-api.yml @@ -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 From 55c4fd72d69d765f0a237f5af3239cf50796d518 Mon Sep 17 00:00:00 2001 From: kynmh69 Date: Wed, 20 Mar 2024 15:20:55 +0900 Subject: [PATCH 2/2] feature add to get code coverage #17 create coverage action --- .github/workflows/codecov.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml index 9228694..33484fe 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/codecov.yml @@ -61,7 +61,7 @@ jobs: env: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} - test-api: + coverage-api: runs-on: ubuntu-latest services: postgres: