Compare commits
2 commits
1f2ae28cf0
...
81c05a244e
Author | SHA1 | Date | |
---|---|---|---|
81c05a244e | |||
cab1379b22 |
8 changed files with 356 additions and 295 deletions
81
.forgejo/workflows/release.yaml
Normal file
81
.forgejo/workflows/release.yaml
Normal file
|
@ -0,0 +1,81 @@
|
||||||
|
---
|
||||||
|
name: Build and publish Debian package
|
||||||
|
on: [create]
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: docker
|
||||||
|
container:
|
||||||
|
image: docker.io/brenard/debian-python-deb:latest
|
||||||
|
steps:
|
||||||
|
- name: Check out repository code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
- name: Build Debian package
|
||||||
|
env:
|
||||||
|
MAINTAINER_NAME: ${{ vars.MAINTAINER_NAME }}
|
||||||
|
MAINTAINER_EMAIL: ${{ vars.MAINTAINER_EMAIL }}
|
||||||
|
DEBIAN_CODENAME: ${{ vars.DEBIAN_CODENAME }}
|
||||||
|
run: |
|
||||||
|
echo "${{ secrets.GPG_KEY }}"|base64 -d|gpg --import
|
||||||
|
./build.sh
|
||||||
|
rm -fr dist/gitdch-*
|
||||||
|
mv gitdch dist/
|
||||||
|
- name: Upload Debian package files
|
||||||
|
uses: actions/upload-artifact@v3
|
||||||
|
with:
|
||||||
|
name: dist
|
||||||
|
path: |
|
||||||
|
dist
|
||||||
|
|
||||||
|
publish-forgejo:
|
||||||
|
runs-on: docker
|
||||||
|
container:
|
||||||
|
image: docker.io/brenard/debian-python-deb:latest
|
||||||
|
steps:
|
||||||
|
- name: Download Debian package files
|
||||||
|
uses: actions/download-artifact@v3
|
||||||
|
with:
|
||||||
|
name: dist
|
||||||
|
|
||||||
|
- name: Create the release
|
||||||
|
id: create-release
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
mkdir release
|
||||||
|
mv *.deb release/
|
||||||
|
mv gitdch release/
|
||||||
|
{
|
||||||
|
echo 'release_note<<EOF'
|
||||||
|
cat release_notes.md
|
||||||
|
echo 'EOF'
|
||||||
|
} >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
|
- name: Publish release on Forgejo
|
||||||
|
uses: actions/forgejo-release@v1
|
||||||
|
with:
|
||||||
|
direction: upload
|
||||||
|
url: https://gitea.zionetrix.net
|
||||||
|
token: ${{ secrets.forgejo_token }}
|
||||||
|
release-dir: release
|
||||||
|
release-notes: ${{ steps.create-release.outputs.release_note }}
|
||||||
|
|
||||||
|
publish-aptly:
|
||||||
|
runs-on: docker
|
||||||
|
container:
|
||||||
|
image: docker.io/brenard/aptly-publish:latest
|
||||||
|
steps:
|
||||||
|
- name: "Download Debian package files"
|
||||||
|
uses: actions/download-artifact@v3
|
||||||
|
with:
|
||||||
|
name: dist
|
||||||
|
|
||||||
|
- name: "Publish Debian package on Aptly repository"
|
||||||
|
uses: https://gitea.zionetrix.net/bn8/aptly-publish@master
|
||||||
|
with:
|
||||||
|
api_url: ${{ vars.apt_api_url }}
|
||||||
|
api_username: ${{ vars.apt_api_username }}
|
||||||
|
api_password: ${{ secrets.apt_api_password }}
|
||||||
|
repo_name: ${{ vars.apt_repo_name }}
|
||||||
|
path: "./"
|
||||||
|
source_name: ${{ vars.apt_source_name }}
|
21
.forgejo/workflows/tests.yaml
Normal file
21
.forgejo/workflows/tests.yaml
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
---
|
||||||
|
name: Run tests
|
||||||
|
on: [push]
|
||||||
|
jobs:
|
||||||
|
test-precommit:
|
||||||
|
runs-on: docker
|
||||||
|
container:
|
||||||
|
image: docker.io/brenard/python-pre-commit:latest
|
||||||
|
steps:
|
||||||
|
- name: Check out repository code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
- name: Install python dependencies
|
||||||
|
env:
|
||||||
|
DEBIAN_FRONTEND: noninteractive
|
||||||
|
run: |
|
||||||
|
apt-get update
|
||||||
|
apt-get -y install --no-install-recommends python3-git git
|
||||||
|
- name: Run pre-commit
|
||||||
|
run: pre-commit run --all-files
|
64
.pre-commit-config.yaml
Normal file
64
.pre-commit-config.yaml
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
# Pre-commit hooks to run tests and ensure code is cleaned.
|
||||||
|
# See https://pre-commit.com for more information
|
||||||
|
---
|
||||||
|
repos:
|
||||||
|
- repo: https://github.com/astral-sh/ruff-pre-commit
|
||||||
|
rev: v0.1.6
|
||||||
|
hooks:
|
||||||
|
- id: ruff
|
||||||
|
args: ["--fix"]
|
||||||
|
- repo: https://github.com/asottile/pyupgrade
|
||||||
|
rev: v3.15.0
|
||||||
|
hooks:
|
||||||
|
- id: pyupgrade
|
||||||
|
args: ["--keep-percent-format", "--py37-plus"]
|
||||||
|
- repo: https://github.com/psf/black
|
||||||
|
rev: 23.11.0
|
||||||
|
hooks:
|
||||||
|
- id: black
|
||||||
|
args: ["--target-version", "py37", "--line-length", "100"]
|
||||||
|
- repo: https://github.com/PyCQA/isort
|
||||||
|
rev: 5.12.0
|
||||||
|
hooks:
|
||||||
|
- id: isort
|
||||||
|
args: ["--profile", "black", "--line-length", "100"]
|
||||||
|
- repo: https://github.com/PyCQA/flake8
|
||||||
|
rev: 6.1.0
|
||||||
|
hooks:
|
||||||
|
- id: flake8
|
||||||
|
args: ["--max-line-length=100"]
|
||||||
|
- repo: https://github.com/codespell-project/codespell
|
||||||
|
rev: v2.2.2
|
||||||
|
hooks:
|
||||||
|
- id: codespell
|
||||||
|
args:
|
||||||
|
- --ignore-words-list=exten
|
||||||
|
- --skip="./.*,*.csv,*.json,*.ini,*.subject,*.txt,*.html,*.log,*.conf"
|
||||||
|
- --quiet-level=2
|
||||||
|
- --ignore-regex=.*codespell-ignore$
|
||||||
|
# - --write-changes # Uncomment to write changes
|
||||||
|
exclude_types: [csv, json]
|
||||||
|
- repo: https://github.com/adrienverge/yamllint
|
||||||
|
rev: v1.32.0
|
||||||
|
hooks:
|
||||||
|
- id: yamllint
|
||||||
|
ignore: .github/
|
||||||
|
- repo: https://github.com/pre-commit/mirrors-prettier
|
||||||
|
rev: v2.7.1
|
||||||
|
hooks:
|
||||||
|
- id: prettier
|
||||||
|
args: ["--print-width", "100"]
|
||||||
|
- repo: local
|
||||||
|
hooks:
|
||||||
|
- id: pylint
|
||||||
|
name: pylint
|
||||||
|
entry: pylint
|
||||||
|
language: system
|
||||||
|
types: [python]
|
||||||
|
require_serial: true
|
||||||
|
- repo: https://github.com/PyCQA/bandit
|
||||||
|
rev: 1.7.5
|
||||||
|
hooks:
|
||||||
|
- id: bandit
|
||||||
|
args: [--skip, "B101", --recursive]
|
||||||
|
minimum_pre_commit_version: 3.2.0
|
|
@ -1,70 +0,0 @@
|
||||||
clone:
|
|
||||||
git:
|
|
||||||
image: woodpeckerci/plugin-git
|
|
||||||
tags: true
|
|
||||||
|
|
||||||
pipeline:
|
|
||||||
test-pylint:
|
|
||||||
group: test
|
|
||||||
image: pipelinecomponents/pylint
|
|
||||||
commands:
|
|
||||||
- pip install GitPython --quiet
|
|
||||||
- pylint gitdch
|
|
||||||
|
|
||||||
test-flake8:
|
|
||||||
group: test
|
|
||||||
image: pipelinecomponents/flake8
|
|
||||||
commands:
|
|
||||||
- flake8 gitdch
|
|
||||||
|
|
||||||
build:
|
|
||||||
image: brenard/debian-python-deb
|
|
||||||
when:
|
|
||||||
event: tag
|
|
||||||
commands:
|
|
||||||
- echo "$GPG_KEY"|base64 -d|gpg --import
|
|
||||||
- ./build.sh --quiet
|
|
||||||
- rm -fr dist/gitdch-*
|
|
||||||
secrets: [ maintainer_name, maintainer_email, gpg_key, debian_codename ]
|
|
||||||
|
|
||||||
publish-dryrun:
|
|
||||||
group: publish
|
|
||||||
image: alpine
|
|
||||||
when:
|
|
||||||
event: tag
|
|
||||||
commands:
|
|
||||||
- ls dist/*
|
|
||||||
|
|
||||||
publish-gitea:
|
|
||||||
group: publish
|
|
||||||
image: plugins/gitea-release
|
|
||||||
when:
|
|
||||||
event: tag
|
|
||||||
settings:
|
|
||||||
api_key:
|
|
||||||
from_secret: gitea_token
|
|
||||||
base_url: https://gitea.zionetrix.net
|
|
||||||
note: dist/release_notes.md
|
|
||||||
files:
|
|
||||||
- gitdch
|
|
||||||
- dist/*.deb
|
|
||||||
checksum:
|
|
||||||
- md5
|
|
||||||
- sha512
|
|
||||||
|
|
||||||
publish-apt:
|
|
||||||
group: publish
|
|
||||||
image: brenard/aptly-publish
|
|
||||||
when:
|
|
||||||
event: tag
|
|
||||||
settings:
|
|
||||||
api_url:
|
|
||||||
from_secret: apt_api_url
|
|
||||||
api_username:
|
|
||||||
from_secret: apt_api_username
|
|
||||||
api_password:
|
|
||||||
from_secret: apt_api_password
|
|
||||||
repo_name:
|
|
||||||
from_secret: apt_repo_name
|
|
||||||
path: dist
|
|
||||||
source_name: gitdch
|
|
7
.yamllint.yml
Normal file
7
.yamllint.yml
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
---
|
||||||
|
extends: default
|
||||||
|
|
||||||
|
rules:
|
||||||
|
line-length:
|
||||||
|
max: 100
|
||||||
|
level: warning
|
10
README.md
10
README.md
|
@ -8,29 +8,34 @@ numbered using ''git describe --always --tags'' command.
|
||||||
# Installation
|
# Installation
|
||||||
|
|
||||||
## Dependencies
|
## Dependencies
|
||||||
|
|
||||||
```
|
```
|
||||||
apt install git python3-git
|
apt install git python3-git
|
||||||
```
|
```
|
||||||
|
|
||||||
## Using git
|
## Using git
|
||||||
|
|
||||||
```
|
```
|
||||||
git clone https://gogs.zionetrix.net/bn8/gitdch.git /usr/local/src/gitdch
|
git clone https://gogs.zionetrix.net/bn8/gitdch.git /usr/local/src/gitdch
|
||||||
ln -s /usr/local/src/gitdch/gitdch /usr/local/bin/gitdch
|
ln -s /usr/local/src/gitdch/gitdch /usr/local/bin/gitdch
|
||||||
```
|
```
|
||||||
|
|
||||||
## Using wget
|
## Using wget
|
||||||
|
|
||||||
```
|
```
|
||||||
wget -O /usr/local/bin/gitdch https://gogs.zionetrix.net/bn8/gitdch/raw/master/gitdch
|
wget -O /usr/local/bin/gitdch https://gogs.zionetrix.net/bn8/gitdch/raw/master/gitdch
|
||||||
chmod +x /usr/local/bin/gitdch
|
chmod +x /usr/local/bin/gitdch
|
||||||
```
|
```
|
||||||
|
|
||||||
## Using curl
|
## Using curl
|
||||||
|
|
||||||
```
|
```
|
||||||
curl -o /usr/local/bin/gitdch https://gogs.zionetrix.net/bn8/gitdch/raw/master/gitdch
|
curl -o /usr/local/bin/gitdch https://gogs.zionetrix.net/bn8/gitdch/raw/master/gitdch
|
||||||
chmod +x /usr/local/bin/gitdch
|
chmod +x /usr/local/bin/gitdch
|
||||||
```
|
```
|
||||||
|
|
||||||
# Usage
|
# Usage
|
||||||
|
|
||||||
```
|
```
|
||||||
usage: gitdch [-h] [-d] [-v] [-w] [-l LOGFILE] [-q] [-p GIT_PATH] [-o OUTPUT] [-A]
|
usage: gitdch [-h] [-d] [-v] [-w] [-l LOGFILE] [-q] [-p GIT_PATH] [-o OUTPUT] [-A]
|
||||||
[-n PACKAGE_NAME] [-V VERSION] [--version-suffix VERSION_SUFFIX]
|
[-n PACKAGE_NAME] [-V VERSION] [--version-suffix VERSION_SUFFIX]
|
||||||
|
@ -54,12 +59,12 @@ optional arguments:
|
||||||
-o OUTPUT, --output OUTPUT
|
-o OUTPUT, --output OUTPUT
|
||||||
Generated Debian changelog output path (default: stdout)
|
Generated Debian changelog output path (default: stdout)
|
||||||
-A, --append Append mode: if the output changelog file already exists,
|
-A, --append Append mode: if the output changelog file already exists,
|
||||||
append generated changelog lines at the begining of the file
|
append generated changelog lines at the beginning of the file
|
||||||
(optional, default: overwriting the file)
|
(optional, default: overwriting the file)
|
||||||
-n PACKAGE_NAME, --package-name PACKAGE_NAME
|
-n PACKAGE_NAME, --package-name PACKAGE_NAME
|
||||||
Package name
|
Package name
|
||||||
-V VERSION, --version VERSION
|
-V VERSION, --version VERSION
|
||||||
Currrent version (default: autodetected using git describe
|
Current version (default: autodetected using git describe
|
||||||
--always --tags)
|
--always --tags)
|
||||||
--version-suffix VERSION_SUFFIX
|
--version-suffix VERSION_SUFFIX
|
||||||
Suffix for autodetected version
|
Suffix for autodetected version
|
||||||
|
@ -100,4 +105,3 @@ This program is free software; you can redistribute it and/or modify it under th
|
||||||
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
|
2
build.sh
2
build.sh
|
@ -24,7 +24,7 @@ sed -i "s/^VERSION *=.*$/VERSION = '$VERSION'/" $BDIR/gitdch
|
||||||
|
|
||||||
if [ -z "$DEBIAN_CODENAME" ]
|
if [ -z "$DEBIAN_CODENAME" ]
|
||||||
then
|
then
|
||||||
echo "Retreive debian codename using lsb_release..."
|
echo "Retrieve debian codename using lsb_release..."
|
||||||
DEBIAN_CODENAME=$( lsb_release -c -s )
|
DEBIAN_CODENAME=$( lsb_release -c -s )
|
||||||
else
|
else
|
||||||
echo "Use debian codename from environment ($DEBIAN_CODENAME)"
|
echo "Use debian codename from environment ($DEBIAN_CODENAME)"
|
||||||
|
|
396
gitdch
396
gitdch
|
@ -12,196 +12,166 @@ import textwrap
|
||||||
import git
|
import git
|
||||||
from git.exc import GitCommandError
|
from git.exc import GitCommandError
|
||||||
|
|
||||||
VERSION = '0.0'
|
VERSION = "0.0"
|
||||||
DEFAULT_GIT_PATCH = './'
|
DEFAULT_GIT_PATCH = "./"
|
||||||
DEFAULT_CODE_NAME = 'unstable'
|
DEFAULT_CODE_NAME = "unstable"
|
||||||
DEFAULT_URGENCY = 'medium'
|
DEFAULT_URGENCY = "medium"
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(description=f"{__doc__} (version: {VERSION})")
|
||||||
description='{0} (version: {1})'.format(__doc__, VERSION)
|
|
||||||
|
parser.add_argument("-d", "--debug", action="store_true", help="Show debug messages")
|
||||||
|
|
||||||
|
parser.add_argument("-v", "--verbose", action="store_true", help="Show verbose messages")
|
||||||
|
|
||||||
|
parser.add_argument("-w", "--warning", action="store_true", help="Show warning messages")
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
"-l", "--log-file", action="store", type=str, dest="logfile", help="Log file path"
|
||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-d', '--debug',
|
"-q",
|
||||||
action='store_true',
|
"--quiet",
|
||||||
help='Show debug messages'
|
action="store_true",
|
||||||
|
help="Quiet mode: do not log on console (only if log file is provided)",
|
||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-v', '--verbose',
|
"-p",
|
||||||
action='store_true',
|
"--path",
|
||||||
help='Show verbose messages'
|
|
||||||
)
|
|
||||||
|
|
||||||
parser.add_argument(
|
|
||||||
'-w', '--warning',
|
|
||||||
action='store_true',
|
|
||||||
help='Show warning messages'
|
|
||||||
)
|
|
||||||
|
|
||||||
parser.add_argument(
|
|
||||||
'-l',
|
|
||||||
'--log-file',
|
|
||||||
action="store",
|
|
||||||
type=str,
|
type=str,
|
||||||
dest="logfile",
|
dest="git_path",
|
||||||
help="Log file path"
|
help="Git repository path (default: %s)" % DEFAULT_GIT_PATCH,
|
||||||
|
default=DEFAULT_GIT_PATCH,
|
||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-q', '--quiet',
|
"-o",
|
||||||
action='store_true',
|
"--output",
|
||||||
help='Quiet mode: do not log on console (only if log file is provided)'
|
|
||||||
)
|
|
||||||
|
|
||||||
parser.add_argument(
|
|
||||||
'-p',
|
|
||||||
'--path',
|
|
||||||
type=str,
|
type=str,
|
||||||
dest='git_path',
|
dest="output",
|
||||||
help='Git repository path (default: %s)' % DEFAULT_GIT_PATCH,
|
help="Generated Debian changelog output path (default: stdout)",
|
||||||
default=DEFAULT_GIT_PATCH
|
|
||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-o',
|
"-A",
|
||||||
'--output',
|
"--append",
|
||||||
type=str,
|
action="store_true",
|
||||||
dest='output',
|
dest="append",
|
||||||
help='Generated Debian changelog output path (default: stdout)',
|
|
||||||
)
|
|
||||||
|
|
||||||
parser.add_argument(
|
|
||||||
'-A',
|
|
||||||
'--append',
|
|
||||||
action='store_true',
|
|
||||||
dest='append',
|
|
||||||
help=(
|
help=(
|
||||||
'Append mode: if the output changelog file already exists, append '
|
"Append mode: if the output changelog file already exists, append "
|
||||||
'generated changelog lines at the begining of the file (optional, '
|
"generated changelog lines at the beginning of the file (optional, "
|
||||||
'default: overwriting the file)'
|
"default: overwriting the file)"
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
parser.add_argument(
|
|
||||||
'-n',
|
|
||||||
'--package-name',
|
|
||||||
type=str,
|
|
||||||
dest='package_name',
|
|
||||||
help='Package name'
|
|
||||||
)
|
|
||||||
|
|
||||||
parser.add_argument(
|
|
||||||
'-V',
|
|
||||||
'--version',
|
|
||||||
type=str,
|
|
||||||
dest='version',
|
|
||||||
help=(
|
|
||||||
'Currrent version (default: autodetected using git describe '
|
|
||||||
'--always --tags)')
|
|
||||||
)
|
|
||||||
|
|
||||||
parser.add_argument(
|
|
||||||
'--version-suffix',
|
|
||||||
type=str,
|
|
||||||
dest='version_suffix',
|
|
||||||
help='Suffix for autodetected version'
|
|
||||||
)
|
|
||||||
|
|
||||||
parser.add_argument(
|
|
||||||
'-c',
|
|
||||||
'--code-name',
|
|
||||||
type=str,
|
|
||||||
dest='code_name',
|
|
||||||
help='Debian code name (default: %s)' % DEFAULT_CODE_NAME,
|
|
||||||
default=DEFAULT_CODE_NAME
|
|
||||||
)
|
|
||||||
|
|
||||||
parser.add_argument(
|
|
||||||
'-u',
|
|
||||||
'--urgency',
|
|
||||||
type=str,
|
|
||||||
dest='urgency',
|
|
||||||
help='Package urgency (default: %s)' % DEFAULT_URGENCY,
|
|
||||||
default=DEFAULT_URGENCY
|
|
||||||
)
|
|
||||||
|
|
||||||
parser.add_argument(
|
|
||||||
'-N',
|
|
||||||
'--maintainer-name',
|
|
||||||
type=str,
|
|
||||||
dest='maintainer_name',
|
|
||||||
help='Maintainer name (default: last commit author name)'
|
|
||||||
)
|
|
||||||
|
|
||||||
parser.add_argument(
|
|
||||||
'-E',
|
|
||||||
'--maintainer-email',
|
|
||||||
type=str,
|
|
||||||
dest='maintainer_email',
|
|
||||||
help='Maintainer email (default: last commit author email)'
|
|
||||||
)
|
|
||||||
|
|
||||||
parser.add_argument(
|
|
||||||
'-R',
|
|
||||||
'--release-notes',
|
|
||||||
type=str,
|
|
||||||
dest='release_notes',
|
|
||||||
help='Specify an optional Markdown release notes output path'
|
|
||||||
)
|
|
||||||
|
|
||||||
parser.add_argument(
|
|
||||||
'--revision',
|
|
||||||
type=str,
|
|
||||||
dest='revision',
|
|
||||||
help=(
|
|
||||||
'Specify the revision to use to generate the changelog (see '
|
|
||||||
'git-rev-parse for viable options, optional, default: generate the '
|
|
||||||
'changelog with all commits of the current branch) '
|
|
||||||
),
|
),
|
||||||
default=None
|
)
|
||||||
|
|
||||||
|
parser.add_argument("-n", "--package-name", type=str, dest="package_name", help="Package name")
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
"-V",
|
||||||
|
"--version",
|
||||||
|
type=str,
|
||||||
|
dest="version",
|
||||||
|
help=("Current version (default: autodetected using git describe " "--always --tags)"),
|
||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-C', '--clean-tags-regex',
|
"--version-suffix", type=str, dest="version_suffix", help="Suffix for autodetected version"
|
||||||
action='append',
|
)
|
||||||
type=re.compile,
|
|
||||||
dest='clean_tags_regex',
|
parser.add_argument(
|
||||||
|
"-c",
|
||||||
|
"--code-name",
|
||||||
|
type=str,
|
||||||
|
dest="code_name",
|
||||||
|
help="Debian code name (default: %s)" % DEFAULT_CODE_NAME,
|
||||||
|
default=DEFAULT_CODE_NAME,
|
||||||
|
)
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
"-u",
|
||||||
|
"--urgency",
|
||||||
|
type=str,
|
||||||
|
dest="urgency",
|
||||||
|
help="Package urgency (default: %s)" % DEFAULT_URGENCY,
|
||||||
|
default=DEFAULT_URGENCY,
|
||||||
|
)
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
"-N",
|
||||||
|
"--maintainer-name",
|
||||||
|
type=str,
|
||||||
|
dest="maintainer_name",
|
||||||
|
help="Maintainer name (default: last commit author name)",
|
||||||
|
)
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
"-E",
|
||||||
|
"--maintainer-email",
|
||||||
|
type=str,
|
||||||
|
dest="maintainer_email",
|
||||||
|
help="Maintainer email (default: last commit author email)",
|
||||||
|
)
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
"-R",
|
||||||
|
"--release-notes",
|
||||||
|
type=str,
|
||||||
|
dest="release_notes",
|
||||||
|
help="Specify an optional Markdown release notes output path",
|
||||||
|
)
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
"--revision",
|
||||||
|
type=str,
|
||||||
|
dest="revision",
|
||||||
help=(
|
help=(
|
||||||
'Clean tags regex: you could specify regex to clean tag names when '
|
"Specify the revision to use to generate the changelog (see "
|
||||||
|
"git-rev-parse for viable options, optional, default: generate the "
|
||||||
|
"changelog with all commits of the current branch) "
|
||||||
|
),
|
||||||
|
default=None,
|
||||||
|
)
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
"-C",
|
||||||
|
"--clean-tags-regex",
|
||||||
|
action="append",
|
||||||
|
type=re.compile,
|
||||||
|
dest="clean_tags_regex",
|
||||||
|
help=(
|
||||||
|
"Clean tags regex: you could specify regex to clean tag names when "
|
||||||
'computing package versions. For instance, to drop a "-eeXXX" suffix '
|
'computing package versions. For instance, to drop a "-eeXXX" suffix '
|
||||||
'of tag names, specify -C "\\-ee[0-9]{3}$" (optional, multiple regex '
|
'of tag names, specify -C "\\-ee[0-9]{3}$" (optional, multiple regex '
|
||||||
'allowed)'
|
"allowed)"
|
||||||
),
|
),
|
||||||
default=[]
|
default=[],
|
||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-x', '--exclude',
|
"-x",
|
||||||
action='append',
|
"--exclude",
|
||||||
|
action="append",
|
||||||
type=re.compile,
|
type=re.compile,
|
||||||
dest='exclude',
|
dest="exclude",
|
||||||
help=(
|
help=(
|
||||||
'Commit exclusion regex: you could specify regex to exclude some '
|
"Commit exclusion regex: you could specify regex to exclude some "
|
||||||
'commits from generated changelog entries. For instance, to exclude '
|
"commits from generated changelog entries. For instance, to exclude "
|
||||||
'commits with message starting with "CI: ", specify -x "^CI: " '
|
'commits with message starting with "CI: ", specify -x "^CI: " '
|
||||||
'(optional, multiple regex allowed)'
|
"(optional, multiple regex allowed)"
|
||||||
),
|
),
|
||||||
default=[]
|
default=[],
|
||||||
)
|
)
|
||||||
|
|
||||||
options = parser.parse_args()
|
options = parser.parse_args()
|
||||||
|
|
||||||
if not options.package_name:
|
if not options.package_name:
|
||||||
parser.error(
|
parser.error("You must provide package name using -n/--package-name parameter")
|
||||||
'You must provide package name using -n/--package-name parameter')
|
|
||||||
|
|
||||||
# Initialize log
|
# Initialize log
|
||||||
log = logging.getLogger()
|
log = logging.getLogger()
|
||||||
logformat = logging.Formatter(
|
logformat = logging.Formatter(
|
||||||
'%(asctime)s - {} - %(levelname)s : %(message)s'.format(
|
f"%(asctime)s - {os.path.basename(sys.argv[0])} - %(levelname)s : %(message)s"
|
||||||
os.path.basename(sys.argv[0])
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
# Set root logger to DEBUG (filtering done by handlers)
|
# Set root logger to DEBUG (filtering done by handlers)
|
||||||
log.setLevel(logging.DEBUG)
|
log.setLevel(logging.DEBUG)
|
||||||
|
@ -230,68 +200,63 @@ repo = git.Repo(options.git_path)
|
||||||
|
|
||||||
|
|
||||||
def clean_deb_version(version_name):
|
def clean_deb_version(version_name):
|
||||||
""" Clean debian version name """
|
"""Clean debian version name"""
|
||||||
version_name = re.sub('^[^0-9]*', '', version_name)
|
version_name = re.sub("^[^0-9]*", "", version_name)
|
||||||
for clean_regex in options.clean_tags_regex:
|
for clean_regex in options.clean_tags_regex:
|
||||||
version_name = clean_regex.sub('', version_name)
|
version_name = clean_regex.sub("", version_name)
|
||||||
if options.version_suffix:
|
if options.version_suffix:
|
||||||
version_name += options.version_suffix
|
version_name += options.version_suffix
|
||||||
return version_name
|
return version_name
|
||||||
|
|
||||||
|
|
||||||
if not options.version:
|
if not options.version:
|
||||||
log.info('Detect current version from git tags & commits')
|
log.info("Detect current version from git tags & commits")
|
||||||
options.version = clean_deb_version(
|
options.version = clean_deb_version(repo.git.describe("--always", "--tags"))
|
||||||
repo.git.describe('--always', '--tags')
|
log.info("Current version detected: %s", options.version)
|
||||||
)
|
|
||||||
log.info('Currrent version detected: %s', options.version)
|
|
||||||
|
|
||||||
if options.output and options.append and not options.revision:
|
if options.output and options.append and not options.revision:
|
||||||
log.info(
|
log.info(
|
||||||
'Append mode enabled but no revision specify, try to detect it from '
|
"Append mode enabled but no revision specify, try to detect it from "
|
||||||
'last modification of the changelog file')
|
"last modification of the changelog file"
|
||||||
|
)
|
||||||
try:
|
try:
|
||||||
last_change_commit = next(repo.iter_commits(paths=options.output))
|
last_change_commit = next(repo.iter_commits(paths=options.output))
|
||||||
# pylint: disable=consider-using-f-string
|
# pylint: disable=consider-using-f-string
|
||||||
options.revision = '{0}..HEAD'.format(last_change_commit)
|
options.revision = f"{last_change_commit}..HEAD"
|
||||||
log.info(
|
log.info(
|
||||||
'Last change commit of the output file is "%s": use revision "%s"',
|
'Last change commit of the output file is "%s": use revision "%s"',
|
||||||
last_change_commit, options.revision)
|
last_change_commit,
|
||||||
|
options.revision,
|
||||||
|
)
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
log.warning(
|
log.warning(
|
||||||
'Fail to auto-detect last change commit of changelog file: it '
|
"Fail to auto-detect last change commit of changelog file: it "
|
||||||
'seem not tracked. Continue without revision.')
|
"seem not tracked. Continue without revision."
|
||||||
|
)
|
||||||
except GitCommandError:
|
except GitCommandError:
|
||||||
log.warning(
|
log.warning(
|
||||||
"Fail to auto-detect last change commit of changelog file. May "
|
"Fail to auto-detect last change commit of changelog file. May "
|
||||||
"be it's outside of the git repository. Continue without "
|
"be it's outside of the git repository. Continue without "
|
||||||
"revision.")
|
"revision."
|
||||||
|
)
|
||||||
# Reset repo object of to avoid BrokenPipeError
|
# Reset repo object of to avoid BrokenPipeError
|
||||||
repo = git.Repo(options.git_path)
|
repo = git.Repo(options.git_path)
|
||||||
|
|
||||||
log.info('Generate changelog from git commits')
|
log.info("Generate changelog from git commits")
|
||||||
|
|
||||||
versions = []
|
versions = []
|
||||||
tag_commits = dict(
|
tag_commits = {tag.commit.binsha: tag for tag in repo.tags}
|
||||||
(tag.commit.binsha, tag)
|
|
||||||
for tag in repo.tags
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def add_version():
|
def add_version():
|
||||||
""" Add version info """
|
"""Add version info"""
|
||||||
global messages # pylint: disable=global-statement
|
global messages # pylint: disable=global-statement
|
||||||
if not version_commit:
|
if not version_commit:
|
||||||
return
|
return
|
||||||
if not messages:
|
if not messages:
|
||||||
messages = ['Release version {0}'.format(version)]
|
messages = [f"Release version {version}"]
|
||||||
log.info('Add version %s:\n - %s', version, '\n - '.join(messages))
|
log.info("Add version %s:\n - %s", version, "\n - ".join(messages))
|
||||||
versions.append({
|
versions.append({"name": version, "tag": tag, "commit": version_commit, "messages": messages})
|
||||||
'name': version,
|
|
||||||
'tag': tag,
|
|
||||||
'commit': version_commit,
|
|
||||||
'messages': messages
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
tag = None
|
tag = None
|
||||||
|
@ -299,10 +264,10 @@ version_commit = None
|
||||||
version = options.version
|
version = options.version
|
||||||
messages = []
|
messages = []
|
||||||
for commit in repo.iter_commits(rev=options.revision):
|
for commit in repo.iter_commits(rev=options.revision):
|
||||||
log.debug('Commit %s (%s)', commit, commit.summary)
|
log.debug("Commit %s (%s)", commit, commit.summary)
|
||||||
if commit.binsha in tag_commits:
|
if commit.binsha in tag_commits:
|
||||||
new_tag = tag_commits[commit.binsha]
|
new_tag = tag_commits[commit.binsha]
|
||||||
log.debug('Reach new tag %s', new_tag)
|
log.debug("Reach new tag %s", new_tag)
|
||||||
|
|
||||||
add_version()
|
add_version()
|
||||||
|
|
||||||
|
@ -310,7 +275,7 @@ for commit in repo.iter_commits(rev=options.revision):
|
||||||
version = clean_deb_version(tag.name)
|
version = clean_deb_version(tag.name)
|
||||||
version_commit = commit
|
version_commit = commit
|
||||||
messages = []
|
messages = []
|
||||||
log.debug('Iter commits for version %s', version)
|
log.debug("Iter commits for version %s", version)
|
||||||
if version_commit is None:
|
if version_commit is None:
|
||||||
version_commit = commit
|
version_commit = commit
|
||||||
excluded = False
|
excluded = False
|
||||||
|
@ -318,76 +283,65 @@ for commit in repo.iter_commits(rev=options.revision):
|
||||||
if regex.search(commit.summary):
|
if regex.search(commit.summary):
|
||||||
excluded = True
|
excluded = True
|
||||||
log.debug(
|
log.debug(
|
||||||
'Exclude commit %s ("%s", match with "%s")',
|
'Exclude commit %s ("%s", match with "%s")', commit, commit.summary, regex.pattern
|
||||||
commit, commit.summary, regex.pattern)
|
)
|
||||||
if not excluded:
|
if not excluded:
|
||||||
messages.append(commit.summary)
|
messages.append(commit.summary)
|
||||||
add_version()
|
add_version()
|
||||||
log.info('%d versions found', len(versions))
|
log.info("%d versions found", len(versions))
|
||||||
|
|
||||||
changelog_lines = []
|
changelog_lines = []
|
||||||
for version in versions:
|
for version in versions:
|
||||||
# pylint: disable=consider-using-f-string
|
# pylint: disable=consider-using-f-string
|
||||||
changelog_lines.append(
|
changelog_lines.append(
|
||||||
'{package} ({version}) {code_name}; urgency={urgency}\n\n'.format(
|
"{package} ({version}) {code_name}; urgency={urgency}\n\n".format(
|
||||||
package=options.package_name,
|
package=options.package_name,
|
||||||
version=version['name'],
|
version=version["name"],
|
||||||
code_name=options.code_name,
|
code_name=options.code_name,
|
||||||
urgency=options.urgency
|
urgency=options.urgency,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
for message in version['messages']:
|
for message in version["messages"]:
|
||||||
for idx, line in enumerate(
|
for idx, line in enumerate(textwrap.wrap(message, 76, break_long_words=True)):
|
||||||
textwrap.wrap(message, 76, break_long_words=True)
|
|
||||||
):
|
|
||||||
# pylint: disable=consider-using-f-string
|
# pylint: disable=consider-using-f-string
|
||||||
changelog_lines.append(
|
changelog_lines.append("{}{}\n".format(" * " if not idx else " ", line))
|
||||||
'{0}{1}\n'.format(
|
|
||||||
' * ' if not idx else ' ',
|
|
||||||
line
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
# pylint: disable=consider-using-f-string
|
# pylint: disable=consider-using-f-string
|
||||||
changelog_lines.append(
|
changelog_lines.append(
|
||||||
"\n -- {name} <{email}> {date}\n\n".format(
|
"\n -- {name} <{email}> {date}\n\n".format(
|
||||||
name=(
|
name=(
|
||||||
options.maintainer_name if options.maintainer_name
|
options.maintainer_name
|
||||||
else version['commit'].author.name),
|
if options.maintainer_name
|
||||||
|
else version["commit"].author.name
|
||||||
|
),
|
||||||
email=(
|
email=(
|
||||||
options.maintainer_email if options.maintainer_email
|
options.maintainer_email
|
||||||
else version['commit'].author.email),
|
if options.maintainer_email
|
||||||
date=version['commit'].committed_datetime.strftime(
|
else version["commit"].author.email
|
||||||
"%a, %d %b %Y %H:%M:%S %z")
|
),
|
||||||
|
date=version["commit"].committed_datetime.strftime("%a, %d %b %Y %H:%M:%S %z"),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
if options.output:
|
if options.output:
|
||||||
log.info('Write generated Debian changelog in file %s', options.output)
|
log.info("Write generated Debian changelog in file %s", options.output)
|
||||||
if options.append and os.path.exists(options.output):
|
if options.append and os.path.exists(options.output):
|
||||||
with open(options.output, 'r', encoding='utf8') as fd:
|
with open(options.output, encoding="utf8") as fd:
|
||||||
changelog_lines += [""]
|
changelog_lines += [""]
|
||||||
changelog_lines += fd.readlines()
|
changelog_lines += fd.readlines()
|
||||||
with open(options.output, 'w', encoding='utf8') as fd:
|
with open(options.output, "w", encoding="utf8") as fd:
|
||||||
fd.writelines(changelog_lines)
|
fd.writelines(changelog_lines)
|
||||||
else:
|
else:
|
||||||
print(''.join(changelog_lines))
|
print("".join(changelog_lines))
|
||||||
|
|
||||||
if options.release_notes:
|
if options.release_notes:
|
||||||
log.info('Generate Markdown release notes')
|
log.info("Generate Markdown release notes")
|
||||||
release_notes_lines = ['# Changelog:\n\n']
|
release_notes_lines = ["# Changelog:\n\n"]
|
||||||
if versions:
|
if versions:
|
||||||
release_notes_lines.extend([
|
release_notes_lines.extend([f"* {message}\n" for message in versions[0]["messages"]])
|
||||||
'* {0}\n'.format(message)
|
|
||||||
for message in versions[0]['messages']
|
|
||||||
])
|
|
||||||
else:
|
else:
|
||||||
release_notes_lines.extend([
|
release_notes_lines.extend([f"* Release version {options.version}\n"])
|
||||||
'* Release version {0}\n'.format(options.version)
|
log.info("Write generated Markdown release notes in file %s", options.release_notes)
|
||||||
])
|
with open(options.release_notes, "w", encoding="utf8") as fd:
|
||||||
log.info(
|
|
||||||
'Write generated Markdown release notes in file %s',
|
|
||||||
options.release_notes)
|
|
||||||
with open(options.release_notes, 'w', encoding='utf8') as fd:
|
|
||||||
fd.writelines(release_notes_lines)
|
fd.writelines(release_notes_lines)
|
||||||
|
|
Loading…
Reference in a new issue