Skip to content

Commit ede89a7

Browse files
authored
299 add partial testing (#1) (#381)
* feat: add partial testing (#299) * docs: add configuration options for GTA base branch and partial testing * feat: add conditional task execution for GTA partial testing * fix: update conditional check for gta-partial-testing input type * fix: update conditional check for gta-partial-testing input type to handle string input * fix: improve PKGS assignment for partial testing and handle errors * fix: update default GTA base branch to use origin/main * fix: update GTA base branch handling in partial testing task * fix: remove unnecessary git branch command from golang-log task * fix: add git diff command to golang-log task for better change tracking * fix: update GTA base branch reference in partial testing task * fix: update GTA base branch alias in task configuration * fix: add git branch command to golang-log task for improved branch management * fix: enhance partial test suite message with base branch details * fix: update partial test suite message and adjust base branch reference * fix: update GTA base branch default value and remove alias * docs: add note fetch-depth needed * fix: add GTA_VERSION to updater script * fix: add removed comment back * fix: update GTA_VERSION package source to DigitalOcean * fix: remove unnecessary newline in test task definition
1 parent 6a10477 commit ede89a7

4 files changed

Lines changed: 62 additions & 2 deletions

File tree

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,11 +232,15 @@ jobs:
232232
test-timeout: 10m0s
233233
steps:
234234
- uses: actions/checkout@v4.1.1
235+
with:
236+
fetch-depth: 0 # this is necessary for gta partial testing
235237
- uses: schubergphilis/mcvs-golang-action@v0.9.0
236238
with:
237239
build-tags: ${{ matrix.args.build-tags }}
238240
golang-unit-tests-exclusions: |-
239241
\(cmd\/some-app\|internal\/app\/some-app\)
242+
gta-base-branch: main
243+
gta-partial-testing: true
240244
release-architecture: ${{ matrix.args.release-architecture }}
241245
release-dir: ${{ matrix.args.release-dir }}
242246
release-type: ${{ matrix.args.release-type }}
@@ -260,8 +264,10 @@ and a [.golangci.yml](https://golangci-lint.run/usage/configuration/).
260264
| code-coverage-timeout | | | Timeout duration for code coverage analysis (e.g., "10m0s") |
261265
| github-token-for-downloading-private-go-modules | | | GitHub token with permissions to download Go modules from private repositories |
262266
| golangci-timeout | x | | Timeout duration for golangci-lint execution |
263-
| golang-unit-tests-exclusions | x | | Regex pattern to exclude specific packages from unit testing (e.g., `\(cmd\/app\|internal\/app\)`) |
267+
| golang-unit-tests-exclusions | x | | Regex pattern to exclude specific packages from unit testing (e.g., `\(cmd\/app\|internal\/app\)`) |
264268
| grype-version | | | Specific version of Grype vulnerability scanner to use |
269+
| gta-base-branch | x | | The branch changed go packages will be compared to, to perform partial tests |
270+
| gta-partial-testing | x | | Whether to run partial tests (true or false) |
265271
| release-application-name | | | Name of the application binary to build (required when release-type is set) |
266272
| release-architecture | | | Target architecture for the binary (e.g., "amd64", "arm64") |
267273
| release-build-tags | | | Build tags to use when building the release binary (e.g., "lambda.norpc") |
@@ -276,6 +282,7 @@ and a [.golangci.yml](https://golangci-lint.run/usage/configuration/).
276282
| trivy-action-db | x | | Trivy vulnerability database configuration |
277283
| trivy-action-java-db | x | | Trivy Java vulnerability database configuration |
278284

285+
279286
Note: If an **x** is registered in the Default column, refer to the
280287
[action.yml](action.yml) for the corresponding value.
281288

action.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ inputs:
3535
disabled.
3636
grype-version:
3737
description: The grype version to be used by the anchore/scan-action.
38+
gta-base-branch:
39+
default: main
40+
description: |
41+
The base branch to compare changed code to.
42+
gta-partial-testing:
43+
default: false
44+
description: |
45+
Whether partial testing should be performed. Only changed packages will be
46+
tested.
3847
release-application-name:
3948
description: |
4049
The name of the application that has to be released.
@@ -262,13 +271,23 @@ runs:
262271
task remote:regal --yes
263272
task remote:opa --yes
264273
#
274+
# Install digitalocean/gta if partial testing is enabled.
275+
#
276+
- name: install gta for partial testing
277+
if: inputs.gta-partial-testing == true || inputs.gta-partial-testing == 'true'
278+
shell: bash
279+
run: |
280+
task remote:gta-install --yes
281+
#
265282
# Unit tests.
266283
#
267284
- name: unit tests
268285
if: inputs.testing-type == 'unit'
269286
shell: bash
270287
env:
271288
GITHUB_TOKEN: ${{ inputs.token }}
289+
GTA_BASE_BRANCH: ${{ inputs.gta-base-branch }}
290+
GTA_PARTIAL_TESTING: ${{ inputs.gta-partial-testing }}
272291
run: |
273292
task remote:test-cicd --yes
274293
#
@@ -279,6 +298,8 @@ runs:
279298
shell: bash
280299
env:
281300
GITHUB_TOKEN: ${{ inputs.token }}
301+
GTA_BASE_BRANCH: ${{ inputs.gta-base-branch }}
302+
GTA_PARTIAL_TESTING: ${{ inputs.gta-partial-testing }}
282303
TEST_TIMEOUT: ${{ inputs.test-timeout }}
283304
run: |
284305
task remote:test-integration-cicd --yes
@@ -293,6 +314,8 @@ runs:
293314
CODE_COVERAGE_FILE_EXCLUSIONS: ${{ inputs.golang-unit-tests-exclusions }}
294315
GITHUB_TOKEN: ${{ inputs.token }}
295316
CODE_COVERAGE_TIMEOUT: ${{ inputs.code-coverage-timeout }}
317+
GTA_BASE_BRANCH: ${{ inputs.gta-base-branch }}
318+
GTA_PARTIAL_TESTING: ${{ inputs.gta-partial-testing }}
296319
run: |
297320
task remote:coverage --yes
298321
#
@@ -303,6 +326,8 @@ runs:
303326
shell: bash
304327
env:
305328
GITHUB_TOKEN: ${{ inputs.token }}
329+
GTA_BASE_BRANCH: ${{ inputs.gta-base-branch }}
330+
GTA_PARTIAL_TESTING: ${{ inputs.gta-partial-testing }}
306331
run: |
307332
task remote:test-component-cicd --yes
308333
#

build/task.yml

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ vars:
7171
GQLGENC_BIN: "{{.GOBIN}}/gqlgenc"
7272
GRAPHQL_LINTER_BIN: "{{.GOBIN}}/graphql-linter"
7373
GRAPHQL_LINTER_VERSION: v0.1.0
74+
GTA_BASE_BRANCH: '{{.GTA_BASE_BRANCH | default "main"}}'
75+
GTA_PARTIAL_TESTING: '{{.GTA_PARTIAL_TESTING | default "false"}}'
76+
GTA_VERSION: v0.1.2
7477
HELM_VERSION: v3.16.2
7578
MCVS_TEXTTIDY_BIN: "{{.GOBIN}}/mcvs-texttidy"
7679
MCVS_TEXTTIDY_VERSION: 0.1.0
@@ -308,6 +311,14 @@ tasks:
308311
go install github.com/go-swagger/go-swagger/cmd/swagger@{{.GO_SWAGGER_VERSION}}
309312
fi
310313
silent: true
314+
gta-install:
315+
cmds:
316+
- |
317+
if ! gta version | grep -q "{{.GTA_VERSION}}"; then
318+
echo "Installing gta version {{.GTA_VERSION}}..."
319+
go install github.com/digitalocean/gta/cmd/gta@{{.GTA_VERSION}}
320+
fi
321+
silent: true
311322
osv-scanner-install:
312323
cmds:
313324
- |
@@ -676,14 +687,30 @@ tasks:
676687
cmds:
677688
- task: golang-log
678689
- |
690+
set -eu
691+
692+
if [ "{{.GTA_PARTIAL_TESTING}}" = true ]; then
693+
echo "Running partial test suite... against origin {{ .GTA_BASE_BRANCH }}"
694+
695+
PKGS="$(gta -include "$(go list -f '{{ .Module.Path }}')/" -base origin/{{ .GTA_BASE_BRANCH }})" \
696+
|| { rc=$?; echo "gta failed (exit $rc)"; exit $rc; }
697+
698+
if [ -z "${PKGS}" ]; then
699+
echo "No packages changed compared to base branch {{ .GTA_BASE_BRANCH }}. Skipping tests."
700+
exit 0;
701+
fi
702+
else
703+
PKGS=./...
704+
fi
705+
679706
# when "if testing.Short() { t.Skip() }" is in the go code then such
680707
# tests will be skipped if -short is used.
681708
go test \
682709
-p {{.GOLANG_PARALLEL_TESTS}} \
683710
-race \
684711
-short \
685712
--tags={{.TEST_TAGS}} \
686-
./... \
713+
${PKGS} \
687714
{{.TEST_EXTRA_ARGS}} \
688715
-timeout {{.TEST_TIMEOUT}}
689716
desc: run test

scripts/package-version-updater.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ readonly PACKAGES_TO_BE_UPDATED=(
5959
"PRESENT_VERSION PRESENT_VERSION present go_list_latest_version golang.org/x/tools"
6060
"REGAL_VERSION REGAL_VERSION regal latest_stable_package_version_on_github StyraOSS/regal"
6161
"YQ_VERSION YQ_VERSION yq latest_stable_package_version_on_github mikefarah/yq"
62+
"GTA_VERSION GTA_VERSION gta latest_stable_package_version_on_github digitalocean/gta"
6263
)
6364
readonly PR_TITLE="build(deps): weekly update package versions that cannot be updated by dependabot"
6465

0 commit comments

Comments
 (0)