add changelog tooling
All checks were successful
Build and Deploy Staging / build (push) Successful in 44s
Build and Deploy Antora Docs / build (push) Successful in 36s
Tests / test (push) Successful in 27s
Build and Deploy Staging / deploy (push) Successful in 6s
Build and Deploy Antora Docs / deploy (push) Successful in 4s
All checks were successful
Build and Deploy Staging / build (push) Successful in 44s
Build and Deploy Antora Docs / build (push) Successful in 36s
Tests / test (push) Successful in 27s
Build and Deploy Staging / deploy (push) Successful in 6s
Build and Deploy Antora Docs / deploy (push) Successful in 4s
This commit is contained in:
parent
6ed6a8f4c3
commit
96469c0212
6 changed files with 415 additions and 3 deletions
141
hack/bumpver-post-commit-hook.sh
Executable file
141
hack/bumpver-post-commit-hook.sh
Executable file
|
|
@ -0,0 +1,141 @@
|
|||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
# Post-commit hook for bumpver to create a Forgejo release
|
||||
# This script creates a release on Forgejo using the changelog generated in the pre-commit hook
|
||||
|
||||
# Configuration
|
||||
FORGEJO_URL="https://servala.app.codey.ch"
|
||||
REPO_OWNER="servala"
|
||||
REPO_NAME="servala-portal"
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Check for required environment variable
|
||||
if [ -z "${FORGEJO_TOKEN:-}" ]; then
|
||||
echo -e "${RED}Error: FORGEJO_TOKEN environment variable is not set${NC}"
|
||||
echo "Please set FORGEJO_TOKEN to your Forgejo API token"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Get the current version from pyproject.toml
|
||||
CURRENT_VERSION=$(grep -E 'current_version = ".*"' pyproject.toml | head -1 | sed -E 's/current_version = "(.*)"/\1/')
|
||||
echo -e "${GREEN}Creating release for version: ${CURRENT_VERSION}${NC}"
|
||||
|
||||
# Get the latest tag (should match CURRENT_VERSION)
|
||||
LATEST_TAG=$(git tag -l --sort=-v:refname | head -1)
|
||||
if [ "$LATEST_TAG" != "$CURRENT_VERSION" ]; then
|
||||
echo -e "${YELLOW}Warning: Latest tag (${LATEST_TAG}) doesn't match current version (${CURRENT_VERSION})${NC}"
|
||||
echo -e "${YELLOW}Using current version: ${CURRENT_VERSION}${NC}"
|
||||
fi
|
||||
|
||||
# Try to read the changelog generated by the pre-commit hook
|
||||
CHANGELOG_DIR=".git/changelog"
|
||||
CHANGELOG_FILE="${CHANGELOG_DIR}/${CURRENT_VERSION}.txt"
|
||||
|
||||
if [ -f "$CHANGELOG_FILE" ]; then
|
||||
CHANGELOG_CONTENT=$(cat "$CHANGELOG_FILE")
|
||||
echo -e "${GREEN}Found changelog content from pre-commit hook${NC}"
|
||||
else
|
||||
echo -e "${YELLOW}Warning: Changelog file not found at ${CHANGELOG_FILE}${NC}"
|
||||
echo -e "${YELLOW}Generating changelog from tag information${NC}"
|
||||
|
||||
# Fallback: use git log to get commits since previous tag
|
||||
PREVIOUS_TAG=$(git tag -l --sort=-v:refname | head -2 | tail -1)
|
||||
if [ -n "$PREVIOUS_TAG" ]; then
|
||||
CHANGELOG_CONTENT=$(git log --pretty=format:"* %s" "${PREVIOUS_TAG}..${LATEST_TAG}")
|
||||
else
|
||||
CHANGELOG_CONTENT="* Initial release"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Convert AsciiDoc to Markdown
|
||||
# 1. Convert === headers to ### (third-level headers)
|
||||
# 2. Convert link:url[text] to [text](url)
|
||||
CHANGELOG_MARKDOWN=$(echo "$CHANGELOG_CONTENT" | sed -E 's/^=== /### /g' | sed -E 's/link:([^[]+)\[([^]]+)\]/[\2](\1)/g')
|
||||
|
||||
# Create release body in Markdown format
|
||||
RELEASE_BODY="## Release ${CURRENT_VERSION}
|
||||
|
||||
${CHANGELOG_MARKDOWN}
|
||||
"
|
||||
|
||||
# Check if release already exists
|
||||
API_URL="${FORGEJO_URL}/api/v1/repos/${REPO_OWNER}/${REPO_NAME}/releases/tags/${CURRENT_VERSION}"
|
||||
EXISTING_RELEASE=$(curl -s -H "Authorization: token ${FORGEJO_TOKEN}" "${API_URL}")
|
||||
|
||||
# Check if we got a release back (not an error)
|
||||
if echo "$EXISTING_RELEASE" | jq -e '.id' > /dev/null 2>&1; then
|
||||
echo -e "${YELLOW}Release ${CURRENT_VERSION} already exists${NC}"
|
||||
RELEASE_ID=$(echo "$EXISTING_RELEASE" | jq -r '.id')
|
||||
echo -e "${GREEN}Updating existing release (ID: ${RELEASE_ID})${NC}"
|
||||
|
||||
# Update the existing release
|
||||
UPDATE_URL="${FORGEJO_URL}/api/v1/repos/${REPO_OWNER}/${REPO_NAME}/releases/${RELEASE_ID}"
|
||||
|
||||
RESPONSE=$(curl -s -X PATCH \
|
||||
-H "Authorization: token ${FORGEJO_TOKEN}" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$(jq -n \
|
||||
--arg tag "${CURRENT_VERSION}" \
|
||||
--arg name "Release ${CURRENT_VERSION}" \
|
||||
--arg body "${RELEASE_BODY}" \
|
||||
'{
|
||||
tag_name: $tag,
|
||||
name: $name,
|
||||
body: $body
|
||||
}')" \
|
||||
"${UPDATE_URL}")
|
||||
|
||||
if echo "$RESPONSE" | jq -e '.id' > /dev/null 2>&1; then
|
||||
RELEASE_URL=$(echo "$RESPONSE" | jq -r '.html_url')
|
||||
echo -e "${GREEN}Release updated successfully!${NC}"
|
||||
echo -e "${GREEN}Release URL: ${RELEASE_URL}${NC}"
|
||||
else
|
||||
echo -e "${RED}Error updating release${NC}"
|
||||
echo "$RESPONSE" | jq .
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo -e "${GREEN}Creating new release${NC}"
|
||||
|
||||
# Create new release
|
||||
CREATE_URL="${FORGEJO_URL}/api/v1/repos/${REPO_OWNER}/${REPO_NAME}/releases"
|
||||
|
||||
RESPONSE=$(curl -s -X POST \
|
||||
-H "Authorization: token ${FORGEJO_TOKEN}" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$(jq -n \
|
||||
--arg tag "${CURRENT_VERSION}" \
|
||||
--arg name "Release ${CURRENT_VERSION}" \
|
||||
--arg body "${RELEASE_BODY}" \
|
||||
'{
|
||||
tag_name: $tag,
|
||||
name: $name,
|
||||
body: $body,
|
||||
draft: false,
|
||||
prerelease: false
|
||||
}')" \
|
||||
"${CREATE_URL}")
|
||||
|
||||
if echo "$RESPONSE" | jq -e '.id' > /dev/null 2>&1; then
|
||||
RELEASE_URL=$(echo "$RESPONSE" | jq -r '.html_url')
|
||||
echo -e "${GREEN}Release created successfully!${NC}"
|
||||
echo -e "${GREEN}Release URL: ${RELEASE_URL}${NC}"
|
||||
else
|
||||
echo -e "${RED}Error creating release${NC}"
|
||||
echo "$RESPONSE" | jq .
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# Clean up the changelog file
|
||||
if [ -f "$CHANGELOG_FILE" ]; then
|
||||
rm -f "$CHANGELOG_FILE"
|
||||
fi
|
||||
|
||||
exit 0
|
||||
Loading…
Add table
Add a link
Reference in a new issue