Skip to content

Commit

Permalink
chore: Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
lewisjared committed Oct 16, 2024
0 parents commit 2c19964
Show file tree
Hide file tree
Showing 24 changed files with 3,093 additions and 0 deletions.
40 changes: 40 additions & 0 deletions .github/ISSUE_TEMPLATE/bug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
name: Bug report
about: Report a bug
title: ''
labels: bug
assignees: ''

---

## Describe the bug
<!--- A clear and concise description of what the bug is. -->

## Failing Test
<!---
Please put the code (ideally in the form of a unit test) which fails below.
e.g.
```python
def test_bug_12():
# Python code here which fails because of the bug
# This is best if other developers can simply copy and paste this test in
# order to run it
```
-->

## Expected behavior
<!--- A clear and concise description of what you expected to happen. -->

## Screenshots
<!--- If applicable, add screenshots to help explain your problem. -->

## System
<!--- Please complete the following information. -->

- OS: [e.g. Windows, Linux, macOS]
- Python version [e.g. Python 3.11]

## Additional context
<!--- Add any other context about the problem here. -->
21 changes: 21 additions & 0 deletions .github/ISSUE_TEMPLATE/default.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
name: Default
about: Report an issue or problem
title: ''
labels: triage
assignees: ''

---

## The problem
<!--- Useful to breakdown to "As a [persona], I [want to do], so that [reason] -->

## Definition of "done"
<!---
What are the things that must be true in order to close this issue
We find that describing these as dot points works well.
-->

## Additional context
<!--- Add any additional context can go here -->
15 changes: 15 additions & 0 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: "Setup Python and uv"
description: "setup Python and uv with caches"

runs:
using: "composite"
steps:
- name: Install uv
uses: astral-sh/setup-uv@v3
with:
version: "0.4.20"
enable-cache: true
- name: Install the project
shell: bash
run: |
uv sync --all-extras --dev --locked
9 changes: 9 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## Description

## Checklist

Please confirm that this pull request has done the following:

- [ ] Tests added
- [ ] Documentation added (where applicable)
- [ ] Changelog item added to `changelog/`
3 changes: 3 additions & 0 deletions .github/release_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Announcements

* Announcement 1
78 changes: 78 additions & 0 deletions .github/workflows/bump.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: Bump version

on:
workflow_dispatch:
inputs:
bump_rule:
type: choice
description: How to bump the project's version (see https://github.com/carstencodes/pdm-bump#usage)
options:
- no-pre-release
# no micro because we always sit on a pre-release in main,
# so we would always use no-pre-release instead of micro
# - micro
- minor
- major
- "pre-release --pre alpha"
- "pre-release --pre beta"
- "pre-release --pre release-candidate"
required: true

jobs:
bump_version:
name: "Bump version and create changelog"
if: "!startsWith(github.event.head_commit.message, 'bump:')"
runs-on: ubuntu-latest
env:
CI_COMMIT_EMAIL: "ci-runner@bookshelf.invalid"
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
token: "${{ secrets.PERSONAL_ACCESS_TOKEN }}"

- uses: ./.github/actions/setup

- name: Install pdm-bump
run: |
uv pip install pdm-bump
- name: Create bump and changelog
run: |
git config --global user.name "$GITHUB_ACTOR"
git config --global user.email "$CI_COMMIT_EMAIL"
BASE_VERSION=$(uv run python scripts/get-version.py)
echo "Bumping from version $BASE_VERSION"
# Bump
uv run pdm bump ${{ github.event.inputs.bump_rule }}
NEW_VERSION=$(uv run python scripts/get-version.py)
echo "Bumping to version $NEW_VERSION"
# Build CHANGELOG
uvx towncrier build --yes --version v$NEW_VERSION
# Commit, tag and push
git commit -a -m "bump: version $BASE_VERSION -> $NEW_VERSION"
git tag v$NEW_VERSION
git push && git push --tags
# Exit early if the version is a pre-release
[[ "$NEW_VERSION" =~ ([abrc]+) ]] && exit 0
# Bump to alpha (so that future commits do not have the same
# version as the tagged commit)
BASE_VERSION=$(uv run python scripts/get-version.py)
# Bump to pre-release of next version
uv run pdm bump pre-release --pre alpha
NEW_VERSION=$(uv run python scripts/get-version.py)
echo "Bumping version $BASE_VERSION > $NEW_VERSION"
# Commit and push
git commit -n -a -m "bump(pre-release): version $BASE_VERSION > $NEW_VERSION"
git push
61 changes: 61 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: CI

