From cc9df189c9844ccd6618fb3808fd2bc12190bba6 Mon Sep 17 00:00:00 2001 From: Bjorn Neergaard Date: Sat, 30 Mar 2024 00:14:12 -0600 Subject: [PATCH] ci: add composite actions from poetry --- .github/actions/bootstrap-poetry/action.yaml | 48 +++++++++++++++++ .github/actions/poetry-install/action.yaml | 57 ++++++++++++++++++++ 2 files changed, 105 insertions(+) create mode 100644 .github/actions/bootstrap-poetry/action.yaml create mode 100644 .github/actions/poetry-install/action.yaml diff --git a/.github/actions/bootstrap-poetry/action.yaml b/.github/actions/bootstrap-poetry/action.yaml new file mode 100644 index 000000000..cec135d89 --- /dev/null +++ b/.github/actions/bootstrap-poetry/action.yaml @@ -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 diff --git a/.github/actions/poetry-install/action.yaml b/.github/actions/poetry-install/action.yaml new file mode 100644 index 000000000..9436303e3 --- /dev/null +++ b/.github/actions/poetry-install/action.yaml @@ -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