From dccd90621b246d0fcb5edfb9c8ca3b92d12c9e68 Mon Sep 17 00:00:00 2001 From: Steven B <51370195+sdb9696@users.noreply.github.com> Date: Tue, 1 Oct 2024 13:26:21 +0100 Subject: [PATCH] Migrate workflows to setup-uv github action --- .github/actions/setup/action.yml | 64 ++++++++------------------------ .github/workflows/ci.yml | 2 +- .github/workflows/publish.yml | 19 +++++++--- .pre-commit-config.yaml | 2 +- pyproject.toml | 1 + 5 files changed, 31 insertions(+), 57 deletions(-) diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml index 6aa77ac..cdb6bf1 100644 --- a/.github/actions/setup/action.yml +++ b/.github/actions/setup/action.yml @@ -1,73 +1,39 @@ --- name: Setup Environment -description: Install requested pipx dependencies, configure the system python, and install uv and the package dependencies +description: Install uv, configure the system python, and the package dependencies inputs: uv-install-options: default: "" uv-version: - default: 0.4.5 + default: 0.4.16 python-version: required: true cache-pre-commit: default: false + cache-version: + default: "v0.1" runs: using: composite steps: - - uses: "actions/setup-python@v5" + - name: Install uv + uses: astral-sh/setup-uv@v3 + with: + enable-cache: true + version: "${{ inputs.uv-version }}" + + - name: "Setup python" + uses: "actions/setup-python@v5" id: setup-python with: python-version: "${{ inputs.python-version }}" allow-prereleases: true - - name: Setup pipx environment Variables - id: pipx-env-setup - # pipx default home and bin dir are not writable by the cache action - # so override them here and add the bin dir to PATH for later steps. - # This also ensures the pipx cache only contains uv - run: | - SEP="${{ !startsWith(runner.os, 'windows') && '/' || '\\' }}" - PIPX_CACHE="${{ github.workspace }}${SEP}pipx_cache" - echo "pipx-cache-path=${PIPX_CACHE}" >> $GITHUB_OUTPUT - echo "pipx-version=$(pipx --version)" >> $GITHUB_OUTPUT - echo "PIPX_HOME=${PIPX_CACHE}${SEP}home" >> $GITHUB_ENV - echo "PIPX_BIN_DIR=${PIPX_CACHE}${SEP}bin" >> $GITHUB_ENV - echo "PIPX_MAN_DIR=${PIPX_CACHE}${SEP}man" >> $GITHUB_ENV - echo "${PIPX_CACHE}${SEP}bin" >> $GITHUB_PATH - shell: bash - - - name: Pipx cache - id: pipx-cache - uses: actions/cache@v4 - with: - path: ${{ steps.pipx-env-setup.outputs.pipx-cache-path }} - key: cache-${{ inputs.cache-version }}-${{ runner.os }}-python-${{ steps.setup-python.outputs.python-version }}-pipx-${{ steps.pipx-env-setup.outputs.pipx-version }}-uv-${{ inputs.uv-version }} - - - name: Install uv - if: steps.pipx-cache.outputs.cache-hit != 'true' - id: install-uv - shell: bash - run: |- - pipx install uv==${{ inputs.uv-version }} --python "${{ steps.setup-python.outputs.python-path }}" - - - name: Read uv cache location - id: uv-cache-location - shell: bash - run: |- - echo "uv-venv-location=$(uv cache dir)" >> $GITHUB_OUTPUT - - - uses: actions/cache@v4 - name: uv cache - with: - path: | - ${{ steps.uv-cache-location.outputs.uv-venv-location }} - key: cache-${{ inputs.cache-version }}-${{ runner.os }}-python-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('uv.lock') }}-options-${{ inputs.uv-install-options }} - - - name: "uv install" + - name: "Install project" shell: bash run: | - uv sync --python "${{ steps.setup-python.outputs.python-path }}" ${{ inputs.uv-install-options }} + uv sync ${{ inputs.uv-install-options }} - name: Read pre-commit version if: inputs.cache-pre-commit == 'true' @@ -81,4 +47,4 @@ runs: name: Pre-commit cache with: path: ~/.cache/pre-commit/ - key: cache-${{ inputs.cache-version }}-${{ runner.os }}-pre-commit-${{ steps.pre-commit-version.outputs.pre-commit-version }}-python-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('.pre-commit-config.yaml') }} + key: cache-${{ inputs.cache-version }}-${{ runner.os }}-${{ runner.arch }}-pre-commit-${{ steps.pre-commit-version.outputs.pre-commit-version }}-python-${{ inputs.python-version }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('.pre-commit-config.yaml') }} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0decb7a..569a819 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,7 +7,7 @@ on: branches: ["main"] env: - UV_VERSION: 0.4.5 + UV_VERSION: 0.4.17 PACKAGE_NAME: firebase_messaging jobs: diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index a096af9..46e8f88 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -6,8 +6,9 @@ on: tags: - '*' env: - UV_VERSION: 0.4.5 + UV_VERSION: 0.4.17 PYPI_PROJECT: firebase-messaging + PYTHON_VERSION: 3.12 # GITHUB_TOKEN must have write access # https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/signing-the-distribution-packages @@ -18,16 +19,22 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - name: Checkout source files + uses: actions/checkout@v4 + + - name: Install uv + uses: astral-sh/setup-uv@v3 + with: + version: ${{ env.UV_VERSION }} + - name: Set up Python uses: actions/setup-python@v5 with: - python-version: "3.x" - - name: Install uv - run: |- - pipx install uv==${{ env.UV_VERSION }} --python "${{ steps.setup-python.outputs.python-path }}" + python-version: ${{ env.PYTHON_VERSION }} + - name: Build with uv run: uv build + - name: Store the distribution packages uses: actions/upload-artifact@v4 with: diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 57dca24..2b94a7d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,7 +2,7 @@ repos: - repo: https://github.com/astral-sh/uv-pre-commit # uv version. - rev: 0.4.5 + rev: 0.4.17 hooks: # Update the uv lockfile - id: uv-lock diff --git a/pyproject.toml b/pyproject.toml index 2cbed07..5be9671 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -74,6 +74,7 @@ dev-dependencies = [ testpaths = "tests" norecursedirs = ".git" asyncio_mode = "auto" +asyncio_default_fixture_loop_scope = "function" addopts = "--disable-socket --allow-unix-socket" [tool.coverage.run]