Skip to content

Commit

Permalink
ci: Set up initial pass at CI/CD
Browse files Browse the repository at this point in the history
  • Loading branch information
seandstewart committed Jun 19, 2024
1 parent f4742e0 commit 4d06c8e
Show file tree
Hide file tree
Showing 8 changed files with 326 additions and 11 deletions.
33 changes: 33 additions & 0 deletions .github/actions/bootstrap-environ/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: setup-environ
description: Setup the CI environ with Poetry & Pre-Commit Caching

inputs:
python-version:
description: The Python version to build your environment with.
runner:
description: The Runner to build your environment on.

runs:
using: composite
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ inputs.python-version }}
- uses: Gr1N/setup-poetry@v8
- uses: actions/cache@v4
with:
path: ~/.cache/
key: |
${{ inputs.runner.name }}-
${{ inputs.python-version }}-
${{ hashFiles('poetry.lock') }}-
${{ hashFiles('.pre-commit-config.yaml') }}
- run: poetry --version
shell: bash
- run: make install
shell: bash
- run: poetry env info
shell: bash
- run: poetry show
shell: bash
34 changes: 34 additions & 0 deletions .github/workflows/.build-matrix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Reusable workflow to enable a single shared matrix for builds.
# Only one job currently, may be extended later to include Cython builds.
on:
workflow_call:
inputs:
runner:
required: true
type: string
python-version:
required: true
type: string

defaults:
run:
shell: bash

jobs:
build-wheel:
name: build-wheel
runs-on: ${{ inputs.runner }}
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/bootstrap-environ
id: bootstrap-environ
with:
python-version: ${{ inputs.python-version }}
runner: ${{ inputs.runner }}
- name: Build ${{ inputs.runner }} binaries
run: poetry build
- name: Store dist artifacts
uses: actions/upload-artifact@v4
with:
name: typelib-dist
path: dist
50 changes: 50 additions & 0 deletions .github/workflows/.validate-matrix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Reusable workflow consumed by ci.yml; used to share a single matrix across jobs.
on:
workflow_call:
inputs:
runner:
required: true
type: string
python-version:
required: true
type: string

defaults:
run:
shell: bash

jobs:
lint:
name: lint
runs-on: ${{ inputs.runner }}
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/bootstrap-environ
id: bootstrap-environ
with:
python-version: ${{ inputs.python-version }}
runner: ${{ inputs.runner }}
- run: make lint
test:
runs-on: ${{ inputs.runner }}
env:
OS: ${{ inputs.runner }}
PYTHON: ${{ inputs.python-version }}
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/bootstrap-environ
id: bootstrap-environ
with:
python-version: ${{ inputs.python-version }}
runner: ${{ inputs.runner }}
- name: pytest
run: make test
- name: coverage
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./coverage.xml
env_vars: OS,PYTHON
flags: unittests
name: codecov-umbrella
fail_ci_if_error: false
137 changes: 137 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
name: Create Release

on:
workflow_dispatch:
inputs:
level:
description: "The level to bump the current version"
required: true
default: "patch"
options:
- "patch"
- "minor"
- "major"
- "prepatch"
- "preminor"
- "prerelease"

jobs:
create-version:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest ]
python-version: [ "3.9" ]
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/bootstrap-environ
id: bootstrap-environ
with:
python-version: ${{ matrix.python-version }}
runner: ${{ matrix.os.image }}
# In order to make a commit, we need to initialize a user.
- name: Initialize mandatory git config
run: |
git config user.name "GitHub actions"
git config user.email [email protected]
- run: |
echo "PRIOR_VERSION=v$(make report-version)" >> $GITHUB_ENV
make release-version rule=${{ inputs.level }}
echo "RELEASE_VERSION=v$(make report-version)" >> $GITHUB_ENV
- name: Update the Changelog
run: make changelog
- name: Push the Version and Changelog
run: git push origin ${{ github.ref_name}}

build-wheels:
needs: [ release-version ]
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ macos-latest, ubuntu-latest, windows-latest ]
python-version: [ "3.9", "3.10", "3.11", "3.12" ]
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/bootstrap-environ
id: bootstrap-environ
with:
python-version: ${{ matrix.python-version }}
runner: ${{ matrix.os.image }}
- uses: ./.github/workflows/.build-matrix.yml
with:
runner: ${{ matrix.os.image }}
python-version: ${{ matrix.python-version }}
- name: Store dist artifacts
uses: actions/upload-artifact@v4
with:
name: typelib-dist
path: dist

build-sdist:
needs: [release-version]
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest ]
python-version: [ "3.9" ]
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/bootstrap-environ
id: bootstrap-environ
with:
python-version: ${{ matrix.python-version }}
runner: ${{ matrix.os.image }}
- name: Build sdist
run: poetry build -f sdist
- name: Store dist artifacts
uses: actions/upload-artifact@v4
with:
name: typelib-dist
path: dist

publish-pypi:
runs-on: ${{ matrix.os }}
needs: [ build-wheels, build-sdist ]
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest ]
python-version: [ "3.9" ]
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/bootstrap-environ
id: bootstrap-environ
with:
python-version: ${{ matrix.python-version }}
runner: ubuntu-latest
- name: Download distribution artifact
uses: actions/download-artifact@v4
with:
name: typelib-dist
path: dist
- name: Publish to PyPI
run: poetry publish -u $PYPI_USERNAME -p $PYPI_PASSWORD
env:
PYPI_USERNAME: ${{ secrets.PYPI_USERNAME }}
PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }}

