Skip to content

Commit

Permalink
(ci) enable optional verbose logging on unit tests and upload artifac…
Browse files Browse the repository at this point in the history
…ts (#2865)

- Optionally enabled verbose logging for unit tests
- adds ability to verbose log to a file, while sending "normal" quiet
output to stdout
- updates CI to upload the test.log artifact and store for 5 days for
later debugging
- local workflow and test runs will stay the same
- only enabled for `make test-unit` for now as a proposal for how we
achieve this, can expand to rest if we like it @renaynay and @vgonkivs

If everyone likes, i can expand to all test cases

fixes #1211
  • Loading branch information
ramin authored Nov 10, 2023
1 parent 65f0f53 commit 70d7a39
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/ci_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ jobs:
outputs:
go-version: ${{ steps.set-vars.outputs.go-version }}
branch: ${{ steps.trim_ref.outputs.branch }}
debug: ${{ steps.debug.outputs.debug }}
steps:
- name: Set go version
id: set-vars
Expand All @@ -43,6 +44,15 @@ jobs:
run: |
echo "branch=$(${${{ github.ref }}:11})" >> $GITHUB_OUTPUT
- name: Set debug output
id: debug
run: |
if [[ "${{ runner.debug }}" == "true" ]]; then
echo "debug=true" >> $GITHUB_ENV
else
echo "debug=false" >> $GITHUB_ENV
fi
# Dockerfile Linting
hadolint:
uses: celestiaorg/.github/.github/workflows/reusable_dockerfile_lint.yml@v0.2.8 # yamllint disable-line rule:line-length
Expand Down
28 changes: 27 additions & 1 deletion .github/workflows/go-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,22 @@ concurrency:
cancel-in-progress: true

jobs:
setup:
runs-on: ubuntu-latest
outputs:
debug: ${{ steps.debug.outputs.debug }}
steps:
- name: Set debug output
id: debug
run: |
if [[ "${{ runner.debug }}" == "true" ]]; then
echo "debug=true" >> $GITHUB_ENV
else
echo "debug=false" >> $GITHUB_ENV
fi
lint:
needs: [setup]
name: Lint
runs-on: ubuntu-latest

Expand All @@ -33,6 +48,7 @@ jobs:
skip-build-cache: true

go_mod_tidy_check:
needs: [setup]
name: Go Mod Tidy Check
runs-on: ubuntu-latest

Expand Down Expand Up @@ -68,7 +84,17 @@ jobs:
go-version: ${{ inputs.go-version }}

- name: run unit tests
run: make test-unit
run: make test-unit ENABLE_VERBOSE=${{ needs.setup.outputs.debug }}

- name: Upload unit test output
uses: actions/upload-artifact@v3
if: always() && needs.setup.outputs.debug == 'true'
with:
name: unit-test-output-${{ matrix.os }}
path: |
debug.log
coverage.txt
retention-days: 5

- name: upload coverage
uses: codecov/codecov-action@v3.1.4
Expand Down
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ LDFLAGS=-ldflags="-X '$(versioningPath).buildTime=$(shell date)' -X '$(versionin
ifeq (${PREFIX},)
PREFIX := /usr/local
endif
ifeq ($(ENABLE_VERBOSE),true)
LOG_AND_FILTER = | tee debug.log
VERBOSE = -v
else
VERBOSE =
LOG_AND_FILTER =
endif
## help: Get more info on make commands.
help: Makefile
@echo " Choose a command run in "$(PROJECTNAME)":"
Expand Down Expand Up @@ -99,7 +106,7 @@ lint: lint-imports
## test-unit: Running unit tests
test-unit:
@echo "--> Running unit tests"
@go test -covermode=atomic -coverprofile=coverage.txt `go list ./... | grep -v nodebuilder/tests`
@go test $(VERBOSE) -covermode=atomic -coverprofile=coverage.txt `go list ./... | grep -v nodebuilder/tests` $(LOG_AND_FILTER)
.PHONY: test-unit

## test-unit-race: Running unit tests with data race detector
Expand Down

0 comments on commit 70d7a39

Please sign in to comment.