Skip to content

Commit

Permalink
Migrate workflows to setup-uv github action
Browse files Browse the repository at this point in the history
  • Loading branch information
sdb9696 committed Oct 1, 2024
1 parent b25d6f4 commit dccd906
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 57 deletions.
64 changes: 15 additions & 49 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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') }}
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
branches: ["main"]

env:
UV_VERSION: 0.4.5
UV_VERSION: 0.4.17
PACKAGE_NAME: firebase_messaging

jobs:
Expand Down
19 changes: 13 additions & 6 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit dccd906

Please sign in to comment.