Skip to content

feat: add action that runs using source #188

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 5, 2025
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
@@ -1,4 +1,4 @@
name: action-test
name: action-test (docker version)
on: [push]
jobs:
build-dev-image:
Expand Down Expand Up @@ -65,7 +65,7 @@ jobs:
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 == '' }}
if: ${{ steps.test-1.outputs.total-coverage == '' || steps.test-1.outputs.badge-text == '' || steps.test-1.outputs.badge-color == '' || steps.test-1.outputs.report == '' }}
run: echo "Previous step should have output values" && exit 1

## Test 2
Expand Down
108 changes: 108 additions & 0 deletions .github/workflows/action-source-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
name: action-test (source version)
on: [push]
jobs:
test:
name: test
runs-on: ubuntu-latest

steps:
- name: checkout
uses: actions/checkout@v4

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

- name: generate test coverage
run: go test ./... -coverprofile=./cover.out -covermode=atomic

## Test 1

- name: "test: total coverage 0% (config)"
uses: ./action/source/.
id: test-1
with:
version: ${{ github.sha }}
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 == '' || steps.test-1.outputs.report == '' }}
run: echo "Previous step should have output values" && exit 1

## Test 2

- name: "test: total coverage 100% (config)"
uses: ./action/source/.
id: test-2
continue-on-error: true
with:
version: ${{ github.sha }}
config: ./.github/workflows/testdata/total100.yml

- name: "check: test should have failed"
if: steps.test-2.outcome != 'failure'
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 == '' }}
run: echo "Previous step should have output values" && exit 1

## Test 3

- name: "test: total coverage 0% (inputs)"
uses: ./action/source/.
id: test-3
with:
version: ${{ github.sha }}
profile: cover.out
threshold-file: 0
threshold-package: 0
threshold-total: 0

## Test 4

- name: "test: total coverage 100% (inputs)"
uses: ./action/source/.
id: test-4
continue-on-error: true
with:
version: ${{ github.sha }}
profile: cover.out
threshold-file: 0
threshold-package: 0
threshold-total: 100

- name: "check: test should have failed"
if: steps.test-4.outcome != 'failure'
run: echo "Previous step should have failed" && exit 1

## Test 5

- name: "test: override config"
uses: ./action/source/.
id: test-5
with:
version: ${{ github.sha }}
config: ./.github/workflows/testdata/total100.yml
threshold-file: 0
threshold-package: 0
threshold-total: 0

## Test 6

- name: "test: debug output"
uses: ./action/source/.
id: test-6
continue-on-error: true
with:
version: ${{ github.sha }}
profile: unexistant-profile.out
debug: true
threshold-file: 0
threshold-package: 0
threshold-total: 100

- name: "check: test should have failed"
if: steps.test-6.outcome != 'failure'
run: echo "Previous step should have failed" && exit 1
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# GO_VERSION: automatically update to most recent via dependabot
FROM golang:1.24.3 as builder
FROM golang:1.24.3 AS builder
WORKDIR /workspace

COPY go.mod go.mod
Expand Down
42 changes: 21 additions & 21 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: go-test-coverage
author: vladopajic
description: go-test-coverage is a tool designed to report issues when test coverage falls below a specified threshold.
branding:
icon: 'code'
color: 'blue'

inputs:
# Config
config:
Expand Down Expand Up @@ -137,32 +141,28 @@ outputs:

