Skip to content

Commit de8fc46

Browse files
Cruft
1 parent db8c5ff commit de8fc46

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+2161
-127
lines changed

.cruft.json

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"template": "https://github.com/woltapp/wolt-python-package-cookiecutter",
3+
"commit": "b25684a2c63387153b83a1cc03ea332be8c8279a",
4+
"checkout": null,
5+
"context": {
6+
"cookiecutter": {
7+
"author_name": "Markus Shepherd",
8+
"author_email": "[email protected]",
9+
"github_username": "recommend-games",
10+
"project_name": "Board Game Scraper",
11+
"project_slug": "board-game-scraper",
12+
"package_name": "board_game_scraper",
13+
"project_short_description": "Scraping data about board games from the web",
14+
"_template": "https://github.com/woltapp/wolt-python-package-cookiecutter"
15+
}
16+
},
17+
"directory": null
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: 'Setup Python + Poetry environment'
2+
description: 'Setup Python + Poetry environment'
3+
4+
inputs:
5+
python-version:
6+
required: false
7+
description: 'Python version'
8+
default: '3.12'
9+
outputs: {}
10+
runs:
11+
using: 'composite'
12+
steps:
13+
- uses: actions/setup-python@v5
14+
with:
15+
python-version: ${{inputs.python-version}}
16+
- name: Install poetry
17+
run: python -m pip install poetry
18+
shell: bash
19+
- name: Create virtual environment
20+
run: poetry install
21+
shell: bash

.github/pull_request_template.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
## Description
2+
3+
A short description about the changes in this pull request. If the pull request is related to some issue, mention it
4+
here.
5+
6+
## Checklist
7+
8+
- [ ] Tests covering the new functionality have been added
9+
- [ ] Documentation has been updated OR the change is too minor to be documented
10+
- [ ] Changes are listed in the `CHANGELOG.md` OR changes are insignificant

.github/workflows/cookiecutter.yml

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: Autoupdate project structure
2+
on:
3+
workflow_dispatch:
4+
schedule:
5+
- cron: "0 0 * * *" # at the end of every day
6+
7+
jobs:
8+
auto-update-project:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
- name: Set up Python
13+
uses: actions/setup-python@v5
14+
with:
15+
python-version: "3.12"
16+
17+
- name: Install dependencies
18+
run: python -m pip install cruft poetry jello tabulate
19+
20+
- name: Update project structure
21+
run: |
22+
cruft update -y
23+
24+
- name: Check if there are changes
25+
id: changes
26+
run: echo "::set-output name=changed::$(git status --porcelain | wc -l)"
27+
28+
- name: apply additional changes and fixes
29+
if: steps.changes.outputs.changed > 0
30+
run: |
31+
poetry lock --no-update # add new dependencies
32+
poetry install
33+
poetry run pre-commit run -a || true # we have to fix other issues manually
34+
35+
- name: Get template versions
36+
id: get_versions
37+
if: steps.changes.outputs.changed > 0
38+
shell: bash
39+
run: |
40+
CURRENT_VERSION=$(git show HEAD:.cruft.json | jello -r "_['commit'][:8]")
41+
NEXT_VERSION=$(jello -r "_['commit'][:8]" < .cruft.json)
42+
echo ::set-output name="current_version::$CURRENT_VERSION"
43+
echo ::set-output name="next_version::$NEXT_VERSION"
44+
45+
- name: Get changelog
46+
id: get_changelog
47+
if: steps.changes.outputs.changed > 0
48+
shell: bash
49+
run: |
50+
TEMPLATE=$(jello -r "_['template']" < .cruft.json)
51+
git clone "$TEMPLATE" /tmp/template
52+
cd /tmp/template
53+
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 ';' -)
54+
body=$(cat <<EOF
55+
Changes from $TEMPLATE
56+
57+
$body
58+
EOF
59+
)
60+
body="${body//'%'/'%25'}"
61+
body="${body//$'\n'/'%0A'}"
62+
body="${body//$'\r'/'%0D'}"
63+
echo ::set-output name="changelog::$body"
64+
65+
# behaviour if PR already exists: https://github.com/marketplace/actions/create-pull-request#action-behaviour
66+
- name: Create Pull Request
67+
env:
68+
# a PAT is required to be able to update workflows
69+
GITHUB_TOKEN: ${{ secrets.AUTO_UPDATE_GITHUB_TOKEN }}
70+
if: ${{ steps.changes.outputs.changed > 0 && env.GITHUB_TOKEN != 0 }}
71+
uses: peter-evans/create-pull-request@v3
72+
with:
73+
token: ${{ env.GITHUB_TOKEN }}
74+
commit-message: >-
75+
chore: update project structure to ${{ steps.get_versions.outputs.next_version }}
76+
title: "[Actions] Auto-Update cookiecutter template"
77+
body: ${{ steps.get_changelog.outputs.changelog }}
78+
branch: chore/auto-update-project-from-template
79+
delete-branch: true

