Skip to content

Commit

Permalink
ci(workflows): update python_package workflow to separate build and p…
Browse files Browse the repository at this point in the history
…ublish steps

ci(workflows): add test_and_lint workflow for testing and linting on push and PR events
  • Loading branch information
NodeJSmith committed Jun 15, 2024
1 parent f6f244b commit 253abe2
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 32 deletions.
83 changes: 51 additions & 32 deletions .github/workflows/python_package.yml
Original file line number Diff line number Diff line change
@@ -1,49 +1,68 @@
name: Python package
name: Publish Python package

on: [push, pull_request]
on:
release:
types: [released, prereleased]
workflow_dispatch:
inputs:
commit:
description: "Commit to build from"
required: true
default: "main"

jobs:
test:
runs-on: ubuntu-latest

env:
ACTIONS_RUNNER_DEBUG: true
ACTIONS_STEP_DEBUG: true
build-pypi-dists:
name: Build Python package

strategy:
matrix:
python-version: ["3.10", "3.11"]
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4
- uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.commit }}
# Versioneer only generates correct versions with a full fetch
fetch-depth: 0
persist-credentials: false

- name: Install poetry
run: pipx install poetry

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
python-version: "3.10"
cache: "poetry"

- name: Cache pip
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/pyproject.toml') }}-${{ matrix.python-version }}
restore-keys: |
${{ runner.os }}-pip-${{ matrix.python-version }}
- name: Install python packages
run: poetry install

- name: Install dependencies
- name: Build a binary wheel and a source tarball
run: |
python -m pip install --upgrade pip
pip install tox
poetry build
- name: Run tests
run: tox -e ${{ matrix.python-version }}
- name: Publish build artifacts
uses: actions/upload-artifact@v4
with:
name: pypi-dists
path: "./dist"

- name: Run lint checks
run: tox -e lint
publish-pypi-dists:
name: Publish to PyPI
environment:
name: release
url: https://pypi.org/p/otf-api
needs: [build-pypi-dists]
runs-on: ubuntu-latest
permissions:
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')

- name: Run build checks
run: tox -e build
steps:
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: pypi-dists
path: "./dist"

- name: Run mkdocs build
run: tox -e docs
- name: Publish distribution to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
55 changes: 55 additions & 0 deletions .github/workflows/test_and_lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Python package

on: [push, pull_request]

jobs:
test:
runs-on: ubuntu-latest

env:
ACTIONS_RUNNER_DEBUG: true
ACTIONS_STEP_DEBUG: true

strategy:
matrix:
python-version: ["3.10", "3.11"]

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Cache pip
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/pyproject.toml') }}-${{ matrix.python-version }}
restore-keys: |
${{ runner.os }}-pip-${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install tox
- name: Run tests
run: tox -e ${{ matrix.python-version }}

- name: Run lint checks
run: tox -e lint

- name: Run mkdocs build
run: tox -e docs

- name: Run build checks
run: tox -e build

- name: Publish build artifacts
uses: actions/upload-artifact@v4
with:
name: pypi-dists
path: "./dist"

0 comments on commit 253abe2

Please sign in to comment.