Skip to content

Commit 11ab8ca

Browse files
committed
merge a cruft native template
1 parent 3301fe8 commit 11ab8ca

39 files changed

+1311
-387
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/abhi18av/cookiecutter-abhinav",
3+
"checkout": null,
4+
"context": {
5+
"cookiecutter": {
6+
"author_name": "Your name",
7+
"author_email": "Your email address (eq. you@example.com)",
8+
"github_username": "",
9+
"project_name": "Name of the project (will be shown e.g. as the title in the readme)",
10+
"project_slug": "name-of-the-project-(will-be-shown-e.g.-as-the-title-in-the-readme)",
11+
"package_name": "name_of_the_project_(will_be_shown_e.g._as_the_title_in_the_readme)",
12+
"project_short_description": "A short description of the project",
13+
"_template": "https://github.com/abhi18av/cookiecutter-abhinav",
14+
"_commit": "b25684a2c63387153b83a1cc03ea332be8c8279a"
15+
}
16+
},
17+
"directory": null
18+
}

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @jerry-git
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

.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: 79 additions & 0 deletions
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

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

Lines changed: 11 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,18 @@
1-
name: release
1+
name: Release
22

33
on:
44
release:
5-
types:
6-
- published
5+
types: [ published ]
76

87
jobs:
9-
build:
10-
name: Build and publish new release
11-
runs-on: "ubuntu-latest"
12-
8+
build-and-publish:
9+
runs-on: ubuntu-latest
1310
steps:
14-
- uses: actions/checkout@v3
15-
16-
- name: Set up Python
17-
uses: actions/setup-python@v4
18-
with:
19-
python-version: "3.10"
20-
21-
- name: Install dependencies
22-
run: |
23-
python -m pip install --upgrade pip
24-
pip install -r dev-requirements.txt
25-
26-
- name: Check that versions match
27-
id: version
28-
run: |
29-
echo "Release tag: [${{ github.event.release.tag_name }}]"
30-
PACKAGE_VERSION=$(python -c "import ccds; print(ccds.__version__)")
31-
echo "Package version: [$PACKAGE_VERSION]"
32-
[ ${{ github.event.release.tag_name }} == "v$PACKAGE_VERSION" ] || { exit 1; }
33-
echo "::set-output name=major_minor_version::v${PACKAGE_VERSION%.*}"
34-
35-
- name: Build package
11+
- uses: actions/checkout@v4
12+
- uses: ./.github/actions/python-poetry-env
13+
- name: Publish to pypi
3614
run: |
37-
make dist
38-
39-
- name: Publish to Test PyPI
40-
uses: pypa/gh-action-pypi-publish@v1.3.0
41-
with:
42-
user: ${{ secrets.PYPI_TEST_USERNAME }}
43-
password: ${{ secrets.PYPI_TEST_PASSWORD }}
44-
repository_url: https://test.pypi.org/legacy/
45-
skip_existing: true
46-
47-
- name: Publish to Production PyPI
48-
uses: pypa/gh-action-pypi-publish@v1.3.0
49-
with:
50-
user: ${{ secrets.PYPI_PROD_USERNAME }}
51-
password: ${{ secrets.PYPI_PROD_PASSWORD }}
52-
skip_existing: false
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: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: Sanity checks
2+
3+
on: [push]
4+
5+
jobs:
6+
actionlint:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v4
10+
- name: Download actionlint
11+
run: bash <(curl https://raw.githubusercontent.com/rhysd/actionlint/main/scripts/download-actionlint.bash) 1.6.21
12+
shell: bash
13+
- name: Check workflow files
14+
run: ./actionlint -color
15+
shell: bash
16+
17+
pre-commit:
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- uses: actions/checkout@v4
22+
- uses: actions/setup-python@v5
23+
with:
24+
python-version: "3.12"
25+
- run: python -m pip install pre-commit
26+
- run: pre-commit run --all-files
27+
28+
test:
29+
runs-on: ubuntu-latest
30+
31+
steps:
32+
- uses: actions/checkout@v4
33+
- uses: actions/setup-python@v5
34+
with:
35+
python-version: "3.12"
36+
- run: python -m pip install cookiecutter pytest pyyaml
37+
- run: pytest
38+
39+
lint-generated-project:
40+
runs-on: ubuntu-latest
41+
42+
steps:
43+
- uses: actions/checkout@v4
44+
- uses: actions/setup-python@v5
45+
with:
46+
python-version: "3.12"
47+
- run: python -m pip install cookiecutter poetry
48+
- run: bash <(curl https://raw.githubusercontent.com/rhysd/actionlint/main/scripts/download-actionlint.bash) 1.6.21
49+
- name: Generate project
50+
run: |
51+
cookiecutter --config-file tests/context.yaml --no-input .
52+
cd example-project/
53+
# actionlint needs a git repo in place
54+
git init
55+
git config user.email "gha@users.noreply.github.com"
56+
git config user.name "gha"
57+
git add .
58+
git commit -m "initial commit"
59+
- name: Lint workflows
60+
run: |
61+
cd example-project
62+
../actionlint -color
63+
- name: Lint project
64+
run: |
65+
cd example-project
66+
poetry install
67+
poetry run pre-commit run -a
68+
poetry run mkdocs build

0 commit comments

Comments
 (0)