Add release automation
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

Added script which assists in creating an automatic release by
extracting the current version and newest changes from the semantic
changelog.

This is then used in the gitea release preparation as title and
content of the release message.
The files built in the dist directory by poetry will be attached.
This commit is contained in:
Marty Oehme 2022-01-19 15:58:36 +01:00
parent e59b19d6e3
commit 85c69e1096
Signed by: Marty
GPG key ID: B7538B8F50A1C800
3 changed files with 65 additions and 1 deletions

View file

@ -41,6 +41,12 @@ pipeline:
when: when:
branch: main branch: main
release_prep:
image: python
commands:
- echo "----------------- preparing release ------------------"
- python tools/extract-changelog.py
gitea_release: gitea_release:
image: plugins/gitea-release image: plugins/gitea-release
settings: settings:
@ -48,6 +54,8 @@ pipeline:
from_secret: gitea_release_token from_secret: gitea_release_token
base_url: https://git.martyoeh.me base_url: https://git.martyoeh.me
files: dist/* files: dist/*
title: NEWEST_VERSION.md
note: NEWEST_CHANGES.md
when: when:
branch: main branch: main
event: tag event: tag

View file

@ -17,7 +17,7 @@ and this project tries to adhere to [Semantic Versioning](https://semver.org/spe
* Compatible with Python stretching back to version 3.7 * Compatible with Python stretching back to version 3.7
## [0.4] - 2021-12-06 ## [0.4.0] - 2021-12-06
### Added ### Added

View file

@ -0,0 +1,56 @@
import re
## Extracts the version and newest changes from a semantic changelog.
#
# Important, it only works with three-parted version numbers
# a-la 1.2.3 or 313.01.1888 -- needs \d.\d.\d to work.
#
# The version number and changeset will be put in `NEWEST_VERSION.md`
# and `NEWEST_CHANGES.md` respectively, for further use in releases.
OUTPUT_FILE_VERSION = "NEWEST_VERSION.md"
OUTPUT_FILE_CHANGES = "NEWEST_CHANGES.md"
def getVersion(file):
for line in file:
m = re.match(r"^## \[(\d+\.\d+\.\d+)\]", line)
if m and m.group(1):
return m.group(1)
def getSection(file):
inRecordingMode = False
for line in file:
if not inRecordingMode:
if re.match(r"^## \[\d+\.\d+\.\d+\]", line):
inRecordingMode = True
elif re.match(r"^## \[\d+\.\d+\.\d+\]", line):
inRecordingMode = False
break
elif re.match(r"^$", line):
pass
else:
yield line
def toFile(fname, content):
file = open(fname, "w")
file.write(content)
file.close()
with open("CHANGELOG.md") as file:
title = getVersion(file)
print(title)
toFile(OUTPUT_FILE_VERSION, title)
with open("CHANGELOG.md") as file:
newest_changes_gen = getSection(file)
newest_changes = ""
for line in newest_changes_gen:
newest_changes += line
print("[Extracted Changelog]")
print(newest_changes)
toFile(OUTPUT_FILE_CHANGES, newest_changes)
file.close()