Skip to content

Commit

Permalink
ci: DRY with composite actions
Browse files Browse the repository at this point in the history
  • Loading branch information
neersighted committed Mar 25, 2024
1 parent 9ac132a commit 70306cb
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 61 deletions.
34 changes: 34 additions & 0 deletions .github/actions/bootstrap-poetry/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Bootstrap Poetry
description: Configure the environment with the specified Python and Poetry version.

inputs:
python-version:
description: Desired Python version
default: "3.12"
python-latest:
description: Use an uncached Python if a newer match is available
default: 'false'
poetry-spec:
description: pip-compatible installation specification to use for Poetry
default: 'poetry'

runs:
using: composite
steps:
# 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
- id: git-config-longpaths
if: runner.os == 'Windows'
shell: pwsh
run: git config --system core.longpaths true

- id: pipx-poetry
shell: bash
run: pipx install '${{ inputs.poetry-spec }}'

- id: setup-python
uses: actions/setup-python@v5
with:
python-version: ${{ inputs.python-version }}
check-latest: ${{ inputs.python-latest == 'true' }}
cache: poetry
39 changes: 16 additions & 23 deletions .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,43 +33,36 @@ jobs:
with:
repository: python-poetry/website

- name: Bootstrap poetry
run: pipx install poetry

- name: Checkout Poetry Source
uses: actions/checkout@v4
with:
path: poetry
ref: ${{ github.event.pull_request.head.sha }}

- name: Set up Python
uses: actions/setup-python@v5
- uses: actions/setup-node@v4
with:
python-version: "3.12"
cache: poetry
node-version: "18"

- name: Setup Node
uses: actions/setup-node@v4
- uses: peaceiris/actions-hugo@v2
with:
node-version: "18"
hugo-version: '0.83.1'

- name: Build Assets
run: npm ci && npm run prod
- uses: ./.github/actions/bootstrap-poetry

- name: Fetch Documentation
run: |
poetry install --no-root --only main
poetry run python bin/website build --local ./poetry
- run: poetry install --no-root --only main

- name: Install Hugo
uses: peaceiris/actions-hugo@v2
with:
hugo-version: '0.83.1'
- name: Build Website
run: |
set -eux -o pipefail
- name: Build
run: hugo -v --minify
# Rebuild the docs files from the PR checkout.
poetry run python bin/website build --local ./poetry
# Build website assets (CSS/JS).
npm ci && npm run prod
# Build the static website.
hugo -v --minify
- name: Deploy
- name: Deploy Website
uses: amondnet/vercel-action@v25
id: vercel-action
with:
Expand Down
42 changes: 4 additions & 38 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,9 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Bootstrap poetry
run: pipx install poetry
- uses: ./.github/actions/bootstrap-poetry

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: poetry

- name: Configure poetry
run: |
poetry config virtualenvs.in-project true
poetry config virtualenvs.options.no-pip true
poetry config virtualenvs.options.no-setuptools true
- name: Install dependencies
run: poetry install --only main,test
- run: poetry install --only main,test

- name: Regenerate PyPI fixtures
run: PYTHONPATH="$PWD" poetry run python tests/repositories/fixtures/pypi.org/generate.py
Expand Down Expand Up @@ -92,38 +78,18 @@ jobs:
- uses: actions/checkout@v4
if: needs.changes.outputs.pytest == 'true'

- name: Bootstrap poetry
if: needs.changes.outputs.pytest == 'true'
run: pipx install poetry

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
- uses: ./.github/actions/bootstrap-poetry
if: needs.changes.outputs.pytest == 'true'
with:
python-version: ${{ matrix.python-version }}
cache: poetry

- name: Enable long paths for git on Windows
if: needs.changes.outputs.pytest == 'true' && matrix.os == 'Windows'
# 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

- name: Configure poetry
- run: poetry install --with github-actions
if: needs.changes.outputs.pytest == 'true'
run: |
poetry config virtualenvs.in-project true
poetry config virtualenvs.options.no-pip true
poetry config virtualenvs.options.no-setuptools true

- name: Check lock file
if: needs.changes.outputs.pytest == 'true'
run: poetry check --lock

- name: Install dependencies
if: needs.changes.outputs.pytest == 'true'
run: poetry install --with github-actions

- name: Run mypy
if: needs.changes.outputs.pytest == 'true'
run: poetry run mypy
Expand Down

0 comments on commit 70306cb

Please sign in to comment.