Merge pull request #50 from BaiduNetdiskAIBot/main #23
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Release Skills | |
| on: | |
| push: | |
| branches: [main] | |
| paths: | |
| - 'skills/*/VERSION' | |
| workflow_dispatch: | |
| inputs: | |
| skill: | |
| description: 'Skill 名称(如 baidu-netdisk),留空则发布所有' | |
| required: false | |
| permissions: | |
| contents: write | |
| jobs: | |
| detect: | |
| if: github.repository == 'baidu-netdisk/bdpan-storage' || github.event_name == 'workflow_dispatch' | |
| runs-on: ubuntu-latest | |
| outputs: | |
| matrix: ${{ steps.set-matrix.outputs.matrix }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 2 | |
| - name: Detect changed skills | |
| id: set-matrix | |
| run: | | |
| if [ "${{ github.event_name }}" = "workflow_dispatch" ] && [ -n "${{ github.event.inputs.skill }}" ]; then | |
| SKILL="${{ github.event.inputs.skill }}" | |
| VERSION=$(cat "skills/${SKILL}/VERSION" | tr -d '[:space:]') | |
| echo "matrix={\"include\":[{\"skill\":\"${SKILL}\",\"version\":\"${VERSION}\"}]}" >> $GITHUB_OUTPUT | |
| elif [ "${{ github.event_name }}" = "workflow_dispatch" ]; then | |
| MATRIX='{"include":[' | |
| FIRST=true | |
| for skill_path in skills/*/; do | |
| if [ -d "$skill_path" ] && [ -f "${skill_path}VERSION" ]; then | |
| skill_name=$(basename "$skill_path") | |
| version=$(cat "${skill_path}VERSION" | tr -d '[:space:]') | |
| if [ "$FIRST" = true ]; then | |
| FIRST=false | |
| else | |
| MATRIX="${MATRIX}," | |
| fi | |
| MATRIX="${MATRIX}{\"skill\":\"${skill_name}\",\"version\":\"${version}\"}" | |
| fi | |
| done | |
| MATRIX="${MATRIX}]}" | |
| echo "matrix=${MATRIX}" >> $GITHUB_OUTPUT | |
| else | |
| MATRIX='{"include":[' | |
| FIRST=true | |
| CHANGED=$(git diff --name-only HEAD~1 HEAD -- 'skills/*/VERSION') | |
| for file in $CHANGED; do | |
| skill_name=$(echo "$file" | cut -d'/' -f2) | |
| version=$(cat "$file" | tr -d '[:space:]') | |
| if [ "$FIRST" = true ]; then | |
| FIRST=false | |
| else | |
| MATRIX="${MATRIX}," | |
| fi | |
| MATRIX="${MATRIX}{\"skill\":\"${skill_name}\",\"version\":\"${version}\"}" | |
| done | |
| MATRIX="${MATRIX}]}" | |
| echo "matrix=${MATRIX}" >> $GITHUB_OUTPUT | |
| fi | |
| release: | |
| needs: detect | |
| if: ${{ needs.detect.outputs.matrix != '{"include":[]}' }} | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: ${{ fromJson(needs.detect.outputs.matrix) }} | |
| fail-fast: false | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Check if tag already exists | |
| id: check_tag | |
| run: | | |
| TAG="${{ matrix.skill }}/${{ matrix.version }}" | |
| echo "tag=${TAG}" >> $GITHUB_OUTPUT | |
| if git rev-parse "refs/tags/${TAG}" >/dev/null 2>&1; then | |
| echo "exists=true" >> $GITHUB_OUTPUT | |
| echo "⚠️ Tag ${TAG} 已存在,跳过发布" | |
| else | |
| echo "exists=false" >> $GITHUB_OUTPUT | |
| echo "✅ Tag ${TAG} 不存在,准备发布" | |
| fi | |
| - name: Package Skill | |
| if: steps.check_tag.outputs.exists == 'false' | |
| run: | | |
| SKILL="${{ matrix.skill }}" | |
| VERSION="${{ matrix.version }}" | |
| mkdir -p dist | |
| echo "📦 打包: ${SKILL} ${VERSION}" | |
| (cd "skills/${SKILL}" && zip -r "../../dist/${SKILL}-${VERSION}.zip" . \ | |
| -x ".git/*" \ | |
| -x ".DS_Store" \ | |
| -x "node_modules/*" \ | |
| -x "__pycache__/*" \ | |
| -x ".env*" \ | |
| -x ".idea/*" \ | |
| -x ".vscode/*" \ | |
| -x "dist/*" \ | |
| -x "build/*" \ | |
| -x "*.pyc" \ | |
| -x "*.log" \ | |
| -x "*.tmp") | |
| echo "✅ 完成: dist/${SKILL}-${VERSION}.zip" | |
| - name: Create and push tag | |
| if: steps.check_tag.outputs.exists == 'false' | |
| run: | | |
| git tag "${{ steps.check_tag.outputs.tag }}" | |
| git push origin "${{ steps.check_tag.outputs.tag }}" | |
| - name: Generate Release Notes | |
| if: steps.check_tag.outputs.exists == 'false' | |
| id: release_notes | |
| run: | | |
| SKILL="${{ matrix.skill }}" | |
| VERSION="${{ matrix.version }}" | |
| SKILL_FILE="skills/${SKILL}/SKILL.md" | |
| DESC="" | |
| if [ -f "$SKILL_FILE" ]; then | |
| # 支持 YAML 多行格式 (description: >-) 和单行格式 | |
| DESC_LINE=$(grep -n "^description:" "$SKILL_FILE" | head -1 | cut -d: -f1) | |
| if [ -n "$DESC_LINE" ]; then | |
| INLINE=$(sed -n "${DESC_LINE}p" "$SKILL_FILE" | sed 's/^description: *//') | |
| if [ "$INLINE" = ">" ] || [ "$INLINE" = ">-" ] || [ "$INLINE" = "|" ] || [ -z "$INLINE" ]; then | |
| DESC=$(sed -n "$((DESC_LINE+1))p" "$SKILL_FILE" | sed 's/^ *//') | |
| else | |
| DESC="$INLINE" | |
| fi | |
| fi | |
| fi | |
| { | |
| echo "RELEASE_NOTES<<EOF" | |
| echo "## 📦 Skill ${SKILL} ${VERSION}" | |
| echo "" | |
| if [ -n "$DESC" ]; then | |
| echo "${DESC}" | |
| echo "" | |
| fi | |
| echo "### 安装方法:" | |
| echo '```bash' | |
| echo "npx skills add https://github.com/baidu-netdisk/bdpan-storage/skills --skill ${SKILL}" | |
| echo '```' | |
| echo "EOF" | |
| } >> $GITHUB_OUTPUT | |
| - name: Create Release | |
| if: steps.check_tag.outputs.exists == 'false' | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| tag_name: ${{ steps.check_tag.outputs.tag }} | |
| name: "${{ matrix.skill }} ${{ matrix.version }}" | |
| body: ${{ steps.release_notes.outputs.RELEASE_NOTES }} | |
| files: dist/${{ matrix.skill }}-${{ matrix.version }}.zip | |
| draft: false | |
| prerelease: false | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Summary | |
| if: steps.check_tag.outputs.exists == 'false' | |
| run: | | |
| echo "## 🎉 Release ${{ steps.check_tag.outputs.tag }} 创建成功!" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "**Skill:** ${{ matrix.skill }}" >> $GITHUB_STEP_SUMMARY | |
| echo "**Version:** ${{ matrix.version }}" >> $GITHUB_STEP_SUMMARY | |
| echo "**Tag:** ${{ steps.check_tag.outputs.tag }}" >> $GITHUB_STEP_SUMMARY |