diff --git a/.github/workflows/.testcoverage.yml b/.github/.testcoverage.yml similarity index 93% rename from .github/workflows/.testcoverage.yml rename to .github/.testcoverage.yml index d4964d6a..894b2d79 100644 --- a/.github/workflows/.testcoverage.yml +++ b/.github/.testcoverage.yml @@ -6,4 +6,4 @@ local-prefix: "github.com/vladopajic/go-test-coverage" threshold: file: 0 package: 0 - total: 63 + total: 65 diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml index d01a6eaa..ace6a2a1 100644 --- a/.github/workflows/integration-test.yml +++ b/.github/workflows/integration-test.yml @@ -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 @@ -43,27 +41,43 @@ 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" @@ -71,9 +85,11 @@ jobs: 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 @@ -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 \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8f9889e2..41d11906 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -17,10 +17,10 @@ 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" @@ -28,23 +28,20 @@ jobs: 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 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1e66d576..ad84e28f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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') diff --git a/action.yml b/action.yml index 68ace10a..c83e2eac 100644 --- a/action.yml +++ b/action.yml @@ -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 diff --git a/pkg/testcoverage/report.go b/pkg/testcoverage/report.go index 67bf6222..6c22b727 100644 --- a/pkg/testcoverage/report.go +++ b/pkg/testcoverage/report.go @@ -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 {