From ff94b05b7354659587acfbc8c7b18f9978baa976 Mon Sep 17 00:00:00 2001 From: Armand Sauzay <35524799+armand-sauzay@users.noreply.github.com> Date: Tue, 31 Dec 2024 14:13:57 +0000 Subject: [PATCH 1/3] feat: support uv as package manager --- test/action.yaml | 107 ++++++++++++++++++++++++++++------------------- 1 file changed, 65 insertions(+), 42 deletions(-) diff --git a/test/action.yaml b/test/action.yaml index a9f6463..78e9b21 100644 --- a/test/action.yaml +++ b/test/action.yaml @@ -41,60 +41,83 @@ runs: fetch-depth: 0 - name: Setup python uses: actions/setup-python@v5 - # First we attempt to run a pip-based workflow if there is no poetry.lock - - name: Install pip dependencies - if: hashFiles('poetry.lock') == '' + + # Determine which package manager to use + - name: Determine package manager + id: pkg-manager shell: bash - #if there is a requirements-dev.txt or requirements-test.txt, we install that run: | - if [[ -f requirements-dev.txt ]]; then - pip install -r requirements-dev.txt - elif [[ -f requirements-test.txt ]]; then - pip install -r requirements-test.txt + if [[ -f "poetry.lock" ]]; then + echo "manager=poetry" >> $GITHUB_OUTPUT + elif [[ -f "uv.lock" ]]; then + echo "manager=uv" >> $GITHUB_OUTPUT + elif [[ -f "requirements.txt" ]]; then + echo "manager=pip" >> $GITHUB_OUTPUT else - pip install -r requirements.txt + echo "::error::No package manager configuration found (poetry.lock/uv.lock/requirements.txt)" + exit 1 fi - - name: Run setup script - if: hashFiles('poetry.lock') == '' && inputs.setup-script != '' + + # Install package manager + - name: Install package manager shell: bash run: | - ${{ inputs.setup-script }} - - name: Run tests - if: hashFiles('poetry.lock') == '' + case "${{ steps.pkg-manager.outputs.manager }}" in + "poetry") pip install poetry ;; + "uv") pip install uv ;; + esac + + # Install dependencies + - name: Install dependencies shell: bash run: | - if command -v pytest &>/dev/null; then - pytest ${{ inputs.test-flags }} - elif [[ -f setup.py ]]; then - python setup.py test -- ${{ inputs.test-flags }} - else - echo "::error::pytest not found in the dependencies, cannot run tests" - exit 1 - fi - # If we do have a poetry.lock, we use a poetry based workflow - - name: install poetry - if: hashFiles('poetry.lock') != '' - shell: bash - run: pip install poetry - - name: Install poetry dependencies - if: hashFiles('poetry.lock') != '' - shell: bash - run: poetry install + case "${{ steps.pkg-manager.outputs.manager }}" in + "poetry") poetry install ;; + "uv") uv pip sync ;; + "pip") + # First install dev/test requirements if they exist + if [[ -f requirements-dev.txt ]]; then + pip install -r requirements-dev.txt + elif [[ -f requirements-test.txt ]]; then + pip install -r requirements-test.txt + else + pip install -r requirements.txt + fi + # Install the package itself in editable mode if pyproject.toml or setup.py exists + if [[ -f pyproject.toml ]] || [[ -f setup.py ]]; then + pip install -e . + fi + ;; + esac + + # Run setup script if provided - name: Run setup script - if: hashFiles('poetry.lock') != '' && inputs.setup-script != '' + if: inputs.setup-script != '' shell: bash - run: | - ${{ inputs.setup-script }} - - name: Run poetry tests - if: hashFiles('poetry.lock') != '' + run: ${{ inputs.setup-script }} + + # Run tests + - name: Run tests shell: bash run: | - if poetry show pytest &>/dev/null; then - poetry run pytest ${{ inputs.test-flags }} - else - echo "::error::pytest not found in poetry.lock, cannot run tests" - exit 1 - fi + case "${{ steps.pkg-manager.outputs.manager }}" in + "poetry") + if poetry show pytest &>/dev/null; then + poetry run pytest ${{ inputs.test-flags }} + else + echo "::error::pytest not found in poetry.lock, cannot run tests" + exit 1 + fi + ;; + "uv"|"pip") + # Install pytest if not already present + if ! command -v pytest &>/dev/null; then + echo "::warning::pytest not found, installing pytest and pytest-cov" + pip install pytest pytest-cov + fi + pytest ${{ inputs.test-flags }} + ;; + esac - name: Upload coverage if: inputs.upload-coverage != 'false' uses: coverallsapp/github-action@v2 From 606115799fea65295a340c1a92ffd0f803347e1b Mon Sep 17 00:00:00 2001 From: Armand Sauzay <35524799+armand-sauzay@users.noreply.github.com> Date: Tue, 31 Dec 2024 14:46:14 +0000 Subject: [PATCH 2/3] test: add test against open source packages --- .github/workflows/ci.yaml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 0d461d9..0c23199 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -44,3 +44,22 @@ jobs: with: checkout-repo: false github-token: ${{ secrets.GITHUB_TOKEN }} + + test-oss: + name: Test / Open source + runs-on: ubuntu-latest + strategy: + matrix: + repos: + - pallets/flask + steps: + - uses: actions/checkout@v4 + with: + repository: ${{ matrix.repos }} + - uses: actions/checkout@v4 + with: + path: actions-python + - uses: ./actions-python/test + with: + checkout-repo: false + github-token: ${{ secrets.GITHUB_TOKEN }} From a6205ab38ceea1c18d3296d9cf07ab114d6d1506 Mon Sep 17 00:00:00 2001 From: Armand Sauzay <35524799+armand-sauzay@users.noreply.github.com> Date: Tue, 31 Dec 2024 14:48:01 +0000 Subject: [PATCH 3/3] fix(test): support pyproject for pip projects --- test/action.yaml | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/test/action.yaml b/test/action.yaml index 78e9b21..a13d36f 100644 --- a/test/action.yaml +++ b/test/action.yaml @@ -51,10 +51,10 @@ runs: echo "manager=poetry" >> $GITHUB_OUTPUT elif [[ -f "uv.lock" ]]; then echo "manager=uv" >> $GITHUB_OUTPUT - elif [[ -f "requirements.txt" ]]; then + elif [[ -f "requirements.txt" ]] || [[ -f "pyproject.toml" ]]; then echo "manager=pip" >> $GITHUB_OUTPUT else - echo "::error::No package manager configuration found (poetry.lock/uv.lock/requirements.txt)" + echo "::error::No package manager configuration found (poetry.lock/uv.lock/requirements.txt/pyproject.toml)" exit 1 fi @@ -75,17 +75,21 @@ runs: "poetry") poetry install ;; "uv") uv pip sync ;; "pip") - # First install dev/test requirements if they exist - if [[ -f requirements-dev.txt ]]; then - pip install -r requirements-dev.txt - elif [[ -f requirements-test.txt ]]; then - pip install -r requirements-test.txt + # For projects with only pyproject.toml, skip requirements.txt check + if [[ -f "pyproject.toml" ]]; then + pip install -e ".[test,dev]" else - pip install -r requirements.txt - fi - # Install the package itself in editable mode if pyproject.toml or setup.py exists - if [[ -f pyproject.toml ]] || [[ -f setup.py ]]; then - pip install -e . + # Traditional requirements.txt based installation + if [[ -f requirements-dev.txt ]]; then + pip install -r requirements-dev.txt + elif [[ -f requirements-test.txt ]]; then + pip install -r requirements-test.txt + elif [[ -f requirements.txt ]]; then + pip install -r requirements.txt + else + echo "::error::No requirements file found" + exit 1 + fi fi ;; esac