Skip to content

Auto Changelog

Auto Changelog #123

name: Auto Changelog
on:
workflow_dispatch:
schedule:
- cron: '5 20 * * *'
permissions:
contents: write
pull-requests: write
jobs:
changelog:
runs-on: ubuntu-latest
steps:
- name: Checkout (full history)
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Detect latest & base branch
id: detect
run: |
set -e
raw=$(curl -s https://community.fit2cloud.com/v1/products/jumpserver/releases | jq -r '.[0].version')
if [ -z "$raw" ] || [ "$raw" = "null" ]; then echo "No version"; exit 1; fi
version=${raw%-lts}
major=$(echo "$version" | sed -E 's/^v([0-9]+).*/\1/')
base_branch="v${major}.0"
echo "Latest version: $version (major=$major base=$base_branch)"
# verify base branch exists
if ! git ls-remote --exit-code --heads origin "$base_branch" >/dev/null 2>&1; then
echo "Base branch $base_branch not found. Skipping." >&2
echo "update=false" >> $GITHUB_OUTPUT
echo "version=$version" >> $GITHUB_OUTPUT
echo "base=$base_branch" >> $GITHUB_OUTPUT
exit 0
fi
# Check remote file content without checkout to avoid ambiguity/detached HEAD issues
if git show "origin/$base_branch:docs/change_log.md" | grep -q "^$version$"; then
echo "Already present in changelog."; upd=false
else
upd=true
fi
echo "version=$version" >> $GITHUB_OUTPUT
echo "base=$base_branch" >> $GITHUB_OUTPUT
echo "update=$upd" >> $GITHUB_OUTPUT
- name: Generate changelog entry
if: ${{ steps.detect.outputs.update == 'true' }}
run: |
python .github/scripts/gen_changelog.py "${{ steps.detect.outputs.version }}"
echo 'Preview:'
grep -n "^${{ steps.detect.outputs.version }}$" -A12 docs/change_log.md || true
- name: Stage changes
if: ${{ steps.detect.outputs.update == 'true' }}
run: |
set -e
# Ensure we are on the correct base branch before staging
base="${{ steps.detect.outputs.base }}"
git checkout -B "$base" "origin/$base"
# Run generation again to ensure file is updated in the correct branch context if needed
# (Optional, but safe if the previous step modified a file in a detached head or different branch)
python .github/scripts/gen_changelog.py "${{ steps.detect.outputs.version }}"
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
git add docs/change_log.md
- name: Create Pull Request
if: ${{ steps.detect.outputs.update == 'true' }}
uses: peter-evans/create-pull-request@v6
with:
branch: chore/changelog-${{ steps.detect.outputs.version }}
title: "chore: add changelog for ${{ steps.detect.outputs.version }}"
commit-message: "chore: add changelog for ${{ steps.detect.outputs.version }}"
body: |
自动生成的更新日志条目: **${{ steps.detect.outputs.version }}**
目标基础分支: `${{ steps.detect.outputs.base }}`
请 @Nickyang00 审核。
base: ${{ steps.detect.outputs.base }}
reviewers: Nickyang00
delete-branch: true
- name: Skip
if: ${{ steps.detect.outputs.update != 'true' }}
run: echo "No changelog update needed (version=${{ steps.detect.outputs.version }}, base=${{ steps.detect.outputs.base }})."