Skip to content

Commit 8e6f7e7

Browse files
authored
Add automated versioning (#5)
1 parent 73b3832 commit 8e6f7e7

22 files changed

+443
-84
lines changed

.github/workflows/release.yml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
name: "Release"
3+
4+
on:
5+
push:
6+
tags:
7+
- 'v2[0-1][0-9][0-9].0[0-9].[0-9][0-9]'
8+
- 'v2[0-1][0-9][0-9].1[0-2].[0-9][0-9]'
9+
10+
jobs:
11+
distribute:
12+
name: Distribute
13+
runs-on: Ubuntu-20.04
14+
steps:
15+
- name: Checkout the repo
16+
uses: actions/checkout@v2
17+
- name: Publish the release to GitHub
18+
uses: actions/create-release@v1
19+
env:
20+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
21+
with:
22+
tag_name: ${{ github.ref }}
23+
release_name: ${{ github.ref }} release
24+
draft: false
25+
prerelease: false

LICENSE

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Copyright (c) 2021-2021, Seiso, LLC - All rights reserved.

Pipfile

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[[source]]
2+
url = "https://pypi.org/simple"
3+
verify_ssl = true
4+
name = "pypi"
5+
6+
[packages]
7+
8+
[dev-packages]
9+
bumpversion = "*"
10+
gitpython = "*"
11+
invoke = "*"

Pipfile.lock

+68
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

+28-7
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,43 @@ cd $(ls -td * | head -1)
1818
grep -r TODO *
1919

2020
# Add your code and tests
21-
...
21+
pipenv install --dev
22+
# ...
2223

23-
# Commit and push your work
24+
# Commit and test your work
2425
git init --initial-branch=main
2526
git add -A
2627
git commit -m "Initial commit"
27-
28-
# Do some final testing
29-
pipenv install --dev
3028
pipenv run invoke test
3129

30+
# Make your first release
31+
git remote add origin git@github.com:SeisoLLC/$(basename $(pwd)).git
32+
git push origin $(git branch --show-current)
33+
34+
###############################
35+
# CalVer
36+
pipenv run invoke release
37+
###############################
38+
# or
39+
###############################
40+
# SemVer
41+
pipenv run invoke release minor
42+
###############################
43+
3244
# Ship it!
33-
git remote add origin git@github.com:SeisoLLC/TODO.git
34-
git push origin main
45+
git push --atomic origin $(git branch --show-current) $(git describe --tags)
46+
47+
# Finally, setup your repo settings (setup a branch policy, enable dependabot, add docker hub secrets, etc...)
48+
```
49+
50+
## Updating the dependencies
51+
```bash
52+
pipenv update
3553
```
3654

3755
## FAQs
3856
Q: Why am I getting `invalid reference format: repository name must be lowercase` when I try to build my docker container?
3957
A: You customized the `project_slug` when answering the `cookiecutter` questions and included a capital letter. Don't do that!
58+
59+
Q: What does `SemVer-ish` mean?
60+
A: Docker isn't compatible with SemVer, as it doesn't allow `+` symbols in their tags (which are used by Semver to indicate builds). As a workaround, we use `-`s instead (only for local builds, not official releases), which is not compliant with the official SemVer spec, but is easily human understandable. In order to keep the docker image tags in line with git tags, both use this SemVer-like notation.

SECURITY.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Reporting Security Issues
2+
Seiso and the cookiecutter-python community take security seriously, and appreciate all efforts that disclose concerns responsibly.
3+
4+
If you believe you've found a security bug in our project, please contact us at [security@SeisoLLC.com](mailto:security@SeisoLLC.com) and include the words "cookiecutter-python vulnerability" in the subject line. If you believe you've found a security bug in a third-party project used by cookiecutter-python, please report it to those those maintainers.
5+
6+
Your email will be acknowledged within one business day, and you'll receive a more detailed response to your email as soon as possible indicating the next steps in handling your report. After the initial reply to your report, we will endeavor to keep you informed of the progress being made towards a fix and announcement.

cookiecutter.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
"project_short_description": "TODO",
55
"project_owner_github_username": "jonzeolla",
66
"dockerhub": "y",
7-
"versioning": ["SemVer", "CalVer"],
7+
"versioning": ["CalVer", "SemVer-ish"],
88
"license": ["MIT", "BSD-3", "Not open source"]
99
}

setup.cfg

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[bumpversion]
2+
current_version = 2021.02.01
3+
parse = (?P<year>2[0-1]\d{2})\.(?P<month>(0\d|1[0-2]))(.(?P<increment>\d{2}))?
4+
serialize = {year}.{month}.{increment}
5+
commit_message = "Automatically generated release {new_version}"
6+
commit = True
7+
tag = True
8+
push = True
9+
10+
[metadata]
11+
author = 'Seiso'
12+
description = 'The Seiso standard python cookiecutter template'
13+
description-file = 'README.md'
14+
license_file = 'LICENSE'
15+
name = 'cookiecutter-python'
16+
url = 'https://github.com/SeisoLLC/cookiecutter-python'
17+
18+
[bumpversion:file:setup.cfg]

tasks.py

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Task execution tool & library
4+
"""
5+
6+
import json
7+
import re
8+
import sys
9+
from datetime import datetime
10+
from logging import basicConfig, getLogger
11+
from pathlib import Path
12+
13+
import git
14+
from bumpversion.cli import main as bumpversion
15+
from invoke import task
16+
17+
LOG_FORMAT = json.dumps(
18+
{
19+
"timestamp": "%(asctime)s",
20+
"namespace": "%(name)s",
21+
"loglevel": "%(levelname)s",
22+
"message": "%(message)s",
23+
}
24+
)
25+
basicConfig(level="INFO", format=LOG_FORMAT)
26+
LOG = getLogger("cookiecutter-python")
27+
28+
CWD = Path(".").absolute()
29+
REPO = git.Repo(CWD)
30+
31+
32+
# Tasks
33+
@task
34+
def test(c): # pylint: disable=unused-argument
35+
"""Test cookiecutter-python"""
36+
LOG.warning("TODO: Implement tests")
37+
38+
39+
@task(pre=[test])
40+
def release(c): # pylint: disable=unused-argument
41+
"""Make a new release of cookiecutter-python"""
42+
if REPO.head.is_detached:
43+
LOG.error("In detached HEAD state, refusing to release")
44+
sys.exit(1)
45+
46+
# Get the current date info
47+
date_info = datetime.now().strftime("%Y.%m")
48+
49+
# Our CalVer pattern which works until year 2200, up to 100 releases a
50+
# month (purposefully excludes builds)
51+
pattern = re.compile(r"v2[0-1][0-9]{2}.(0[0-9]|1[0-2]).[0-9]{2}")
52+
53+
# Identify and set the increment
54+
for tag in reversed(REPO.tags):
55+
if pattern.fullmatch(tag.name):
56+
latest_release = tag.name
57+
break
58+
else:
59+
latest_release = None
60+
61+
if latest_release and date_info == latest_release[:7]:
62+
increment = str(int(latest_release[8:]) + 1).zfill(2)
63+
else:
64+
increment = "01"
65+
66+
new_version = date_info + "." + increment
67+
68+
bumpversion(["--new-version", new_version, "unusedpart"])

{{cookiecutter.project_slug}}/.github/ISSUE_TEMPLATE.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010
## Your environment
1111

1212

13-
## Logs, errors, etc.
13+
## Logs and error messages
1414

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
rules:
3+
# Workaround until replicatedhq/dockerfilelint#169 is resolved
4+
missing_tag: off
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
ignored:
3+
# Workaround: added an environment variable of PIP_NO_CACHE_DIR=1 in the
4+
# Dockerfile
5+
- DL3042
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
---
22
name: "Commit"
3+
34
on:
45
push:
56
branches:
67
- main
8+
79
jobs:
810
test:
9-
name: Test the project
11+
name: Test
1012
runs-on: Ubuntu-20.04
1113
strategy:
1214
matrix:
1315
python-version:
14-
- '3.8'
15-
- '3.9'
16+
- 3.8
17+
- 3.9
1618
steps:
1719
- name: Checkout the repo
1820
uses: actions/checkout@v2
@@ -28,43 +30,34 @@ jobs:
2830
pipenv install --python ${{ "{{ matrix.python-version }}" }} --dev
2931
- name: Run the tests
3032
run: pipenv run invoke test
31-
{% if cookiecutter.dockerhub == 'y' -%}
32-
push:
33-
name: Build and push the Docker images
33+
{%- if cookiecutter.dockerhub == 'y' %}
34+
distribute:
35+
name: Distribute
3436
runs-on: Ubuntu-20.04
35-
strategy:
36-
matrix:
37-
python-version:
38-
- '3.9'
3937
needs: test
4038
steps:
4139
- name: Checkout the repo
4240
uses: actions/checkout@v2
4341
- name: Setup python
4442
uses: actions/setup-python@v2
4543
with:
46-
python-version: ${{ "{{ matrix.python-version }}" }}
44+
python-version: 3.9
4745
- name: Install the dependencies
4846
run: |
4947
python -m pip install --upgrade pipenv
50-
pipenv install --python ${{ "{{ matrix.python-version }}" }} --dev
51-
- name: Build the docker image
52-
run: pipenv run invoke build
48+
pipenv install --dev
5349
- name: Login to Docker Hub
5450
uses: docker/login-action@v1
5551
with:
5652
username: ${{ "{{ secrets.DOCKERHUB_USERNAME }}" }}
5753
password: ${{ "{{ secrets.DOCKERHUB_TOKEN }}" }}
5854
- name: Publish the README
59-
uses: christian-korneck/update-container-description-action@d36005551adeaba9698d8d67a296bd16fa91f8e8
60-
env:
61-
DOCKER_USER: ${{ "{{ secrets.DOCKERHUB_USERNAME }}" }}
62-
DOCKER_PASS: ${{ "{{ secrets.DOCKERHUB_TOKEN }}" }}
55+
uses: peter-evans/dockerhub-description@v2
6356
with:
64-
destination_container_repo: seiso/{{ cookiecutter.project_slug }}
65-
provider: dockerhub
66-
short_description: {{ cookiecutter.project_short_description }}
67-
readme_file: README.md
68-
- name: Publish the latest image
57+
username: ${{ "{{ secrets.DOCKERHUB_USERNAME }}" }}
58+
password: ${{ "{{ secrets.DOCKERHUB_TOKEN }}" }}
59+
repository: seiso/{{ cookiecutter.project_slug }}
60+
short-description: {{ cookiecutter.project_short_description }}
61+
- name: Publish the latest docker image
6962
run: pipenv run invoke publish latest
7063
{%- endif -%}

{{cookiecutter.project_slug}}/.github/workflows/pr.yml

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
---
22
name: "PR"
3+
34
on:
45
pull_request:
56
branches:
67
- main
8+
79
jobs:
810
test:
9-
name: Test the project
11+
name: Test
1012
runs-on: Ubuntu-20.04
1113
strategy:
1214
matrix:
1315
python-version:
14-
- '3.8'
15-
- '3.9'
16+
- 3.8
17+
- 3.9
1618
steps:
1719
- name: Checkout the repo
1820
uses: actions/checkout@v2

0 commit comments

Comments
 (0)