Skip to content

Commit 6fc06f6

Browse files
committed
Inital restructure
0 parents  commit 6fc06f6

File tree

26 files changed

+879
-0
lines changed

26 files changed

+879
-0
lines changed

.cruft.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"template": "https://github.com/collijk/python-package-cookiecutter",
3+
"commit": "d86abba2604d3fb06b718d45a83170b6315debde",
4+
"checkout": null,
5+
"context": {
6+
"cookiecutter": {
7+
"author_name": "Bobby Reiner",
8+
"author_email": "bcreiner@uw.edu",
9+
"github_username": "bcreiner",
10+
"project_name": "idd-forecast-mbp",
11+
"project_slug": "idd-forecast-mbp",
12+
"package_name": "idd_forecast_mbp",
13+
"project_short_description": "Word",
14+
"_template": "https://github.com/collijk/python-package-cookiecutter",
15+
"_commit": "d86abba2604d3fb06b718d45a83170b6315debde"
16+
}
17+
},
18+
"directory": null
19+
}
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.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
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Build and Deploy Docs
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
branches:
7+
- main
8+
types:
9+
- closed
10+
11+
jobs:
12+
build-and-deploy-docs:
13+
if: ${{ github.event.pull_request.merged }} or ${{ github.event_name == 'workflow_dispatch' }}
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
with:
18+
token: ${{ secrets.GH_TOKEN }}
19+
- uses: ./.github/actions/python-poetry-env
20+
- name: Deploy docs
21+
run: poetry run mkdocs gh-deploy --force

.github/pull_request_template.md

Lines changed: 10 additions & 0 deletions
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

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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: |
27+
git status --porcelain | wc -l
28+
echo "changed=$(git status --porcelain | wc -l)" >> "$GITHUB_OUTPUT"
29+
30+
31+
- name: apply additional changes and fixes
32+
if: steps.changes.outputs.changed > 0
33+
run: |
34+
poetry lock # add new dependencies
35+
poetry install
36+
poetry run pre-commit run -a || true # we have to fix other issues manually
37+
38+
- name: Get template versions
39+
id: get_versions
40+
if: steps.changes.outputs.changed > 0
41+
shell: bash
42+
run: |
43+
CURRENT_VERSION=$(git show HEAD:.cruft.json | jello -r "_['commit'][:8]")
44+
NEXT_VERSION=$(jello -r "_['commit'][:8]" < .cruft.json)
45+
echo "current_version=$CURRENT_VERSION next_version=$NEXT_VERSION"
46+
echo "current_version=$CURRENT_VERSION" >> "$GITHUB_OUTPUT"
47+
echo "next_version=$NEXT_VERSION" >> "$GITHUB_OUTPUT"
48+
49+
- name: Get changelog
50+
id: get_changelog
51+
if: steps.changes.outputs.changed > 0
52+
shell: bash
53+
run: |
54+
TEMPLATE=$(jello -r "_['template']" < .cruft.json)
55+
git clone "$TEMPLATE" /tmp/template
56+
cd /tmp/template
57+
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 ';' -)
58+
body=$(cat <<EOF
59+
Changes from $TEMPLATE
60+
61+
$body
62+
EOF
63+
)
64+
65+
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
66+
{
67+
echo "changelog<<$EOF"
68+
echo "$body"
69+
echo "$EOF"
70+
} >> "$GITHUB_OUTPUT"
71+
echo "$body"
72+
73+
# behaviour if PR already exists: https://github.com/marketplace/actions/create-pull-request#action-behaviour
74+
- name: Create Pull Request
75+
env:
76+
# a PAT is required to be able to update workflows
77+
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
78+
if: ${{ steps.changes.outputs.changed > 0 && env.GITHUB_TOKEN != 0 }}
79+
uses: peter-evans/create-pull-request@v5
80+
with:
81+
token: ${{ env.GITHUB_TOKEN }}
82+
commit-message: >-
83+
chore: update project structure to ${{ steps.get_versions.outputs.next_version }}
84+
title: "[Actions] Auto-Update cookiecutter template"
85+
body: ${{ steps.get_changelog.outputs.changelog }}
86+
branch: chore/auto-update-project-from-template
87+
delete-branch: true

