clash-verge-rev/.github/workflows/sync-mihomo-changelog.yml
2026-05-18 21:52:53 +08:00

79 lines
2.4 KiB
YAML

name: Sync Mihomo Changelog
on:
workflow_dispatch:
schedule:
# UTC+8 Monday 11:30
- cron: '30 3 * * 1'
permissions:
contents: write
pull-requests: write
concurrency:
group: sync-mihomo-changelog
cancel-in-progress: false
jobs:
sync:
name: Sync Changelog
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
ref: ${{ github.event.repository.default_branch }}
- name: Install Node
uses: actions/setup-node@v6
with:
node-version: '24.15.0'
- name: Sync Mihomo version
run: node scripts/sync-mihomo-version.mjs
- name: Detect changelog changes
id: changes
run: |
if git diff --quiet -- Changelog.md; then
echo "changed=false" >> "$GITHUB_OUTPUT"
exit 0
fi
mihomo_version="$(grep -Eo 'Mihomo\(Meta\).*v[0-9]+(\.[0-9]+)+' Changelog.md | grep -Eo 'v[0-9]+(\.[0-9]+)+' | head -n 1)"
echo "changed=true" >> "$GITHUB_OUTPUT"
echo "mihomo_version=$mihomo_version" >> "$GITHUB_OUTPUT"
- name: Open pull request
if: steps.changes.outputs.changed == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BASE_BRANCH: ${{ github.event.repository.default_branch }}
MIHOMO_VERSION: ${{ steps.changes.outputs.mihomo_version }}
run: |
branch="chore/sync-mihomo-changelog"
title="chore: sync Mihomo changelog to ${MIHOMO_VERSION}"
body="Automated update for the Mihomo core version recorded in Changelog.md."
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git fetch origin "$branch:refs/remotes/origin/$branch" || true
git checkout -B "$branch"
git add Changelog.md
git commit -m "$title"
git push --force-with-lease origin "$branch"
if gh pr view "$branch" --repo "$GITHUB_REPOSITORY" > /dev/null 2>&1; then
gh pr edit "$branch" \
--repo "$GITHUB_REPOSITORY" \
--title "$title" \
--body "$body"
else
gh pr create \
--repo "$GITHUB_REPOSITORY" \
--base "$BASE_BRANCH" \
--head "$branch" \
--title "$title" \
--body "$body"
fi