Skip to content
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

Add option to exclude directories from go test #99

Merged
merged 1 commit into from
Nov 14, 2024
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
2 changes: 2 additions & 0 deletions .github/workflows/go-common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ env:
RACE_DETECTOR: ${{ vars.RACE_DETECTOR || true }}
SKIP_TEST: ${{ vars.SKIP_TEST || '' }}
RUN_TEST: ${{ vars.RUN_TEST || '' }}
EXCLUDE_DIRECTORIES: ${{ vars.EXCLUDE_DIRECTORIES || '' }}

# gosec action
GOSEC_EXCLUDES: ${{ vars.GOSEC_EXCLUDES || '' }}
Expand All @@ -44,6 +45,7 @@ jobs:
race-detector: ${{ env.RACE_DETECTOR }}
skip-test: ${{ env.SKIP_TEST }}
run-test: ${{ env.RUN_TEST }}
exclude-directory: ${{ env.EXCLUDE_DIRECTORIES }}

# Check sources for security vulnerabilities
security:
Expand Down
4 changes: 4 additions & 0 deletions go-code-tester/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ jobs:
skip-test: "TestToSkip"
# Optional parameter to specify regex for tests to run
run-test: "TestToRun"
# Optional paramter to exlude certain directories from go test. Ex. intregration test folders.
exclude-directory: "DirectoryToExclude|DirectoryToExclude2"
```

The `threshold` for the Action is a coverage percentage threshold that every package must meet. The default `threshold` is 90.
Expand All @@ -48,3 +50,5 @@ The `race-detector` is an optional boolean parameter to enable or disable the ra
The `skip-test` is a regex and passed directly as the -skip option to the `go test` command.

The `run-test` is a regex and passed directly as the -run option to the `go test` command.

The `exclude-directory` is an optional parameter to filter out directories you want to exclude from the `go test` command.
5 changes: 5 additions & 0 deletions go-code-tester/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ inputs:
description: 'Regex to specify tests to run'
required: false
default: ""
exclude-directory:
description: 'Name of directory to be excluded from go test'
required: false
default: ""
runs:
using: 'docker'
image: 'Dockerfile'
Expand All @@ -42,6 +46,7 @@ runs:
- ${{ inputs.race-detector }}
- ${{ inputs.skip-test }}
- ${{ inputs.run-test }}
- ${{ inputs.exclude-directory }}
branding:
icon: 'shield'
color: 'blue'
12 changes: 9 additions & 3 deletions go-code-tester/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ SKIP_LIST=$3
RACE_DETECTOR=$4
SKIP_TEST=$5
RUN_TEST=$6
EXCLUDE_DIRECTORIES=$7

skip_options=""
run_options=""
Expand All @@ -31,10 +32,15 @@ fi
go clean -testcache

cd ${TEST_FOLDER}
if [[ -z $RACE_DETECTOR ]] || [[ $RACE_DETECTOR == "true" ]]; then
GOEXPERIMENT=nocoverageredesign go test $skip_options -v -short -race -count=1 -cover $run_options ./... > ~/run.log
if [[ -n $EXCLUDE_DIRECTORIES ]]; then
echo "excluding the following directories: $EXCLUDE_DIRECTORIES"
if [[ -z $RACE_DETECTOR ]] || [[ $RACE_DETECTOR == "true" ]]; then
GOEXPERIMENT=nocoverageredesign go test $skip_options -v $(go list ./... | grep -vE $EXCLUDE_DIRECTORIES) -short -race -count=1 -cover $run_options ./... > ~/run.log
else
# Run without the race flag
GOEXPERIMENT=nocoverageredesign go test $skip_options -v $(go list ./... | grep -vE $EXCLUDE_DIRECTORIES) -short -count=1 -cover $run_options ./... > ~/run.log
fi
else
# Run without the race flag
GOEXPERIMENT=nocoverageredesign go test $skip_options -v -short -count=1 -cover $run_options ./... > ~/run.log
fi

Expand Down