Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Major rewrite to v4 #2

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .cruft.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"template": "https://github.com/woltapp/wolt-python-package-cookiecutter",
"commit": "b25684a2c63387153b83a1cc03ea332be8c8279a",
"checkout": null,
"context": {
"cookiecutter": {
"author_name": "Markus Shepherd",
"author_email": "[email protected]",
"github_username": "recommend-games",
"project_name": "Board Game Recommender",
"project_slug": "board-game-recommender",
"package_name": "board_game_recommender",
"project_short_description": "Board game recommendation engine.",
"_template": "https://github.com/woltapp/wolt-python-package-cookiecutter"
}
},
"directory": null
}
21 changes: 21 additions & 0 deletions .github/actions/python-poetry-env/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: 'Setup Python + Poetry environment'
description: 'Setup Python + Poetry environment'

inputs:
python-version:
required: false
description: 'Python version'
default: '3.12'
outputs: {}
runs:
using: 'composite'
steps:
- uses: actions/setup-python@v5
with:
python-version: ${{inputs.python-version}}
- name: Install poetry
run: python -m pip install poetry
shell: bash
- name: Create virtual environment
run: poetry install
shell: bash
10 changes: 10 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
## Description

A short description about the changes in this pull request. If the pull request is related to some issue, mention it
here.

## Checklist

- [ ] Tests covering the new functionality have been added
- [ ] Documentation has been updated OR the change is too minor to be documented
- [ ] Changes are listed in the `CHANGELOG.md` OR changes are insignificant
79 changes: 79 additions & 0 deletions .github/workflows/cookiecutter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: Autoupdate project structure
on:
workflow_dispatch:
schedule:
- cron: "0 0 * * *" # at the end of every day

jobs:
auto-update-project:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Install dependencies
run: python -m pip install cruft poetry jello tabulate

- name: Update project structure
run: |
cruft update -y

- name: Check if there are changes
id: changes
run: echo "::set-output name=changed::$(git status --porcelain | wc -l)"

- name: apply additional changes and fixes
if: steps.changes.outputs.changed > 0
run: |
poetry lock --no-update # add new dependencies
poetry install
poetry run pre-commit run -a || true # we have to fix other issues manually

- name: Get template versions
id: get_versions
if: steps.changes.outputs.changed > 0
shell: bash
run: |
CURRENT_VERSION=$(git show HEAD:.cruft.json | jello -r "_['commit'][:8]")
NEXT_VERSION=$(jello -r "_['commit'][:8]" < .cruft.json)
echo ::set-output name="current_version::$CURRENT_VERSION"
echo ::set-output name="next_version::$NEXT_VERSION"

- name: Get changelog
id: get_changelog
if: steps.changes.outputs.changed > 0
shell: bash
run: |
TEMPLATE=$(jello -r "_['template']" < .cruft.json)
git clone "$TEMPLATE" /tmp/template
cd /tmp/template
body=$( (echo "Date;Change;Hash"; git log --pretty=format:"%as;%s;%h" ${{ steps.get_versions.outputs.current_version }}..${{ steps.get_versions.outputs.next_version }}) | tabulate --header --format github -s ';' -)
body=$(cat <<EOF
Changes from $TEMPLATE

$body
EOF
)
body="${body//'%'/'%25'}"
body="${body//$'\n'/'%0A'}"
body="${body//$'\r'/'%0D'}"
echo ::set-output name="changelog::$body"

# behaviour if PR already exists: https://github.com/marketplace/actions/create-pull-request#action-behaviour
- name: Create Pull Request
env:
# a PAT is required to be able to update workflows
GITHUB_TOKEN: ${{ secrets.AUTO_UPDATE_GITHUB_TOKEN }}
if: ${{ steps.changes.outputs.changed > 0 && env.GITHUB_TOKEN != 0 }}
uses: peter-evans/create-pull-request@v3
with:
token: ${{ env.GITHUB_TOKEN }}
commit-message: >-
chore: update project structure to ${{ steps.get_versions.outputs.next_version }}
title: "[Actions] Auto-Update cookiecutter template"
body: ${{ steps.get_changelog.outputs.changelog }}
branch: chore/auto-update-project-from-template
delete-branch: true
57 changes: 57 additions & 0 deletions .github/workflows/dependencies.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Autoupdate dependencies
on:
workflow_dispatch:
schedule:
- cron: "0 0 1 * *"