runs:
using: docker
# VERSION: when changing version update version in other places
# TOOL_VERSION: when changing version update version in other places
image: docker://ghcr.io/vladopajic/go-test-coverage:v2.14.3
args:
- --config=${{ inputs.config || '''''' }}
- --profile=${{ inputs.profile || '''''' }}
- --source-dir=${{ inputs.source-dir || '''''' }}
- --config=${{ inputs.config || '***' }}
- --profile=${{ inputs.profile || '***' }}
- --source-dir=${{ inputs.source-dir || '***' }}
- --debug=${{ inputs.debug }}
- --github-action-output=true
- --threshold-file=${{ inputs.threshold-file }}
- --threshold-package=${{ inputs.threshold-package }}
- --threshold-total=${{ inputs.threshold-total }}
- --breakdown-file-name=${{ inputs.breakdown-file-name || '''''' }}
- --diff-base-breakdown-file-name=${{ inputs.diff-base-breakdown-file-name || '''''' }}
- --badge-file-name=${{ inputs.badge-file-name || '''''' }}
- --cdn-key=${{ inputs.cdn-key || '''''' }}
- --cdn-secret=${{ inputs.cdn-secret || '''''' }}
- --cdn-region=${{ inputs.cdn-region || '''''' }}
- --cdn-endpoint=${{ inputs.cdn-endpoint || '''''' }}
- --cdn-file-name=${{ inputs.cdn-file-name || '''''' }}
- --cdn-bucket-name=${{ inputs.cdn-bucket-name || '''''' }}
- --breakdown-file-name=${{ inputs.breakdown-file-name || '***' }}
- --diff-base-breakdown-file-name=${{ inputs.diff-base-breakdown-file-name || '***' }}
- --badge-file-name=${{ inputs.badge-file-name || '***' }}
- --cdn-key=${{ inputs.cdn-key || '***' }}
- --cdn-secret=${{ inputs.cdn-secret || '***' }}
- --cdn-region=${{ inputs.cdn-region || '***' }}
- --cdn-endpoint=${{ inputs.cdn-endpoint || '***' }}
- --cdn-file-name=${{ inputs.cdn-file-name || '***' }}
- --cdn-bucket-name=${{ inputs.cdn-bucket-name || '***' }}
- --cdn-force-path-style=${{ inputs.cdn-force-path-style }}
- --git-token=${{ inputs.git-token || '''''' }}
- --git-branch=${{ inputs.git-branch || '''''' }}
- --git-repository=${{ inputs.git-repository || ''''''}}
- --git-file-name=${{ inputs.git-file-name || '''''' }}

branding:
icon: 'code'
color: 'blue'
- --git-token=${{ inputs.git-token || '***' }}
- --git-branch=${{ inputs.git-branch || '***' }}
- --git-repository=${{ inputs.git-repository || '***'}}
- --git-file-name=${{ inputs.git-file-name || '***' }}
193 changes: 193 additions & 0 deletions action/source/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
name: go-test-coverage (as source)
author: vladopajic
description: go-test-coverage is a tool designed to report issues when test coverage falls below a specified threshold.
branding:
icon: 'code'
color: 'blue'

inputs:
# Config
config:
description: Path to the configuration file (.testcoverage.yml), which defines test coverage settings and thresholds.
required: false
default: ""
type: string
source-dir:
description: Sets relative path to source files.
required: false
default: ""
type: string
debug:
description: Prints additional debugging output when running action.
required: false
default: false
type: boolean

# Individual properties
profile:
description: Path to the coverage profile file. Overrides value from configuration.
required: false
default: ""
type: string
# DEPRECATED
local-prefix:
description: DEPRECATED! not used anymore.
required: false
default: ""
type: string
threshold-file:
description: Minimum coverage percentage required for individual files. Overrides value from configuration.
required: false
default: -1
type: number
threshold-package:
description: Minimum coverage percentage required for each package. Overrides value from configuration.
required: false
default: -1
type: number
threshold-total:
description: Minimum overall project coverage percentage required. Overrides value from configuration.
required: false
default: -1
type: number

breakdown-file-name:
description: File name of go-test-coverage breakdown file, which can be used to analyze coverage difference. Overrides value from configuration.
required: false
default: ""
type: string

diff-base-breakdown-file-name:
description: File name of go-test-coverage breakdown file used to calculate coverage difference from current (head).
required: false
default: ""
type: string

# Badge (as file)
badge-file-name:
description: If specified, a coverage badge will be generated and saved to the given file path.
required: false
default: ""
type: string

