Skip to content

Commit 86b095b

Browse files
committed
Bring in the goodies from the wolt cookiecutter
1 parent 5fd16ae commit 86b095b

19 files changed

+1651
-353
lines changed

.cruft.json

Lines changed: 18 additions & 0 deletions
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": "b773d08f38d1980e215aeb8dcdcfa7a8af7e1620",
4+
"checkout": null,
5+
"context": {
6+
"cookiecutter": {
7+
"author_name": "Jerry Pussinen",
8+
"author_email": "[email protected]",
9+
"github_username": "jerry-git",
10+
"project_name": "pytest-split",
11+
"project_slug": "pytest-split",
12+
"package_name": "pytest_split",
13+
"project_short_description": "Pytest plugin which splits the test suite to equally sized \"sub suites\" based on test execution time.",
14+
"_template": "https://github.com/woltapp/wolt-python-package-cookiecutter"
15+
}
16+
},
17+
"directory": null
18+
}
Lines changed: 21 additions & 0 deletions
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.9'
9+
outputs: {}
10+
runs:
11+
using: 'composite'
12+
steps:
13+
- uses: actions/setup-python@v2
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/workflows/cookiecutter.yml

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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@v2
12+
- name: Set up Python
13+
uses: actions/setup-python@v2
14+
with:
15+
python-version: 3.9
16+
17+
- name: Set credentials for private templates
18+
run: |
19+
git config --global url."https://api:${{ secrets.AUTO_UPDATE_GITHUB_TOKEN }}@github.com/".insteadOf "https://github.com/"
20+
git config --global url."https://ssh:${{ secrets.AUTO_UPDATE_GITHUB_TOKEN }}@github.com/".insteadOf "ssh://[email protected]/"
21+
git config --global url."https://git:${{ secrets.AUTO_UPDATE_GITHUB_TOKEN }}@github.com/".insteadOf "[email protected]:"
22+
23+
- name: Install dependencies
24+
run: python -m pip install cruft poetry jello tabulate
25+
26+
- name: Update project structure
27+
run: |
28+
cruft update -y
29+
30+
- name: Check if there are changes
31+
id: changes
32+
uses: UnicornGlobal/[email protected]
33+
34+
- name: apply additional changes and fixes
35+
if: steps.changes.outputs.changed == 1
36+
run: |
37+
poetry lock --no-update # add new dependencies
38+
poetry install
39+
poetry run pre-commit run -a || true # we have to fix other issues manually
40+
41+
- name: Get template versions
42+
id: get_versions
43+
if: steps.changes.outputs.changed == 1
44+
run: |
45+
echo ::set-output name=current_version::$(git show HEAD:.cruft.json | jello -r "_['commit'][:8]")
46+
echo ::set-output name=next_version::$(cat .cruft.json | jello -r "_['commit'][:8]")
47+
48+
- name: Get changelog
49+
id: get_changelog
50+
if: steps.changes.outputs.changed == 1
51+
run: |
52+
export TEMPLATE=$(cat .cruft.json | jello -r "_['template']")
53+
git clone $TEMPLATE /tmp/template
54+
cd /tmp/template
55+
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 ';' -)
56+
body=$(cat <<EOF
57+
Changes from $TEMPLATE
58+
59+
$body
60+
EOF
61+
)
62+
body="${body//'%'/'%25'}"
63+
body="${body//$'\n'/'%0A'}"
64+
body="${body//$'\r'/'%0D'}"
65+
echo ::set-output name=changelog::$body
66+
67+
# behaviour if PR already exists: https://github.com/marketplace/actions/create-pull-request#action-behaviour
68+
- name: Create Pull Request
69+
env:
70+
# a PAT is required to be able to update workflows
71+
GITHUB_TOKEN: ${{ secrets.AUTO_UPDATE_GITHUB_TOKEN }}
72+
if: ${{ steps.changes.outputs.changed == 1 && env.GITHUB_TOKEN != 0 }}
73+
uses: peter-evans/create-pull-request@v3
74+
with:
75+
token: ${{ env.GITHUB_TOKEN }}
76+
commit-message: >-
77+
chore: update project structure to ${{ steps.get_versions.outputs.next_version }}
78+
title: "[Actions] Auto-Update cookiecutter template"
79+
body: ${{ steps.get_changelog.outputs.changelog }}
80+
branch: chore/auto-update-project-from-template
81+
delete-branch: true

.github/workflows/dependencies.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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@v2
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+
run: |
27+
body=$(poetry show -o -n | sed 's/(!)//' | awk 'BEGIN {print "Package","Used","Update"}; {print $1,$2,$3}' | tabulate --header --format github -)
28+
body=$(cat <<EOF
29+
The following packages are outdated
30+
31+
$body
32+
EOF
33+
)
34+
body="${body//'%'/'%25'}"
35+
body="${body//$'\n'/'%0A'}"
36+
body="${body//$'\r'/'%0D'}"
37+
echo ::set-output name=body::$body
38+
39+
- name: Update outdated packages
40+
if: ${{ steps.check_for_outdated_dependencies.outputs.body != 0 }}
41+
run: poetry lock
42+
43+
# behaviour if PR already exists: https://github.com/marketplace/actions/create-pull-request#action-behaviour
44+
- name: Create Pull Request
45+
env:
46+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
47+
if: ${{ steps.check_for_outdated_dependencies.outputs.body != 0 }}
48+
uses: peter-evans/create-pull-request@v3
49+
with:
50+
token: ${{ env.GITHUB_TOKEN }}
51+
commit-message: >-
52+
chore: update dependencies
53+
title: "[Actions] Auto-Update dependencies"
54+
body: ${{ steps.get_outdated_dependencies.outputs.body }}
55+
branch: chore/update-dependencies
56+
delete-branch: true

.github/workflows/draft_release.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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@v2
16+
- uses: ./.github/actions/python-poetry-env
17+
- name: Update version
18+
id: updated_version
19+
run: |
20+
poetry version ${{ github.event.inputs.version }}
21+
version=$(poetry version --short)
22+
echo ::set-output name=version::$version
23+
- name: Update changelog
24+
id: changelog
25+
run: |
26+
poetry run kacl-cli release ${{ steps.updated_version.outputs.version }} --modify --auto-link
27+
echo "" >> CHANGELOG.md
28+
body=$(poetry run kacl-cli get ${{ steps.updated_version.outputs.version }})
29+
body="${body//'%'/'%25'}"
30+
body="${body//$'\n'/'%0A'}"
31+
body="${body//$'\r'/'%0D'}"
32+
echo ::set-output name=body::$body
33+
- name: Commit changes
34+
uses: EndBug/add-and-commit@v7
35+
with:
36+
add: 'CHANGELOG.md pyproject.toml'
37+
message: 'Release ${{ steps.updated_version.outputs.version }}'
38+
- name: Create tag
39+
run: |
40+
git tag ${{ steps.updated_version.outputs.version }}
41+
git push origin ${{ steps.updated_version.outputs.version }}
42+
- name: Create a draft release
43+
uses: actions/create-release@v1
44+
env:
45+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
46+
with:
47+
tag_name: ${{ steps.updated_version.outputs.version }}
48+
release_name: Release ${{ steps.updated_version.outputs.version }}
49+
body: ${{ steps.changelog.outputs.body }}
50+
draft: true

.github/workflows/publish.yml

Lines changed: 0 additions & 35 deletions
This file was deleted.

.github/workflows/release.yml

Lines changed: 18 additions & 0 deletions
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@v2
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

Lines changed: 0 additions & 75 deletions
This file was deleted.

0 commit comments

Comments
 (0)