.github/workflows/dependencies.yml

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Autoupdate dependencies
2+
on:
3+
workflow_dispatch:
4+
schedule:
5+
- cron: "0 0 1 * *"
6+
7+
jobs:
8+
auto-update-dependencies:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
- uses: ./.github/actions/python-poetry-env
13+
14+
- name: Install tabulate
15+
run: python -m pip install tabulate
16+
17+
- name: Gather outdated dependencies
18+
id: check_for_outdated_dependencies
19+
run: |
20+
body=$(poetry show -o -n)
21+
echo ::set-output name="body::$body"
22+
23+
- name: Format PR message
24+
if: ${{ steps.check_for_outdated_dependencies.outputs.body != 0 }}
25+
id: get_outdated_dependencies
26+
shell: bash
27+
run: |
28+
body=$(poetry show -o -n | sed 's/(!)//' | awk 'BEGIN {print "Package","Used","Update"}; {print $1,$2,$3}' | tabulate --header --format github -)
29+
body=$(cat <<EOF
30+
The following packages are outdated
31+
32+
$body
33+
EOF
34+
)
35+
body="${body//'%'/'%25'}"
36+
body="${body//$'\n'/'%0A'}"
37+
body="${body//$'\r'/'%0D'}"
38+
echo ::set-output name="body::$body"
39+
40+
- name: Update outdated packages
41+
if: ${{ steps.check_for_outdated_dependencies.outputs.body != 0 }}
42+
run: poetry lock
43+
44+
# behaviour if PR already exists: https://github.com/marketplace/actions/create-pull-request#action-behaviour
45+
- name: Create Pull Request
46+
env:
47+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
48+
if: ${{ steps.check_for_outdated_dependencies.outputs.body != 0 }}
49+
uses: peter-evans/create-pull-request@v3
50+
with:
51+
token: ${{ env.GITHUB_TOKEN }}
52+
commit-message: >-
53+
chore: update dependencies
54+
title: "[Actions] Auto-Update dependencies"
55+
body: ${{ steps.get_outdated_dependencies.outputs.body }}
56+
branch: chore/update-dependencies
57+
delete-branch: true

.github/workflows/draft_release.yml

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Draft a release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: 'The version number (e.g. 1.2.3) OR one of: patch|minor|major|prepatch|preminor|premajor|prerelease'
8+
required: true
9+
default: 'patch'
10+
11+
jobs:
12+
draft-release:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
- uses: ./.github/actions/python-poetry-env
17+
- name: Update version
18+
id: updated_version
19+
shell: bash
20+
run: |
21+
poetry version ${{ github.event.inputs.version }}
22+
version=$(poetry version --short)
23+
echo ::set-output name="version::$version"
24+
- name: Update changelog
25+
id: changelog
26+
shell: bash
27+
run: |
28+
poetry run kacl-cli release ${{ steps.updated_version.outputs.version }} --modify --auto-link
29+
echo "" >> CHANGELOG.md
30+
body=$(poetry run kacl-cli get ${{ steps.updated_version.outputs.version }})
31+
body="${body//'%'/'%25'}"
32+
body="${body//$'\n'/'%0A'}"
33+
body="${body//$'\r'/'%0D'}"
34+
echo ::set-output name="body::$body"
35+
- name: Commit changes
36+
uses: EndBug/add-and-commit@v7
37+
with:
38+
add: 'CHANGELOG.md pyproject.toml'
39+
message: 'Release ${{ steps.updated_version.outputs.version }}'
40+
- name: Create tag
41+
run: |
42+
git tag ${{ steps.updated_version.outputs.version }}
43+
git push origin ${{ steps.updated_version.outputs.version }}
44+
- name: Create a draft release
45+
uses: actions/create-release@v1
46+
env:
47+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
48+
with:
49+
tag_name: ${{ steps.updated_version.outputs.version }}
50+
release_name: Release ${{ steps.updated_version.outputs.version }}
51+
body: ${{ steps.changelog.outputs.body }}
52+
draft: true

.github/workflows/release.yml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Release
2+
3+
on:
4+
release:
5+
types: [ published ]
6+
7+
jobs:
8+
build-and-publish:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
- uses: ./.github/actions/python-poetry-env
13+
- name: Publish to pypi
14+
run: |
15+
poetry config pypi-token.pypi ${{ secrets.PYPI_TOKEN }}
16+
poetry publish --build --no-interaction
17+
- name: Deploy docs
18+
run: poetry run mkdocs gh-deploy --force

.github/workflows/test.yml

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Test
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- "**"
8+
9+
jobs:
10+
actionlint:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
- name: Download actionlint
15+
run: bash <(curl https://raw.githubusercontent.com/rhysd/actionlint/main/scripts/download-actionlint.bash) 1.6.21
16+
shell: bash
17+
- name: Check workflow files
18+
run: ./actionlint -color
19+
shell: bash
20+
21+
lint-cruft:
22+
name: Check if automatic project update was successful
23+
runs-on: ubuntu-latest
24+
steps:
25+
- uses: actions/checkout@v4
26+
- name: Fail if .rej files exist as structure update was not successful
27+
run: test -z "$(find . -iname '*.rej')"
28+
29+
pre-commit:
30+
runs-on: ubuntu-latest
31+
steps:
32+
- uses: actions/checkout@v4
33+
- uses: ./.github/actions/python-poetry-env
34+
- run: poetry run pre-commit run --all-files
35+
36+
test:
37+
runs-on: ubuntu-latest
38+
strategy:
39+
fail-fast: false
40+
matrix:
41+
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
42+
steps:
43+
- uses: actions/checkout@v4
44+
- uses: ./.github/actions/python-poetry-env
45+
with:
46+
python-version: ${{ matrix.python-version }}
47+
- run: poetry run pytest
48+
49+
docs:
50+
runs-on: ubuntu-latest
51+
steps:
52+
- uses: actions/checkout@v4
53+
- uses: ./.github/actions/python-poetry-env
54+
- run: poetry run mkdocs build

0 commit comments

Comments
 (0)