Add plugin release workflow with version extraction and changelog management
Co-authored-by: Fu-Jie <33599649+Fu-Jie@users.noreply.github.com>
This commit is contained in:
141
.github/workflows/plugin-version-check.yml
vendored
Normal file
141
.github/workflows/plugin-version-check.yml
vendored
Normal file
@@ -0,0 +1,141 @@
|
||||
# GitHub Actions Workflow for Plugin Version Change Detection
|
||||
# 插件版本变化检测工作流
|
||||
#
|
||||
# This workflow detects version changes in plugins when PRs are created or updated.
|
||||
# 此工作流在创建或更新 PR 时检测插件的版本变化。
|
||||
#
|
||||
# What it does:
|
||||
# 1. Compares plugin versions between base and head branches
|
||||
# 2. Generates a summary of version changes
|
||||
# 3. Comments on the PR with the changes (optional)
|
||||
|
||||
name: Plugin Version Check / 插件版本检查
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
paths:
|
||||
- 'plugins/**/*.py'
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
pull-requests: write
|
||||
|
||||
jobs:
|
||||
check-versions:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout PR head
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
ref: ${{ github.event.pull_request.head.sha }}
|
||||
path: head
|
||||
|
||||
- name: Checkout base branch
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
ref: ${{ github.event.pull_request.base.sha }}
|
||||
path: base
|
||||
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: '3.11'
|
||||
|
||||
- name: Extract and compare versions
|
||||
id: compare
|
||||
run: |
|
||||
# Extract base versions
|
||||
cd base
|
||||
if [ -f scripts/extract_plugin_versions.py ]; then
|
||||
python scripts/extract_plugin_versions.py --json --output ../base_versions.json
|
||||
else
|
||||
# Fallback if script doesn't exist in base
|
||||
echo "[]" > ../base_versions.json
|
||||
fi
|
||||
cd ..
|
||||
|
||||
# Extract head versions
|
||||
cd head
|
||||
python scripts/extract_plugin_versions.py --json --output ../head_versions.json
|
||||
|
||||
# Compare versions
|
||||
python scripts/extract_plugin_versions.py --compare ../base_versions.json --output ../changes.md
|
||||
cd ..
|
||||
|
||||
echo "=== Version Changes ==="
|
||||
cat changes.md
|
||||
|
||||
# Check if there are any changes
|
||||
if grep -q "No changes detected" changes.md; then
|
||||
echo "has_changes=false" >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "has_changes=true" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
|
||||
# Store changes for comment
|
||||
{
|
||||
echo 'changes<<EOF'
|
||||
cat changes.md
|
||||
echo 'EOF'
|
||||
} >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Comment on PR
|
||||
if: steps.compare.outputs.has_changes == 'true'
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
script: |
|
||||
const changes = `${{ steps.compare.outputs.changes }}`;
|
||||
|
||||
const body = `## 🔍 Plugin Version Changes / 插件版本变化
|
||||
|
||||
${changes}
|
||||
|
||||
---
|
||||
*This comment was generated automatically. / 此评论由自动生成。*
|
||||
`;
|
||||
|
||||
// Find existing comment from github-actions bot
|
||||
const { data: comments } = await github.rest.issues.listComments({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
issue_number: context.issue.number,
|
||||
});
|
||||
|
||||
const botComment = comments.find(comment =>
|
||||
(comment.user.login === 'github-actions[bot]' || comment.user.type === 'Bot') &&
|
||||
comment.body.includes('Plugin Version Changes')
|
||||
);
|
||||
|
||||
if (botComment) {
|
||||
// Update existing comment
|
||||
await github.rest.issues.updateComment({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
comment_id: botComment.id,
|
||||
body: body,
|
||||
});
|
||||
} else {
|
||||
// Create new comment
|
||||
await github.rest.issues.createComment({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
issue_number: context.issue.number,
|
||||
body: body,
|
||||
});
|
||||
}
|
||||
|
||||
- name: Summary
|
||||
run: |
|
||||
echo "## 🔍 Plugin Version Check Results" >> $GITHUB_STEP_SUMMARY
|
||||
echo "" >> $GITHUB_STEP_SUMMARY
|
||||
|
||||
if [ "${{ steps.compare.outputs.has_changes }}" = "true" ]; then
|
||||
echo "✅ **Version changes detected!**" >> $GITHUB_STEP_SUMMARY
|
||||
echo "" >> $GITHUB_STEP_SUMMARY
|
||||
cat changes.md >> $GITHUB_STEP_SUMMARY
|
||||
else
|
||||
echo "ℹ️ **No version changes detected.**" >> $GITHUB_STEP_SUMMARY
|
||||
fi
|
||||
Reference in New Issue
Block a user