on:
pull_request:
push:
branches: [main]
tags: ['v*']

env:
BOOKSHELF_DOWNLOAD_CACHE_LOCATION: /tmp/pooch

jobs:
linting:
if: ${{ !github.event.pull_request.draft }}
runs-on: ubuntu-latest
env:
MYPYPATH: stubs
PRE_COMMIT_HOME: /tmp/.cache/pre-commit
steps:
- name: Check out repository
uses: actions/checkout@v4
- uses: ./.github/actions/setup
- name: Cache pre-commit
uses: actions/cache@v4
with:
path: /tmp/.cache/pre-commit
key: ${{ runner.os }}-pre-commit
- name: mypy
run: |
uvx pre-commit run --all-files
uv run mypy src
tests:
strategy:
fail-fast: false
matrix:
os: [ "ubuntu-latest" ]
python-version:
- "3.11"
runs-on: "${{ matrix.os }}"
defaults:
run:
shell: bash
steps:
- name: Check out repository
uses: actions/checkout@v4
- uses: ./.github/actions/setup
- name: Set up Python ${{ matrix.python-version }}
run: uv python install ${{ matrix.python-version }}
- name: Cache pooch
uses: actions/cache@v4
with:
path: /tmp/pooch
key: ${{ runner.os }}-${{ matrix.python-version }}-pooch
- name: Check build
run: |
make run
- name: Run tests
run: |
[[ ! -d "tests" ]] && exit 0
uv run pytest src tests -r a -v --doctest-modules
28 changes: 28 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Deploy

on:
release:
types: [published]

defaults:
run:
shell: bash

jobs:
deploy-bookshelf:
name: Deploy to the Bookshelf
environment: deploy
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: ./.github/actions/setup
- name: Build datasets
run: |
make run
- name: Deploy to the Bookshelf
run: |
echo "Deploying to the Bookshelf"
# uv run bookshelf publish
53 changes: 53 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Release

on:
push:
tags: ['v*']

defaults:
run:
shell: bash

jobs:
draft-release:
name: Create draft release
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: ./.github/actions/setup
- name: Add version to environment
run: |
PROJECT_VERSION=$(uv run python scripts/get-version.py)
echo "PROJECT_VERSION=$PROJECT_VERSION" >> $GITHUB_ENV
- name: Build datasets
run: |
make run
zip -r data_v$PROJECT_VERSION.zip dist
tar -czf data_v$PROJECT_VERSION.tar.gz dist
- name: Generate Release Notes
run: |
echo "" >> ".github/release_template.md"
echo "## Changelog" >> ".github/release_template.md"
echo "" >> ".github/release_template.md"
uv run python scripts/changelog-to-release-template.py >> ".github/release_template.md"
echo "" >> ".github/release_template.md"
echo "## Changes" >> ".github/release_template.md"
echo "" >> ".github/release_template.md"
git log $(git describe --tags --abbrev=0 HEAD^)..HEAD --pretty='format:* %h %s' --no-merges >> ".github/release_template.md"
- name: Archive built artifacts
uses: actions/upload-artifact@v4
with:
name: dist
path: |
dist
- name: Create Release Draft
uses: softprops/action-gh-release@v2
with:
body_path: ".github/release_template.md"
token: "${{ secrets.PERSONAL_ACCESS_TOKEN }}"
draft: true
files: |
data_*
Loading

0 comments on commit 2c19964

Please sign in to comment.