diff --git a/.github/actions/common-setup/action.yml b/.github/actions/common-setup/action.yml index 280be94..36e9a98 100644 --- a/.github/actions/common-setup/action.yml +++ b/.github/actions/common-setup/action.yml @@ -6,43 +6,49 @@ inputs: description: "Python version to setup" required: true default: "3.13" - poetry_version: - description: "Poetry version to setup" - required: true - default: "2.1.3" runs: using: "composite" steps: - - name: Install Poetry - run: pipx install poetry==${{ inputs.poetry_version }} - shell: bash + - name: Set up Python 🐍 + uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0 + with: + python-version: ${{ inputs.python_version }} + + - name: Default shell + run: | + if [ "$RUNNER_OS" == "Linux" ]; then + echo shellos=bash >> $GITHUB_ENV + elif [ "$RUNNER_OS" == "Windows" ]; then + echo shellos=powershell >> $GITHUB_ENV + else + echo "$RUNNER_OS not supported" + exit 1 + fi + shell: bash - - name: Set up Python 🐍 - id: setup-python - uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0 - with: - python-version: ${{ inputs.python_version }} - cache: poetry - cache-dependency-path: poetry.lock + - name: Install Poetry + uses: abatilo/actions-poetry@65c61eae400c65c9510a584af85138c1ae19bbc0 # v3.0.2 + with: + poetry-version: 2.1.3 - - name: Set Poetry environment - run: poetry env use ${{ inputs.python_version }} - shell: bash + # Cache your dependencies (i.e. all the stuff in your `pyproject.toml`). Note the cache + # key: if you're using multiple Python versions, or multiple OSes, you'd need to include + # them in the cache key. I'm not, so it can be simple and just depend on the poetry.lock. + - name: cache deps + id: cache-deps + uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3 + with: + path: ~/.cache/pypoetry + key: pydeps-${{ inputs.python_version }}-${{ env.shellos }}-${{ hashFiles('**/poetry.lock') }} - - name: Default shell - run: | - if [ "$RUNNER_OS" == "Linux" ]; then - echo shellos=bash >> $GITHUB_ENV - elif [ "$RUNNER_OS" == "Windows" ]; then - echo shellos=powershell >> $GITHUB_ENV - else - echo "$RUNNER_OS not supported" - exit 1 - fi - shell: bash + # Install dependencies. `--no-root` means "install all dependencies but not the project + # itself", which is what you want to avoid caching _your_ code. The `if` statement + # ensures this only runs on a cache miss. + - name: Install dependencies + run: poetry install --no-interaction --no-root + shell: ${{ env.shellos }} + if: steps.cache-deps.outputs.cache-hit != 'true' - # The 'setup-python' action with 'cache: poetry' installs dependencies but not the project - # itself. This step installs the project package into the created virtual environment. - - name: Install project - run: poetry install --no-interaction - shell: ${{ env.shellos }} + - name: Install project + run: poetry install --no-interaction + shell: ${{ env.shellos }} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2f31f39..ab48636 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,14 +16,11 @@ jobs: strategy: matrix: task: ["fmt", "lint"] - python-version: ["3.10", "3.11", "3.12", "3.13"] steps: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - uses: ./.github/actions/common-setup - with: - python_version: ${{ matrix.python-version }} - name: check code run: poetry run poe ${{ matrix.task }} @@ -31,16 +28,11 @@ jobs: build: needs: code_checks runs-on: ubuntu-latest - strategy: - matrix: - python-version: ["3.10", "3.11", "3.12", "3.13"] steps: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - uses: ./.github/actions/common-setup - with: - python_version: ${{ matrix.python-version }} - name: Build 🔨 run: poetry build @@ -48,17 +40,13 @@ jobs: build_windows: needs: code_checks runs-on: windows-latest - strategy: - matrix: - python-version: ["3.10", "3.11", "3.12", "3.13"] steps: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - uses: ./.github/actions/common-setup with: - python_version: ${{ matrix.python-version }} - poetry_version: 2.1.3 + python_version: 3.13 - name: Add entrypoint to bypass issue with relative imports in PyInstaller run: powershell -Command 'Invoke-WebRequest https://gist.githubusercontent.com/Wenzel/e38d227d94f16e026b3aed03ea6a6661/raw/383ec56d62c58e444f6c5962ee6940a5c583d341/stub.py -OutFile stub.py' @@ -68,7 +56,6 @@ jobs: shell: bash - name: Upload Windows release artefact - if: ${{ matrix.python-version == 3.13 }} uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 with: name: checksec.exe @@ -80,12 +67,10 @@ jobs: shell: bash test: - needs: ['build', 'build_windows'] - + needs: build strategy: matrix: os: [ubuntu-latest, windows-latest] - python-version: ["3.10", "3.11", "3.12", "3.13"] runs-on: ${{ matrix.os }} defaults: run: @@ -97,8 +82,6 @@ jobs: submodules: true - uses: ./.github/actions/common-setup - with: - python_version: ${{ matrix.python-version }} - name: Run tests run: poetry run poe test_e2e