Skip to content

Commit

Permalink
ci: add composite actions from poetry
Browse files Browse the repository at this point in the history
  • Loading branch information
neersighted committed Apr 1, 2024
1 parent 1a41415 commit 94b865c
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 0 deletions.
48 changes: 48 additions & 0 deletions .github/actions/bootstrap-poetry/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Bootstrap Poetry
description: Configure the environment with the specified Python and Poetry version.

inputs:
python-version:
description: Desired node-semver compatible Python version expression (or 'default')
default: 'default'
python-latest:
description: Use an uncached Python if a newer match is available
default: 'false'
python-prereleases:
description: Allow usage of pre-release Python versions
default: 'false'
poetry-spec:
description: pip-compatible installation specification to use for Poetry
default: 'poetry'

outputs:
python-path:
description: Path to the installed Python interpreter
value: ${{ steps.setup-python.outputs.python-path }}
python-version:
description: Version of the installed Python interpreter
value: ${{ steps.setup-python.outputs.python-version }}

runs:
using: composite
steps:
- uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c # v5
id: setup-python
if: inputs.python-version != 'default'
with:
python-version: ${{ inputs.python-version }}
check-latest: ${{ inputs.python-latest == 'true' }}
allow-prereleases: ${{ inputs.python-prereleases == 'true' }}
update-environment: false

- run: >
pipx install \
${{ inputs.python-version != 'default' && format('--python "{0}"', steps.setup-python.outputs.python-path) || '' }} \
'${{ inputs.poetry-spec }}'
shell: bash
# Enable handling long path names (+260 char) on the Windows platform
# https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file#maximum-path-length-limitation
- run: git config --system core.longpaths true
if: runner.os == 'Windows'
shell: pwsh
57 changes: 57 additions & 0 deletions .github/actions/poetry-install/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Poetry Install
description: Run `poetry install` with optional artifact and metadata caching

inputs:
args:
description: Arguments for `poetry install`
cache:
description: Enable transparent Poetry artifact and metadata caching
default: 'true'
path:
description: Path to Poetry project
default: '.'

outputs:
cache-hit:
description: Whether an exact cache hit occured
value: ${{ steps.cache.outputs.cache-hit }}

defaults:
run:
working-directory: ${{ inputs.path }}

runs:
using: composite
steps:
- run: printf 'cache-dir=%s\n' "$(poetry config cache-dir)" >> $GITHUB_OUTPUT
id: poetry-config
shell: bash

# Bust the cache every 24 hours to prevent it from expanding over time.
- run: printf 'date=%s\n' "$(date -I)" >> $GITHUB_OUTPUT
id: get-date
if: inputs.cache == 'true'
shell: bash

- uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4
id: cache
if: inputs.cache == 'true'
with:
path: |
${{ steps.poetry-config.outputs.cache-dir }}/artifacts
${{ steps.poetry-config.outputs.cache-dir }}/cache
key: poetry-${{ steps.get-date.outputs.date }}-${{ runner.os }}-${{ hashFiles(format('{0}/pyproject.toml', inputs.path), format('{0}/poetry.lock', inputs.path)) }}
# The cache is cross-platform, and other platforms are used to seed cache misses.
restore-keys: |
poetry-${{ steps.get-date.outputs.date }}-${{ runner.os }}-
poetry-${{ steps.get-date.outputs.date }}-
enableCrossOsArchive: true

- run: poetry install ${{ inputs.args }}
shell: bash

- run: poetry env info
shell: bash

- run: poetry show
shell: bash

0 comments on commit 94b865c

Please sign in to comment.