Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ local-prefix: "github.com/vladopajic/go-test-coverage"
threshold:
file: 0
package: 0
total: 63
total: 65
58 changes: 36 additions & 22 deletions .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,26 @@ jobs:
steps:
- name: checkout
uses: actions/checkout@v3

- name: setup go
uses: actions/setup-go@v3
with:
go-version-file: go.mod

- name: Set action image version to dev
- name: set action image version to dev
run: |
yq e -i '.runs.image = "docker://ghcr.io/vladopajic/go-test-coverage:dev"' action.yml
image=$(yq '.runs.image' action.yml)
echo "Image: $image"

- name: Setup buildx
uses: docker/setup-buildx-action@v2

- name: Login to GitHub container registry
- name: login to GitHub container registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
- name: build and push
uses: docker/build-push-action@v4
with:
push: true
Expand All @@ -43,37 +41,55 @@ jobs:
- name: generate test coverage
run: go test ./... -coverprofile=./cover.out -covermode=atomic

- name: Test total coverage 0% (config)
## Test 1

- name: "test: total coverage 0% (config)"
uses: ./
id: test-1
with:
config: ./.github/workflows/testdata/zero.yml

- name: "check: test output values"
if: ${{ steps.test-1.outputs.total-coverage == '' || steps.test-1.outputs.badge-text == '' || steps.test-1.outputs.badge-color == '' }}
shell: bash
run: echo "Previous step should have output values" && exit 1

## Test 2

- name: Test total coverage 100% (config)
- name: "test: total coverage 100% (config)"
uses: ./
id: should-fail-1
id: test-2
continue-on-error: true
with:
config: ./.github/workflows/testdata/total100.yml

- name: Check previous step failed
if: steps.should-fail-1.outcome != 'failure'
- name: "check: test should have failed"
if: steps.test-2.outcome != 'failure'
shell: bash
run: |
echo "Previous step should have failed"
exit 1
run: echo "Previous step should have failed" && exit 1

- name: "check: test output values"
if: ${{ steps.test-2.outputs.total-coverage == '' || steps.test-2.outputs.badge-text == '' || steps.test-2.outputs.badge-color == '' }}
shell: bash
run: echo "Previous step should have output values" && exit 1

- name: Test total coverage 0% (inputs)
## Test 3

- name: "test: total coverage 0% (inputs)"
uses: ./
id: test-3
with:
profile: cover.out
local-prefix: "github.com/vladopajic/go-test-coverage"
threshold-file: 0
threshold-package: 0
threshold-total: 0

- name: Test total coverage 100% (inputs)
## Test 4

- name: "test: total coverage 100% (inputs)"
uses: ./
id: should-fail-2
id: test-4
continue-on-error: true
with:
profile: cover.out
Expand All @@ -82,9 +98,7 @@ jobs:
threshold-package: 0
threshold-total: 100

- name: Check previous step failed
if: steps.should-fail-2.outcome != 'failure'
- name: "check: test should have failed"
if: steps.test-4.outcome != 'failure'
shell: bash
run: |
echo "Previous step should have failed"
exit 1
run: echo "Previous step should have failed" && exit 1
13 changes: 5 additions & 8 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,31 @@ jobs:
with:
go-version-file: go.mod

- name: Set RELEASE_VERSION ENV var
- name: set RELEASE_VERSION ENV var
run: echo "RELEASE_VERSION=${GITHUB_REF:10}" >> $GITHUB_ENV

- name: Ensure container version is updated to release version
- name: ensure container version is updated to release version
run: |
image=$(yq '.runs.image' action.yml)
echo "Image: $image"
imageVer=${image:(-6)}
echo "Image version: $imageVer, Release version: ${{ env.RELEASE_VERSION }}"
[[ "$imageVer" == "${{ env.RELEASE_VERSION }}" ]]

- name: Update the major version tag
- name: update the major version tag
id: majorver
uses: actions/publish-action@v0.2.2
with:
source-tag: ${{ env.RELEASE_VERSION }}

- name: Setup buildx
uses: docker/setup-buildx-action@v2

- name: Login to GitHub container registry
- name: login to GitHub container registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
- name: build and push
uses: docker/build-push-action@v4
with:
push: true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
id: coverage
uses: vladopajic/go-test-coverage@v2
with:
config: ./.github/workflows/.testcoverage.yml
config: ./.github/.testcoverage.yml
- name: make coverage badge
uses: action-badges/core@0.2.2
if: contains(github.ref, 'main')
Expand Down
6 changes: 5 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,12 @@ inputs:
default: 50
type: number
outputs:
total_coverage:
total-coverage:
description: Holds total coverage value.
badge-text:
description: Holds badge text value.
badge-color:
description: Holds badge color value.
runs:
using: docker
image: docker://ghcr.io/vladopajic/go-test-coverage:v2.0.0
Expand Down
6 changes: 3 additions & 3 deletions pkg/testcoverage/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ func ReportForGithubAction(w io.Writer, result AnalyzeResult, cfg Config) {

const (
gaOutputFileEnv = "GITHUB_OUTPUT"
gaOutputTotalCoverage = "total_coverage"
gaOutputBadgeColor = "badge_color"
gaOutputBadgeText = "badge_text"
gaOutputTotalCoverage = "total-coverage"
gaOutputBadgeColor = "badge-color"
gaOutputBadgeText = "badge-text"
)

func SetGithubActionOutput(result AnalyzeResult) error {
Expand Down