From cb31835b4dd0925440d9e74247ae460c654e9612 Mon Sep 17 00:00:00 2001 From: lvlcn-t <75443136+lvlcn-t@users.noreply.github.com> Date: Sun, 17 Nov 2024 19:47:48 +0100 Subject: [PATCH] ci: add ability to provide logging options to tests Signed-off-by: lvlcn-t <75443136+lvlcn-t@users.noreply.github.com> --- .github/workflows/test.yml | 57 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5c8f5a9e..c55b769d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,6 +1,19 @@ name: Tests -on: [push] +on: + push: + workflow_dispatch: + inputs: + log_format: + description: "Log format" + required: false + default: "text" + type: string + log_level: + description: "Log level" + required: false + default: "info" + type: string permissions: contents: read @@ -20,7 +33,24 @@ jobs: go install github.com/mfridman/tparse@latest go mod download - - name: Run all go tests + - name: Set log format and level + id: inputs + run: | + if [ -z "${{ inputs.log_format }}" ]; then + echo "LOG_FORMAT=text" >> $GITHUB_OUTPUT + else + echo "LOG_FORMAT=${{ inputs.log_format }}" >> $GITHUB_OUTPUT + fi + if [ -z "${{ inputs.log_level }}" ]; then + echo "LOG_LEVEL=info" >> $GITHUB_OUTPUT + else + echo "LOG_LEVEL=${{ inputs.log_level }}" >> $GITHUB_OUTPUT + fi + + - name: Run go unit tests + env: + LOG_FORMAT: ${{ steps.inputs.outputs.LOG_FORMAT }} + LOG_LEVEL: ${{ steps.inputs.outputs.LOG_LEVEL }} run: | go test -v -count=1 -test.short -race ./... -json -coverpkg ./... \ | tee output.jsonl | tparse -notests -follow -all || true @@ -40,7 +70,28 @@ jobs: go install github.com/mfridman/tparse@latest go mod download - - name: Run all go tests + - name: Set log format and level + id: inputs + run: | + if [ -z "${{ inputs.log_format }}" ]; then + echo "No log format provided, using default: text" + echo "LOG_FORMAT=text" >> $GITHUB_OUTPUT + else + echo "Log format provided: ${{ inputs.log_format }}" + echo "LOG_FORMAT=${{ inputs.log_format }}" >> $GITHUB_OUTPUT + fi + if [ -z "${{ inputs.log_level }}" ]; then + echo "No log level provided, using default: info" + echo "LOG_LEVEL=info" >> $GITHUB_OUTPUT + else + echo "Log level provided: ${{ inputs.log_level }}" + echo "LOG_LEVEL=${{ inputs.log_level }}" >> $GITHUB_OUTPUT + fi + + - name: Run go e2e tests + env: + LOG_FORMAT: ${{ steps.inputs.outputs.LOG_FORMAT }} + LOG_LEVEL: ${{ steps.inputs.outputs.LOG_LEVEL }} run: | go test -v -count=1 -race ./... -json -coverpkg ./... \ | tee output.jsonl | tparse -notests -follow -all || true