.github/workflows/dependencies.yml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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+
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
21+
body=$(poetry show -o -n)
22+
23+
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
24+
{
25+
echo "body<<$EOF"
26+
echo "$body"
27+
echo "$EOF"
28+
} >> "$GITHUB_OUTPUT"
29+
echo "$body"
30+
31+
- name: Format PR message
32+
if: ${{ steps.check_for_outdated_dependencies.outputs.body != 0 }}
33+
id: get_outdated_dependencies
34+
shell: bash
35+
run: |
36+
body=$(poetry show -o -n | sed 's/(!)//' | awk 'BEGIN {print "Package","Used","Update"}; {print $1,$2,$3}' | tabulate --header --format github -)
37+
body=$(cat <<EOF
38+
The following packages are outdated
39+
40+
$body
41+
EOF
42+
)
43+
44+
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
45+
{
46+
echo "body<<$EOF"
47+
echo "$body"
48+
echo "$EOF"
49+
} >> "$GITHUB_OUTPUT"
50+
echo "$body"
51+
52+
- name: Update outdated packages
53+
if: ${{ steps.check_for_outdated_dependencies.outputs.body != 0 }}
54+
run: poetry lock --regenerate
55+
56+
# behaviour if PR already exists: https://github.com/marketplace/actions/create-pull-request#action-behaviour
57+
- name: Create Pull Request
58+
env:
59+
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
60+
if: ${{ steps.check_for_outdated_dependencies.outputs.body != 0 && env.GITHUB_TOKEN != 0 }}
61+
uses: peter-evans/create-pull-request@v5
62+
with:
63+
token: ${{ env.GITHUB_TOKEN }}
64+
commit-message: >-
65+
chore: update dependencies
66+
title: "[Actions] Auto-Update dependencies"
67+
body: ${{ steps.get_outdated_dependencies.outputs.body }}
68+
branch: chore/update-dependencies
69+
delete-branch: true
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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+
with:
17+
token: ${{ secrets.GH_TOKEN }}
18+
- uses: ./.github/actions/python-poetry-env
19+
- name: Update version
20+
id: updated_version
21+
shell: bash
22+
run: |
23+
poetry version ${{ github.event.inputs.version }}
24+
version=$(poetry version --short)
25+
echo "version=$version" >> "$GITHUB_OUTPUT"
26+
- name: Update changelog
27+
id: changelog
28+
shell: bash
29+
run: |
30+
poetry run kacl-cli release ${{ steps.updated_version.outputs.version }} --modify --auto-link
31+
body=$(poetry run kacl-cli get ${{ steps.updated_version.outputs.version }})
32+
33+
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
34+
{
35+
echo "body<<$EOF"
36+
echo "$body"
37+
echo "$EOF"
38+
} >> "$GITHUB_OUTPUT"
39+
echo "$body"
40+
- name: Commit changes
41+
uses: EndBug/add-and-commit@v9
42+
with:
43+
add: 'CHANGELOG.md pyproject.toml'
44+
message: 'Release ${{ steps.updated_version.outputs.version }}'
45+
- name: Create tag
46+
run: |
47+
git tag ${{ steps.updated_version.outputs.version }}
48+
git push origin ${{ steps.updated_version.outputs.version }}
49+
- name: Create a draft release
50+
uses: actions/create-release@v1
51+
env:
52+
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
53+
with:
54+
tag_name: ${{ steps.updated_version.outputs.version }}
55+
release_name: Release ${{ steps.updated_version.outputs.version }}
56+
body: ${{ steps.changelog.outputs.body }}
57+
draft: true

.github/workflows/release.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
with:
13+
token: ${{ secrets.GH_TOKEN }}
14+
- uses: ./.github/actions/python-poetry-env
15+
- name: Publish to pypi
16+
run: |
17+
poetry config pypi-token.pypi ${{ secrets.PYPI_TOKEN }}
18+
poetry publish --build --no-interaction
19+
- name: Deploy docs
20+
run: poetry run mkdocs gh-deploy --force

.github/workflows/test.yml

Lines changed: 54 additions & 0 deletions
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.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)