# Badge (on CDN)
cdn-secret:
description: API secret key for CDN. If specified, the badge will be uploaded to the CDN.
required: false
default: ""
type: string
cdn-key:
description: API key for CDN access.
required: false
default: ""
type: string
cdn-region:
description: Specifies the CDN region for the badge upload.
required: false
default: ""
type: string
cdn-endpoint:
description: URL endpoint for CDN where the badge will be uploaded.
required: false
default: ""
type: string
cdn-file-name:
description: Filename (including path) for storing the badge on the CDN.
required: false
default: ""
type: string
cdn-bucket-name:
description: Name of the CDN bucket where the badge will be saved.
required: false
default: ""
type: string
cdn-force-path-style:
description: Forces path-style URL access in the CDN.
required: false
default: false
type: boolean

# Badge (on Git)
git-token:
description: GitHub token for authorization. If provided, the badge will be uploaded to the specified GitHub repository.
required: false
default: ""
type: string
git-repository:
description: Target GitHub repository in {owner}/{repository} format where the badge will be stored.
required: false
default: ${{ github.repository }}
type: string
git-branch:
description: Repository branch where the badge file will be saved.
required: false
default: ""
type: string
git-file-name:
description: File name (including path) for storing the badge in the specified repository.
required: false
default: .badges/${{ github.ref_name }}/coverage.svg
type: string

version:
description: Version of go-test-coverage source to run
required: false
# TOOL_VERSION: when changing version update version in other places
default: v2.14.3
type: string

outputs:
report:
description: JSON-encoded string containing the detailed test coverage report.
value: ${{steps.coverage.outputs.report}}
total-coverage:
description: Integer value in the range [0-100], representing the overall project test coverage percentage.
value: ${{steps.coverage.outputs.total-coverage}}
badge-color:
description: Color hex code for the badge (e.g., `#44cc11`), representing the coverage status.
value: ${{steps.coverage.outputs.badge-color}}
badge-text:
description: Deprecated! Text label for the badge.
value: ${{steps.coverage.outputs.badge-text}}

runs:
using: composite
steps:
- name: check if go is installed
shell: bash
run: |
if command -v go >/dev/null 2>&1; then
echo "Go is installed"
go version
else
echo "Go is NOT installed. Please install Go before running this action."
exit 1
fi

- name: run go-test-coverage
id: coverage
shell: bash
run: |
go run github.com/vladopajic/go-test-coverage/v2@${{ inputs.version }} \
--config=${{ inputs.config || '***' }} \
--profile=${{ inputs.profile || '***' }} \
--source-dir=${{ inputs.source-dir || '***' }} \
--debug=${{ inputs.debug }} \
--github-action-output=true \
--threshold-file=${{ inputs.threshold-file }} \
--threshold-package=${{ inputs.threshold-package }} \
--threshold-total=${{ inputs.threshold-total }} \
--breakdown-file-name=${{ inputs.breakdown-file-name || '***' }} \
--diff-base-breakdown-file-name=${{ inputs.diff-base-breakdown-file-name || '***' }} \
--badge-file-name=${{ inputs.badge-file-name || '***' }} \
--cdn-key=${{ inputs.cdn-key || '***' }} \
--cdn-secret=${{ inputs.cdn-secret || '***' }} \
--cdn-region=${{ inputs.cdn-region || '***' }} \
--cdn-endpoint=${{ inputs.cdn-endpoint || '***' }} \
--cdn-file-name=${{ inputs.cdn-file-name || '***' }} \
--cdn-bucket-name=${{ inputs.cdn-bucket-name || '***' }} \
--cdn-force-path-style=${{ inputs.cdn-force-path-style }} \
--git-token=${{ inputs.git-token || '***' }} \
--git-branch=${{ inputs.git-branch || '***' }} \
--git-repository=${{ inputs.git-repository || '***'}} \
--git-file-name=${{ inputs.git-file-name || '***' }}
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

const (
Version = "v2.14.3" // VERSION: when changing version update version in other places
Version = "v2.14.3" // TOOL_VERSION: when changing version update version in other places
Name = "go-test-coverage"
)

Expand Down
Loading
Loading