diff --git a/.github/workflows/self-test.yml b/.github/workflows/self-test.yml index f815892..3f7c229 100644 --- a/.github/workflows/self-test.yml +++ b/.github/workflows/self-test.yml @@ -16,12 +16,48 @@ jobs: steps: - uses: actions/checkout@v3 + - run: echo "3.11.6" > .python-version + shell: bash + + # Run local action + - name: Test action-setup-venv + id: venv + uses: ./ + with: + # this should override .python-version + python-version: 3.11.4 + install-cmd: pip install -r test/testdata/requirements.txt + + # Print debug vars + - name: Print variables for debugging + shell: bash + run: | + echo "VIRTUAL_ENV: ${VIRTUAL_ENV}" + echo "PATH: ${PATH}" + echo "Cache Hit: ${{ steps.venv.outputs.cache-hit }}" + ls -la ${VIRTUAL_ENV}/${{ runner.os == 'Windows' && 'Lib' || 'lib/*' }}/site-packages + + # Test the venv and install worked + - name: Ensure environment works + run: | + python -Sc 'import sys; assert sys.version_info[:3] == (3, 11, 4), sys.version_info' + python ./test/testdata/demo.py + + self-test-python-version-file: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - run: echo "3.11.6" > .python-version + shell: bash + # Run local action - name: Test action-setup-venv id: venv uses: ./ with: - python-version: 3.8 + # since there is a .python-version file and we did not specify + # python-version, it should be used install-cmd: pip install -r test/testdata/requirements.txt # Print debug vars @@ -35,7 +71,9 @@ jobs: # Test the venv and install worked - name: Ensure environment works - run: python ./test/testdata/demo.py + run: | + python -Sc 'import sys; assert sys.version_info[:3] == (3, 11, 6), sys.version_info' + python ./test/testdata/demo.py no-install-self-test: runs-on: ubuntu-latest @@ -47,11 +85,13 @@ jobs: id: venv uses: ./ with: - python-version: 3.8 + python-version: 3.11.6 # Test the venv and external install work - name: Pip install if: steps.venv.outputs.cache-hit != 'true' run: pip install -r test/testdata/requirements.txt - name: Ensure environment works - run: python ./test/testdata/demo.py + run: | + python -Sc 'import sys; assert sys.version_info[:3] == (3, 11, 6), sys.version_info' + python ./test/testdata/demo.py diff --git a/README.md b/README.md index ad48c7e..91c06c7 100644 --- a/README.md +++ b/README.md @@ -9,11 +9,28 @@ when the cache is available. ### Usage +uv: ```yaml - - uses: getsentry/action-setup-venv@v2.2.0 + - uses: astral-sh/setup-uv@884ad927a57e558e7a70b92f2bccf9198a4be546 # v6 + with: + version: "0.8.2" + # we just cache the venv-dir directly in action-setup-venv + enable-cache: false + + - uses: getsentry/action-setup-venv@v3.0.0 + with: + cache-dependency-path: uv.lock + install-cmd: uv sync --frozen --active +``` + +pip: +```yaml + - uses: getsentry/action-setup-venv@v3.0.0 id: venv with: - python-version: 3.10.7 + # starting from action-setup-venv@v3.0.0, if python-version isn't specified, + # we default to using the version in .python-version file. + python-version: 3.11.6 cache-dependency-path: | requirements.txt requirements-frozen.txt diff --git a/action.yml b/action.yml index 0f2e4fa..1eca513 100644 --- a/action.yml +++ b/action.yml @@ -3,7 +3,8 @@ description: 'configures venv, python and caches' inputs: python-version: - description: "Version range or exact version of Python or PyPy to use, using SemVer's version range syntax." + description: "Version range or exact version of Python or PyPy to use, using SemVer's version range syntax. If not set, the version in .python-version file will be used." + default: '' cache-dependency-path: description: "Requirement files to install. Can be a glob pattern." default: '**/requirements*.txt' @@ -24,6 +25,7 @@ runs: id: setup-python with: python-version: ${{ inputs.python-version }} + python-version-file: ${{ hashFiles('.python-version') == '' && '' || '.python-version' }} - run: echo '::remove-matcher owner=python::' shell: bash