Skip to content

Commit cc9df18

Browse files
committed
ci: add composite actions from poetry
1 parent 7e7b6ad commit cc9df18

2 files changed

Lines changed: 105 additions & 0 deletions

File tree

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Bootstrap Poetry
2+
description: Configure the environment with the specified Python and Poetry version.
3+
4+
inputs:
5+
python-version:
6+
description: Desired node-semver compatible Python version expression (or 'default')
7+
default: 'default'
8+
python-latest:
9+
description: Use an uncached Python if a newer match is available
10+
default: 'false'
11+
python-prereleases:
12+
description: Allow usage of pre-release Python versions
13+
default: 'false'
14+
poetry-spec:
15+
description: pip-compatible installation specification to use for Poetry
16+
default: 'poetry'
17+
18+
outputs:
19+
python-path:
20+
description: Path to the installed Python interpreter
21+
value: ${{ steps.setup-python.outputs.python-path }}
22+
python-version:
23+
description: Version of the installed Python interpreter
24+
value: ${{ steps.setup-python.outputs.python-version }}
25+
26+
runs:
27+
using: composite
28+
steps:
29+
- uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c # v5
30+
id: setup-python
31+
if: inputs.python-version != 'default'
32+
with:
33+
python-version: ${{ inputs.python-version }}
34+
check-latest: ${{ inputs.python-latest == 'true' }}
35+
allow-prereleases: ${{ inputs.python-prereleases == 'true' }}
36+
update-environment: false
37+
38+
- run: >
39+
pipx install \
40+
${{ inputs.python-version != 'default' && format('--python "{0}"', steps.setup-python.outputs.python-path) || '' }} \
41+
'${{ inputs.poetry-spec }}'
42+
shell: bash
43+
44+
# Enable handling long path names (+260 char) on the Windows platform
45+
# https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file#maximum-path-length-limitation
46+
- run: git config --system core.longpaths true
47+
if: runner.os == 'Windows'
48+
shell: pwsh
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Poetry Install
2+
description: Run `poetry install` with optional artifact and metadata caching
3+
4+
inputs:
5+
args:
6+
description: Arguments for `poetry install`
7+
cache:
8+
description: Enable transparent Poetry artifact and metadata caching
9+
default: 'true'
10+
path:
11+
description: Path to Poetry project
12+
default: '.'
13+
14+
outputs:
15+
cache-hit:
16+
description: Whether an exact cache hit occured
17+
value: ${{ steps.cache.outputs.cache-hit }}
18+
19+
defaults:
20+
run:
21+
working-directory: ${{ inputs.path }}
22+
23+
runs:
24+
using: composite
25+
steps:
26+
- run: printf 'cache-dir=%s\n' "$(poetry config cache-dir)" >> $GITHUB_OUTPUT
27+
id: poetry-config
28+
shell: bash
29+
30+
# Bust the cache every 24 hours to prevent it from expanding over time.
31+
- run: printf 'date=%s\n' "$(date -I)" >> $GITHUB_OUTPUT
32+
id: get-date
33+
if: inputs.cache == 'true'
34+
shell: bash
35+
36+
- uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4
37+
id: cache
38+
if: inputs.cache == 'true'
39+
with:
40+
path: |
41+
${{ steps.poetry-config.outputs.cache-dir }}/artifacts
42+
${{ steps.poetry-config.outputs.cache-dir }}/cache
43+
key: poetry-${{ steps.get-date.outputs.date }}-${{ runner.os }}-${{ hashFiles(format('{0}/pyproject.toml', inputs.path), format('{0}/poetry.lock', inputs.path)) }}
44+
# The cache is cross-platform, and other platforms are used to seed cache misses.
45+
restore-keys: |
46+
poetry-${{ steps.get-date.outputs.date }}-${{ runner.os }}-
47+
poetry-${{ steps.get-date.outputs.date }}-
48+
enableCrossOsArchive: true
49+
50+
- run: poetry install ${{ inputs.args }}
51+
shell: bash
52+
53+
- run: poetry env info
54+
shell: bash
55+
56+
- run: poetry show
57+
shell: bash

0 commit comments

Comments
 (0)