From ff51a3b41fc5862be967cc5c0b11a1c97115b403 Mon Sep 17 00:00:00 2001 From: Whitney Young Date: Mon, 16 Sep 2024 10:49:56 -0700 Subject: [PATCH] Test against upgraded dependencies The scheduled cron job will include upgraded dependencies in the build matrix and the workflow will allow this as an option. --- .github/workflows/pytest.yml | 45 +++++++++++++++++++++++++++++++++++- script/unfreeze | 9 ++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100755 script/unfreeze diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index 948cd2f..aadeb79 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -8,16 +8,45 @@ on: pull_request: branches: [ main ] workflow_dispatch: + inputs: + upgraded: + description: "Include upgraded dependencies in build matrix" + default: false + type: boolean schedule: - cron: "0 0 * * *" jobs: - build: + info: + name: Collect info + outputs: + dependencies: ${{ steps.info.outputs.dependencies }} + runs-on: ubuntu-latest + steps: + - name: Collect info + id: info + run: | + dependencies='["pinned", "upgraded"]' + + if [[ "${{ github.event_name }}" == "push" ]] || \ + [[ "${{ github.event_name }}" == "pull_request" ]] || \ + [[ "${{ github.event.inputs.upgraded }}" == "false" ]]; + then + dependencies='["pinned"]' + fi + # Output & sent to GitHub Actions + echo "dependencies: ${dependencies}" + echo "dependencies=${dependencies}" >> $GITHUB_OUTPUT + build: + name: Run tests runs-on: ubuntu-latest + needs: + - info strategy: fail-fast: false matrix: + dependencies: ${{ fromJSON(needs.info.outputs.dependencies) }} python-version: ["3.12"] steps: @@ -29,7 +58,21 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip + + if [[ "${{ matrix.dependencies }}" == "upgraded" ]]; + then + echo "unpinning dependencies" + ./script/unfreeze + fi + pip install -r requirements.test.txt + + if [[ "${{ matrix.dependencies }}" == "upgraded" ]]; + then + ./script/freeze + echo "dependency changes after upgrade:" + git diff requirements.test.txt + fi - name: Test with pytest run: | pytest diff --git a/script/unfreeze b/script/unfreeze new file mode 100755 index 0000000..c1ae38a --- /dev/null +++ b/script/unfreeze @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +set -e + +cd "$(dirname "$0")/.." + +cat requirements.test.txt | \ + sed 's/==.*//' > requirements.test.txt.tmp && \ + mv requirements.test.txt.tmp requirements.test.txt