|
| 1 | +name: Auto Changelog |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + schedule: |
| 6 | + - cron: '50 23 * * *' |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write |
| 10 | + pull-requests: write |
| 11 | + |
| 12 | +jobs: |
| 13 | + changelog: |
| 14 | + runs-on: ubuntu-latest |
| 15 | + steps: |
| 16 | + - name: Checkout (full history) |
| 17 | + uses: actions/checkout@v4 |
| 18 | + with: |
| 19 | + fetch-depth: 0 |
| 20 | + |
| 21 | + - name: Setup Python |
| 22 | + uses: actions/setup-python@v5 |
| 23 | + with: |
| 24 | + python-version: '3.x' |
| 25 | + |
| 26 | + - name: Detect latest & base branch |
| 27 | + id: detect |
| 28 | + run: | |
| 29 | + set -e |
| 30 | + raw=$(curl -s https://community.fit2cloud.com/v1/products/dataease/releases | jq -r '.[0].version') |
| 31 | + if [ -z "$raw" ] || [ "$raw" = "null" ]; then echo "No version"; exit 1; fi |
| 32 | + version=${raw%-lts} |
| 33 | + major=$(echo "$version" | sed -E 's/^v([0-9]+).*/\1/') |
| 34 | + # base_branch="v${major}.0" |
| 35 | + base_branch="v2" |
| 36 | + echo "Latest version: $version (major=$major base=$base_branch)" |
| 37 | + # verify base branch exists |
| 38 | + if ! git ls-remote --exit-code --heads origin "$base_branch" >/dev/null 2>&1; then |
| 39 | + echo "Base branch $base_branch not found. Skipping." >&2 |
| 40 | + echo "update=false" >> $GITHUB_OUTPUT |
| 41 | + echo "version=$version" >> $GITHUB_OUTPUT |
| 42 | + echo "base=$base_branch" >> $GITHUB_OUTPUT |
| 43 | + exit 0 |
| 44 | + fi |
| 45 | + # Check remote file content without checkout to avoid ambiguity/detached HEAD issues |
| 46 | + if git show "origin/$base_branch:docs/changelog.md" | grep -q "^$version$"; then |
| 47 | + echo "Already present in changelog."; upd=false |
| 48 | + else |
| 49 | + upd=true |
| 50 | + fi |
| 51 | + echo "version=$version" >> $GITHUB_OUTPUT |
| 52 | + echo "base=$base_branch" >> $GITHUB_OUTPUT |
| 53 | + echo "update=$upd" >> $GITHUB_OUTPUT |
| 54 | +
|
| 55 | + - name: Generate changelog entry |
| 56 | + if: ${{ steps.detect.outputs.update == 'true' }} |
| 57 | + run: | |
| 58 | + python .github/scripts/gen_changelog.py "${{ steps.detect.outputs.version }}" |
| 59 | + echo 'Preview:' |
| 60 | + grep -n "^${{ steps.detect.outputs.version }}$" -A12 docs/changelog.md || true |
| 61 | +
|
| 62 | + - name: Stage changes |
| 63 | + if: ${{ steps.detect.outputs.update == 'true' }} |
| 64 | + run: | |
| 65 | + set -e |
| 66 | + # Ensure we are on the correct base branch before staging |
| 67 | + base="${{ steps.detect.outputs.base }}" |
| 68 | + git checkout -B "$base" "origin/$base" |
| 69 | + |
| 70 | + # Run generation again to ensure file is updated in the correct branch context if needed |
| 71 | + # (Optional, but safe if the previous step modified a file in a detached head or different branch) |
| 72 | + python .github/scripts/gen_changelog.py "${{ steps.detect.outputs.version }}" |
| 73 | + |
| 74 | + git config user.name 'github-actions[bot]' |
| 75 | + git config user.email 'github-actions[bot]@users.noreply.github.com' |
| 76 | + git add docs/changelog.md |
| 77 | +
|
| 78 | + - name: Create Pull Request |
| 79 | + if: ${{ steps.detect.outputs.update == 'true' }} |
| 80 | + uses: peter-evans/create-pull-request@v6 |
| 81 | + with: |
| 82 | + branch: chore/changelog-${{ steps.detect.outputs.version }} |
| 83 | + title: "chore: add changelog for ${{ steps.detect.outputs.version }}" |
| 84 | + commit-message: "chore: add changelog for ${{ steps.detect.outputs.version }}" |
| 85 | + body: | |
| 86 | + 自动生成的更新日志条目: **${{ steps.detect.outputs.version }}** |
| 87 | +
|
| 88 | + 目标基础分支: `${{ steps.detect.outputs.base }}` |
| 89 | +
|
| 90 | + 请 @liuboF2c 审核。 |
| 91 | + base: ${{ steps.detect.outputs.base }} |
| 92 | + reviewers: liuboF2c |
| 93 | + delete-branch: true |
| 94 | + |
| 95 | + - name: Skip |
| 96 | + if: ${{ steps.detect.outputs.update != 'true' }} |
| 97 | + run: echo "No changelog update needed (version=${{ steps.detect.outputs.version }}, base=${{ steps.detect.outputs.base }})." |
0 commit comments