Skip to content

Commit 5496625

Browse files
committed
feat: implemented release automation (#154)
1 parent 6dcd671 commit 5496625

6 files changed

Lines changed: 94 additions & 182 deletions

File tree

.github/workflows/python-unittest.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
name: Python Tests ChurchToolsAPI
22

3-
on: [ push, pull_request ]
3+
on:
4+
push:
5+
branches-ignore:
6+
- main
7+
pull_request:
48

59
env:
610
CT_TOKEN: ${{ secrets.CT_TOKEN }}

.github/workflows/release.yml

Lines changed: 75 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,104 @@
1-
name: Create Release
1+
name: 1. Release-Please
2+
23
on:
34
push:
4-
tags:
5-
- '*'
6-
5+
branches:
6+
- main
7+
permissions:
8+
contents: write
9+
pull-requests: write
10+
711
jobs:
8-
build:
12+
release-please:
913
runs-on: ubuntu-latest
14+
env:
15+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1016
steps:
17+
- uses: googleapis/release-please-action@v4
18+
id: release
19+
with:
20+
release-type: python
21+
token: ${{ secrets.MY_RELEASE_PLEASE_TOKEN }}
22+
23+
- name: Debug release outputs
24+
run: |
25+
echo "release_created=${{ steps.release.outputs.release_created }}"
26+
echo "version=${{ steps.release.outputs.version }}"
27+
echo "tag_name=${{ steps.release.outputs.tag_name }}"
28+
echo "upload_url=${{ steps.release.outputs.upload_url }}"
29+
1130
- name: Checkout code
31+
if: ${{ steps.release.outputs.release_created }}
1232
uses: actions/checkout@v4.2.1
1333

14-
- name: Version from Python
15-
run: echo "VERSION=$(python3 -c 'import version; print(version.VERSION)')" >> $GITHUB_ENV
34+
- name: last release tag
35+
if: ${{ steps.release.outputs.release_created }}
36+
id: get_last_release
37+
run: |
38+
LAST_RELEASE_TAG=$(gh release list --limit 2 --json tagName -q '.[1].tagName')
39+
echo "last_release=$LAST_RELEASE_TAG"
40+
echo "last_release=$LAST_RELEASE_TAG" >> $GITHUB_OUTPUT
1641
1742
- name: Set up Python
43+
if: ${{ steps.release.outputs.release_created }}
1844
uses: actions/setup-python@v5.2.0
1945
with:
2046
python-version: 3.x
2147

2248
- name: Install Poetry
49+
if: ${{ steps.release.outputs.release_created }}
2350
run: |
2451
pip install poetry
2552
poetry config virtualenvs.create false # Skip creating a virtual environment
2653
env:
2754
POETRY_HOME: ${{ github.workspace }}/.poetry
2855

2956
- name: Install project dependencies
30-
run: |
31-
poetry install
57+
if: ${{ steps.release.outputs.release_created }}
58+
run: poetry install
3259
env:
3360
POETRY_HOME: ${{ github.workspace }}/.poetry
3461

3562
- name: Build package
36-
run: |
37-
poetry build
63+
if: ${{ steps.release.outputs.release_created }}
64+
run: poetry build
3865
env:
3966
POETRY_HOME: ${{ github.workspace }}/.poetry
4067

41-
- name: Create Release
42-
uses: ncipollo/release-action@v1.14.0
43-
with:
44-
tag: ${{ env.VERSION}}
45-
name: Version ${{env.VERSION}}
46-
body: |
47-
Automated Release preparation using Git Tag
48-
- make sure tests didn't fail
49-
- needs to be published from draft online
50-
51-
Install as package using:
52-
pip install git+https://github.com/bensteUEM/ChurchToolsAPI.git@${{env.VERSION}}#egg=churchtools-api
53-
54-
draft: true
55-
prerelease: false
56-
artifacts: dist/*
68+
- name: Append custom release notes
69+
if: ${{ steps.release.outputs.release_created }}
70+
run: |
71+
release_id=$(gh api \
72+
-H "Accept: application/vnd.github+json" \
73+
/repos/${{ github.repository }}/releases/tags/${{ steps.release.outputs.tag_name }} \
74+
--jq .id)
75+
76+
# Fetch existing release body
77+
existing_body=$(gh api /repos/${{ github.repository }}/releases/$release_id --jq .body)
78+
79+
# Create temporary file for new body
80+
tmpfile=$(mktemp)
81+
82+
# Write combined content into the file
83+
{
84+
echo "$existing_body"
85+
echo
86+
echo "Install as package using:"
87+
echo '```bash'
88+
echo "pip install git+https://github.com/bensteUEM/ChurchToolsAPI.git@${{ steps.release.outputs.tag_name }}#egg=churchtools-api"
89+
echo '```'
90+
echo "**Full Changelog**: https://github.com/bensteUEM/ChurchToolsAPI/compare/${{ steps.get_last_release.outputs.last_release }}...${{ steps.release.outputs.tag_name }}"
91+
} > "$tmpfile"
92+
93+
# Update the release body using the file
94+
gh api \
95+
-X PATCH \
96+
-H "Accept: application/vnd.github+json" \
97+
/repos/${{ github.repository }}/releases/$release_id \
98+
-F body="$(cat "$tmpfile")"
99+
100+
- name: Upload Release Artifact
101+
if: ${{ steps.release.outputs.release_created }}
102+
env:
103+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
104+
run: gh release upload ${{ steps.release.outputs.tag_name }} dist/*

churchtools_api/churchtools_api_abstract.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
import json
44
import logging
55
from abc import ABC, abstractmethod
6+
from typing import TYPE_CHECKING
7+
8+
if TYPE_CHECKING:
9+
import requests
610

711
logger = logging.getLogger(__name__)
812

@@ -17,8 +21,8 @@ class ChurchToolsApiAbstract(ABC):
1721
@abstractmethod
1822
def __init__(self) -> None:
1923
"""Preparing base variables."""
20-
self.session = None
21-
self.domain = None
24+
self.session:requests.Session |None = None
25+
self.domain:str|None = None
2226

2327
def combine_paginated_response_data(
2428
self,

generate_pyproj.py

Lines changed: 0 additions & 124 deletions
This file was deleted.

pyproject.toml

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@
22
name = "churchtools-api"
33
version = "1.7.3"
44
description = "A python wrapper for use with ChurchToolsAPI"
5-
authors = [
6-
"bensteUEM",
7-
"kolibri52",
8-
"fschrempf",
9-
]
5+
authors = ["bensteUEM", "kolibri52", "fschrempf"]
106
homepage = "https://github.com/bensteUEM/ChurchToolsAPI"
117
license = "CC-BY-SA"
128
readme = "README.md"
@@ -64,28 +60,23 @@ target-version = "py310"
6460
output-format = "grouped"
6561

6662
[tool.ruff.lint]
67-
select = [
68-
"ALL",
69-
]
63+
select = ["ALL"]
7064
ignore = [
7165
"FIX002", # correctly formatted TODO items that have open Github issues
72-
"COM812", "ISC001", #disabled for formatter compatibility #TODO 102 - move to pyproject.py
66+
"COM812",
67+
"ISC001", #disabled for formatter compatibility #TODO 102 - move to pyproject.py
7368

7469
"N802", #function lowercase -> breaking change #TODO 125 with release 2.0
7570
"N803", #argument lowercase -> breaking change #TODO 125 with release 2.0
7671
"N806", #variable name lowercase -> breaking change #TODO 125 with release 2.0
77-
]
78-
79-
fixable = [
80-
"ALL",
8172
]
73+
74+
fixable = ["ALL"]
8275
unfixable = []
8376
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
8477

8578
[tool.ruff.lint.per-file-ignores]
86-
"tests/*.py" = [
87-
"S101",
88-
]
79+
"tests/*.py" = ["S101"]
8980

9081
[tool.ruff.lint.pydocstyle]
9182
convention = "google"
@@ -99,7 +90,5 @@ docstring-code-format = false
9990
docstring-code-line-length = "dynamic"
10091

10192
[build-system]
102-
requires = [
103-
"poetry-core",
104-
]
93+
requires = ["poetry-core"]
10594
build-backend = "poetry.core.masonry.api"

version.py

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)