From c95a6a709294233d13777fa3aae9414100116bf2 Mon Sep 17 00:00:00 2001 From: Reuben Frankel Date: Wed, 16 Oct 2024 00:54:39 +0100 Subject: [PATCH] Provide a cleaner interface for generating (multiple) annotations --- .github/workflows/test.yml | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 48ce986..f6fda75 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -39,4 +39,33 @@ jobs: poetry install - name: Test with pytest run: | - poetry run pytest | sed -E 's/.*(UserWarning)/::warning title="${{ github.job }} (${{ matrix.python-version }}): \1"::\0/' + __generate_annotations () { + level=$1 + pattern=$2 + title=${3:-'\1'} + message=${4:-'\0'} + + test -z "$level" \ + && echo 'Error: level is required' \ + && exit 1 + + test "$level" != debug \ + && test "$level" != notice \ + && test "$level" != warning \ + && test "$level" != error \ + && echo 'Error: level must be one of [ debug | notice | warning | error ]' \ + && exit 1 + + test -z "$pattern" \ + && echo 'Error: pattern is required' \ + && exit 1 + + sed -E "s/.*($pattern)/::$level title='${{ github.job }} (${{ matrix.python-version }}): $title'::$message/" + } + + debug () { __generate_annotations $FUNCNAME $@; } + notice () { __generate_annotations $FUNCNAME $@; } + warning () { __generate_annotations $FUNCNAME $@; } + error () { __generate_annotations $FUNCNAME $@; } + + poetry run pytest | warning UserWarning