jobs:
auto-update-dependencies:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/python-poetry-env

- name: Install tabulate
run: python -m pip install tabulate

- name: Gather outdated dependencies
id: check_for_outdated_dependencies
run: |
body=$(poetry show -o -n)
echo ::set-output name="body::$body"

- name: Format PR message
if: ${{ steps.check_for_outdated_dependencies.outputs.body != 0 }}
id: get_outdated_dependencies
shell: bash
run: |
body=$(poetry show -o -n | sed 's/(!)//' | awk 'BEGIN {print "Package","Used","Update"}; {print $1,$2,$3}' | tabulate --header --format github -)
body=$(cat <<EOF
The following packages are outdated

$body
EOF
)
body="${body//'%'/'%25'}"
body="${body//$'\n'/'%0A'}"
body="${body//$'\r'/'%0D'}"
echo ::set-output name="body::$body"

- name: Update outdated packages
if: ${{ steps.check_for_outdated_dependencies.outputs.body != 0 }}
run: poetry lock

# behaviour if PR already exists: https://github.com/marketplace/actions/create-pull-request#action-behaviour
- name: Create Pull Request
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: ${{ steps.check_for_outdated_dependencies.outputs.body != 0 }}
uses: peter-evans/create-pull-request@v3
with:
token: ${{ env.GITHUB_TOKEN }}
commit-message: >-
chore: update dependencies
title: "[Actions] Auto-Update dependencies"
body: ${{ steps.get_outdated_dependencies.outputs.body }}
branch: chore/update-dependencies
delete-branch: true
52 changes: 52 additions & 0 deletions .github/workflows/draft_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Draft a release

on:
workflow_dispatch:
inputs:
version:
description: 'The version number (e.g. 1.2.3) OR one of: patch|minor|major|prepatch|preminor|premajor|prerelease'
required: true
default: 'patch'

jobs:
draft-release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/python-poetry-env
- name: Update version
id: updated_version
shell: bash
run: |
poetry version ${{ github.event.inputs.version }}
version=$(poetry version --short)
echo ::set-output name="version::$version"
- name: Update changelog
id: changelog
shell: bash
run: |
poetry run kacl-cli release ${{ steps.updated_version.outputs.version }} --modify --auto-link
echo "" >> CHANGELOG.md
body=$(poetry run kacl-cli get ${{ steps.updated_version.outputs.version }})
body="${body//'%'/'%25'}"
body="${body//$'\n'/'%0A'}"
body="${body//$'\r'/'%0D'}"
echo ::set-output name="body::$body"
- name: Commit changes
uses: EndBug/add-and-commit@v7
with:
add: 'CHANGELOG.md pyproject.toml'
message: 'Release ${{ steps.updated_version.outputs.version }}'
- name: Create tag
run: |
git tag ${{ steps.updated_version.outputs.version }}
git push origin ${{ steps.updated_version.outputs.version }}
- name: Create a draft release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.updated_version.outputs.version }}
release_name: Release ${{ steps.updated_version.outputs.version }}
body: ${{ steps.changelog.outputs.body }}
draft: true
18 changes: 18 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Release

on:
release:
types: [ published ]

jobs:
build-and-publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/python-poetry-env
- name: Publish to pypi
run: |
poetry config pypi-token.pypi ${{ secrets.PYPI_TOKEN }}
poetry publish --build --no-interaction
- name: Deploy docs
run: poetry run mkdocs gh-deploy --force
54 changes: 54 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Test

on:
pull_request:
push:
branches:
- "**"

jobs:
actionlint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Download actionlint
run: bash <(curl https://raw.githubusercontent.com/rhysd/actionlint/main/scripts/download-actionlint.bash) 1.6.21
shell: bash
- name: Check workflow files
run: ./actionlint -color
shell: bash

lint-cruft:
name: Check if automatic project update was successful
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Fail if .rej files exist as structure update was not successful
run: test -z "$(find . -iname '*.rej')"

pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/python-poetry-env
- run: poetry run pre-commit run --all-files

test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/python-poetry-env
with:
python-version: ${{ matrix.python-version }}
- run: poetry run pytest

docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/python-poetry-env
- run: poetry run mkdocs build
Loading
Loading