From fbdf6dc8237693f24de5cd8ed60623c8c447a189 Mon Sep 17 00:00:00 2001 From: David Hart Date: Tue, 22 Oct 2024 15:02:36 -0600 Subject: [PATCH 1/5] ci: create reusable testing workflow Signed-off-by: David Hart --- .github/workflows/pytest-workflow.yml | 67 +++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 .github/workflows/pytest-workflow.yml diff --git a/.github/workflows/pytest-workflow.yml b/.github/workflows/pytest-workflow.yml new file mode 100644 index 0000000..bc39173 --- /dev/null +++ b/.github/workflows/pytest-workflow.yml @@ -0,0 +1,67 @@ +name: Testing Workflow + +on: + workflow_call: + inputs: + version: + required: true + type: string + os: + required: true + type: string + secrets: + coverage_token: + required: false + +permissions: + contents: read + +jobs: + run-pytest-coverage: + runs-on: ${{ inputs.os }} + steps: + - name: Harden Runner + uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1 + with: + disable-sudo: true + egress-policy: block + allowed-endpoints: > + api.codecov.io:443 + api.github.com:443 + cli.codecov.io:443 + codecov.io:443 + files.pythonhosted.org:443 + github.com:443 + pypi.org:443 + storage.googleapis.com:443 + uploader.codecov.io:443 + + - name: Check out the commit + uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1 + + - name: Set up Python + uses: actions/setup-python@f677139bbe7f9c59b41e40162b753c062f5d49a3 # v5.2.0 + with: + python-version: ${{ inputs.version }} + + - name: Install testing dependencies + run: | + python3 -m pip install --upgrade pip + python3 -m pip install -r requirements.txt -r requirements-dev.txt + + - name: Test build and install + run: python3 -m pip install . + + - name: Test with pytest + run: python3 -m pytest --nbmake --cov=sansmic --cov=tests examples/ tests/ + + - name: Upload coverage reports to Codecov + uses: codecov/codecov-action@b9fd7d16f6d7d1b5d2bec1a2887e65ceed900238 # v4.6.0 + with: + token: ${{ secrets.coverage_token }} + flags: ${{ inputs.os }} + + - name: Test uninstall + if: success() || failure() + # Allow upload to codecov to fail but not fail all tests + run: python3 -m pip uninstall -y sansmic From 0a3d864717264cbadb0e01185301d981484ece6e Mon Sep 17 00:00:00 2001 From: David Hart Date: Tue, 22 Oct 2024 15:19:34 -0600 Subject: [PATCH 2/5] ci: update to deal with py39 requirements lock Signed-off-by: David Hart --- .github/workflows/pytest-workflow.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/pytest-workflow.yml b/.github/workflows/pytest-workflow.yml index bc39173..ab81943 100644 --- a/.github/workflows/pytest-workflow.yml +++ b/.github/workflows/pytest-workflow.yml @@ -47,10 +47,9 @@ jobs: - name: Install testing dependencies run: | python3 -m pip install --upgrade pip - python3 -m pip install -r requirements.txt -r requirements-dev.txt - name: Test build and install - run: python3 -m pip install . + run: python3 -m pip install .[formats,examples,tests] - name: Test with pytest run: python3 -m pytest --nbmake --cov=sansmic --cov=tests examples/ tests/ From b177de7699ceb7f5a3253bc06931a8b88df4fa2f Mon Sep 17 00:00:00 2001 From: David Hart Date: Tue, 22 Oct 2024 15:38:08 -0600 Subject: [PATCH 3/5] ci: update reusable test workflow for clarity Signed-off-by: David Hart --- .github/workflows/pytest-workflow.yml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pytest-workflow.yml b/.github/workflows/pytest-workflow.yml index ab81943..3c7bf8a 100644 --- a/.github/workflows/pytest-workflow.yml +++ b/.github/workflows/pytest-workflow.yml @@ -1,4 +1,4 @@ -name: Testing Workflow +name: Reusable test workflow on: workflow_call: @@ -18,6 +18,7 @@ permissions: jobs: run-pytest-coverage: + name: Test and compute coverage runs-on: ${{ inputs.os }} steps: - name: Harden Runner @@ -52,9 +53,14 @@ jobs: run: python3 -m pip install .[formats,examples,tests] - name: Test with pytest - run: python3 -m pytest --nbmake --cov=sansmic --cov=tests examples/ tests/ + run: | + echo '### Run tests' >> $GITHUB_STEP_SUMMARY + echo '```bash' >> $GITHUB_STEP_SUMMARY + python3 -m pytest --nbmake --no-cov-on-fail --disable-warnings --cov=sansmic --cov=tests --no-header --color=auto examples/ tests/ | tee -a $GITHUB_STEP_SUMMARY + echo '```' >> $GITHUB_STEP_SUMMARY - name: Upload coverage reports to Codecov + if: success() || failure() uses: codecov/codecov-action@b9fd7d16f6d7d1b5d2bec1a2887e65ceed900238 # v4.6.0 with: token: ${{ secrets.coverage_token }} From 0e0fd5c0898ea34e82f40ef39dcfc93bf6584d4e Mon Sep 17 00:00:00 2001 From: David Hart Date: Tue, 22 Oct 2024 15:55:05 -0600 Subject: [PATCH 4/5] ci(test): add verbose option to reusable test workflow Signed-off-by: David Hart --- .github/workflows/pytest-workflow.yml | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pytest-workflow.yml b/.github/workflows/pytest-workflow.yml index 3c7bf8a..5f68133 100644 --- a/.github/workflows/pytest-workflow.yml +++ b/.github/workflows/pytest-workflow.yml @@ -9,6 +9,10 @@ on: os: required: true type: string + verbose: + default: false + required: false + type: boolean secrets: coverage_token: required: false @@ -53,12 +57,27 @@ jobs: run: python3 -m pip install .[formats,examples,tests] - name: Test with pytest + if: ${{ !inputs.verbose }} + run: | + python3 -m pytest --nbmake --disable-warnings --cov=sansmic --cov=tests --no-header --color=auto examples/ tests/ + + - name: Test with pytest (non-windows verbose) + if: ${{ inputs.verbose && inputs.os != "windows-latest" }} run: | echo '### Run tests' >> $GITHUB_STEP_SUMMARY echo '```bash' >> $GITHUB_STEP_SUMMARY - python3 -m pytest --nbmake --no-cov-on-fail --disable-warnings --cov=sansmic --cov=tests --no-header --color=auto examples/ tests/ | tee -a $GITHUB_STEP_SUMMARY + python3 -m pytest --nbmake --disable-warnings --cov=sansmic --cov=tests --no-header --color=auto examples/ tests/ | tee -a $GITHUB_STEP_SUMMARY echo '```' >> $GITHUB_STEP_SUMMARY + - name: Test with pytest (windows verbose) + if: ${{ inputs.verbose && inputs.os == "windows-latest" }} + shell: powershell + run: | + echo '### Run tests' >> $Env:GITHUB_STEP_SUMMARY + echo '```bash' >> $Env:GITHUB_STEP_SUMMARY + python3 -m pytest --nbmake --disable-warnings --cov=sansmic --cov=tests --no-header --color=auto examples/ tests/ >> $Env:GITHUB_STEP_SUMMARY + echo '```' >> $Env:GITHUB_STEP_SUMMARY + - name: Upload coverage reports to Codecov if: success() || failure() uses: codecov/codecov-action@b9fd7d16f6d7d1b5d2bec1a2887e65ceed900238 # v4.6.0 From 951ebbd277e18b0a5b88a4e67535e262bc59f979 Mon Sep 17 00:00:00 2001 From: David Hart Date: Tue, 22 Oct 2024 16:07:56 -0600 Subject: [PATCH 5/5] ci(test): fix syntax error in if-statement Signed-off-by: David Hart --- .github/workflows/pytest-workflow.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pytest-workflow.yml b/.github/workflows/pytest-workflow.yml index 5f68133..f01c82b 100644 --- a/.github/workflows/pytest-workflow.yml +++ b/.github/workflows/pytest-workflow.yml @@ -57,12 +57,12 @@ jobs: run: python3 -m pip install .[formats,examples,tests] - name: Test with pytest - if: ${{ !inputs.verbose }} + if: ${{ ! inputs.verbose }} run: | python3 -m pytest --nbmake --disable-warnings --cov=sansmic --cov=tests --no-header --color=auto examples/ tests/ - name: Test with pytest (non-windows verbose) - if: ${{ inputs.verbose && inputs.os != "windows-latest" }} + if: inputs.verbose && inputs.os != 'windows-latest' run: | echo '### Run tests' >> $GITHUB_STEP_SUMMARY echo '```bash' >> $GITHUB_STEP_SUMMARY @@ -70,7 +70,7 @@ jobs: echo '```' >> $GITHUB_STEP_SUMMARY - name: Test with pytest (windows verbose) - if: ${{ inputs.verbose && inputs.os == "windows-latest" }} + if: inputs.verbose && inputs.os == 'windows-latest' shell: powershell run: | echo '### Run tests' >> $Env:GITHUB_STEP_SUMMARY