create-release:
needs: [ release-version, build-wheels, build-sdist ]
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest ]
python-version: [ "3.9" ]
steps:
- name: Compile Release Notes
run: make release-notes > release-notes.md
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
body_path: release-notes.md
tag_name: ${{ github.env.RELEASE_VERSION }}
make_latest: true
14 changes: 14 additions & 0 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Validate
on: [push, pull_request]
jobs:
ci:
uses: ./.github/workflows/.validate-matrix.yaml
name: "${{ matrix.os.name }} (Python ${{ matrix.python-version }})"
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.9", "3.10", "3.11", "3.12"]
with:
runner: ${{ matrix.os.image }}
python-version: ${{ matrix.python-version }}
32 changes: 32 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

<!-- insertion marker -->
## Unreleased

<small>[Compare with latest](https://github.com/seandstewart/python-typelib/compare/ac01975a1a2d50a197716e9d5cfb03be13d26fa9...HEAD)</small>

### Features

- Implement marshallers. ([ed159ef](https://github.com/seandstewart/python-typelib/commit/ed159ef10f90ea4e9a5ea89e3b2c62b03119a08c) by Sean Stewart).
- Support TypeAliasType ([e235f43](https://github.com/seandstewart/python-typelib/commit/e235f43f0e2322edc90526e6ba6c1af89abb3b7a) by Sean Stewart).
- Support for cyclic types. ([4422413](https://github.com/seandstewart/python-typelib/commit/44224130f5d129699652c59e6124e3164ffd4192) by Sean Stewart).
- Defining the unmarshal API. ([8117e0c](https://github.com/seandstewart/python-typelib/commit/8117e0c088c6de024f627e0a5aa17ccb731a68d9) by Sean Stewart).
- Better generics interface. ([0f96785](https://github.com/seandstewart/python-typelib/commit/0f9678560e7d3c5412704ac43763b94fee8d34ad) by Sean Stewart).
- Initial pass of complex types for unmarshalling. ([82b566c](https://github.com/seandstewart/python-typelib/commit/82b566c8715a346bde6ac59617b72f0313c0e994) by Sean Stewart).
- Unmarshallers for initial primitive types. ([1c6aa1c](https://github.com/seandstewart/python-typelib/commit/1c6aa1cead5b73a9da15dc26940e4909703ee4db) by Sean Stewart).
- Core utilities and graph resolver, with test coverage. ([108faa1](https://github.com/seandstewart/python-typelib/commit/108faa1a845775dbbc43bcf75289f8fc3a6921f1) by Sean Stewart).

### Bug Fixes

- Fix type hints for marshalled values ([f4742e0](https://github.com/seandstewart/python-typelib/commit/f4742e0161042304b980bb2c69c3b0de65705eab) by Sean Stewart).
- Enforce utc for tz-naive datetime.date during number conversion ([afe79fb](https://github.com/seandstewart/python-typelib/commit/afe79fbbafef93fbd9aac9c5eaf146cebb78cb22) by Sean Stewart).
- The factory function can handle strings/forwardrefs. ([34dd7dd](https://github.com/seandstewart/python-typelib/commit/34dd7dd807e72e5a48b2652898c95c85ccec7110) by Sean Stewart).
- Tweaking root node assignment. ([6b1f141](https://github.com/seandstewart/python-typelib/commit/6b1f14136e356179c63fb5bd4c38849de493f025) by Sean Stewart).
- Fix passing var names to unmarshaller ([38c2002](https://github.com/seandstewart/python-typelib/commit/38c2002c6bd0a509a24ca73250bad5403994c620) by Sean Stewart).

<!-- insertion marker -->
29 changes: 19 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,32 @@ test: ## Run this app's tests with a test db. Target a specific path `target=pat

TEST_ARGS ?= --cov --cov-config=.coveragerc --cov-report=xml --cov-report=term --junit-xml=junit.xml

bump-version: ## Bump the version for this package.
@poetry version $(rule)
.PHONY: bump-version

rule ?= patch

tag-version: bump-version ## Bump and tag a new version for this package

release-version: ## Bump the version for this package.
@poetry version $(rule)
@$(eval version := $(shell poetry version -s))
@$(eval message := [skip ci] Release $(version))
@git add pyproject.toml && @git commit -m "$(message)"
@git tag v$(version) -m "$(message)"
.PHONY: tag-version
@git add pyproject.toml
@git commit -m "$(message)"
@git tag -a v$(version) -m $(message)
.PHONY: release-version


report-version: ## Show the current version of this application.
@poetry version
report-version: ## Show the current version of this library.
@poetry version -s
.PHONY: report-version

changelog: ## Compile the latest changelog for the current branch.
@git changelog
@git add CHANGELOG.md
@git commit -m "[skip ci] Update changelog."
.PHONY: changelog

release-notes: ## Compile release notes for VCS
@git changelog --release-notes
.PHONY: release-notes

# endregion

Expand Down
8 changes: 7 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "typelib"
version = "0.1.0"
version = "0.0.0"
description = "A toolkit for marshalling, unmarshalling, and runtime validation leveraging type annotations."
authors = ["Sean Stewart <[email protected]>"]
readme = "README.md"
Expand Down Expand Up @@ -126,6 +126,12 @@ no_strict_optional = true
follow_imports = "silent"
exclude = ".*tests/.*|.*docs/.*"

[tool.git-changelog]
convention = "conventional"
in-place = true
output = "CHANGELOG.md"
parse-refs = true

[build-system]
requires = ["poetry-core>=1.8.0"]
build-backend = "poetry.core.masonry.api"

0 comments on commit 4d06c8e

Please sign in to comment.