perf(tool): 为 box.tool 新增可选填入 GitHub Token
#42
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: debug | |
| on: | |
| workflow_dispatch: | |
| push: | |
| paths-ignore: | |
| - "docs/**" | |
| - "README.md" | |
| - "CHANGELOG.md" | |
| branches: | |
| - master | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/[email protected] | |
| with: | |
| fetch-depth: 0 | |
| - name: Update Module.prop | |
| run: | | |
| dos2unix module.prop || true | |
| VERSION=$(grep -oP 'version=\K[^ ]+' module.prop | tr -d '\r') | |
| sed -i "s/$VERSION/$VERSION($(git log --oneline -n 1 | awk '{print $1}'))/g" module.prop | |
| sed -i "s/versionCode=.*/versionCode=$(date +%Y%m%d)/g" module.prop | |
| - name: Get Version | |
| id: get_version | |
| run: | | |
| VERSION=$(grep -oP 'version=\K[^ ]+' module.prop | tr -d '\r') | |
| echo "version=$VERSION" >> "$GITHUB_OUTPUT" | |
| - name: Generate Asset | |
| run: | | |
| sudo mkdir -p /box | |
| sudo cp -r --parents $(find ./ -type f ! -path './.git/*' ! -name 'CHANGELOG.md' ! -name 'update.json' ! -name 'build.sh' ! -path './.github/*' ! -path './docs/*') /box/ | |
| - name: Upload Debug Asset => (box_${{ steps.get_version.outputs.version }}) | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: "box_${{ steps.get_version.outputs.version }}" | |
| path: /box/ | |
| upload: | |
| runs-on: ubuntu-latest | |
| needs: | |
| - build | |
| steps: | |
| - uses: actions/[email protected] | |
| with: | |
| fetch-depth: 0 | |
| - name: run build | |
| run: | | |
| chmod +x build.sh | |
| ./build.sh | |
| telegram-upload: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| actions: read | |
| needs: | |
| - build | |
| if: success() | |
| steps: | |
| - uses: actions/[email protected] | |
| with: | |
| fetch-depth: 0 | |
| - name: Get Version and Artifact Name | |
| id: get_version | |
| run: | | |
| VERSION=$(grep -oP 'version=\K[^ ]+' module.prop | tr -d '\r') | |
| COMMIT_HASH=$(git log -1 --pretty=format:"%h") | |
| ARTIFACT_NAME="box_${VERSION}(${COMMIT_HASH})" | |
| echo "version=$VERSION" >> "$GITHUB_OUTPUT" | |
| echo "artifact_name=$ARTIFACT_NAME" >> "$GITHUB_OUTPUT" | |
| - name: Get Commit Info | |
| id: commit_info | |
| run: | | |
| COMMIT_MSG=$(git log -1 --pretty=format:"%B") | |
| COMMIT_HASH=$(git log -1 --pretty=format:"%h") | |
| COMMIT_AUTHOR=$(git log -1 --pretty=format:"%an") | |
| COMMIT_DATE=$(git log -1 --pretty=format:"%ad" --date=short) | |
| # Escape HTML special characters for Telegram HTML parse mode | |
| COMMIT_MSG_ESCAPED=$(echo "$COMMIT_MSG" | sed 's/&/\&/g; s/</\</g; s/>/\>/g; s/`\([^`]*\)`/<code>\1<\/code>/g') | |
| COMMIT_AUTHOR_ESCAPED=$(echo "$COMMIT_AUTHOR" | sed 's/&/\&/g; s/</\</g; s/>/\>/g') | |
| # Use EOF delimiter for multiline output | |
| { | |
| echo 'commit_msg<<EOF' | |
| echo "$COMMIT_MSG_ESCAPED" | |
| echo 'EOF' | |
| } >> "$GITHUB_OUTPUT" | |
| echo "commit_hash=$COMMIT_HASH" >> "$GITHUB_OUTPUT" | |
| echo "commit_author=$COMMIT_AUTHOR_ESCAPED" >> "$GITHUB_OUTPUT" | |
| echo "commit_date=$COMMIT_DATE" >> "$GITHUB_OUTPUT" | |
| - name: Send to Telegram | |
| env: | |
| TG_BOT_TOKEN: ${{ secrets.TG_BOT_TOKEN }} | |
| TG_CHAT_ID: ${{ secrets.TG_CHAT_ID }} | |
| GITHUB_TOKEN: ${{ github.token }} | |
| run: | | |
| ARTIFACT_URL=$(curl -s -H "Authorization: Bearer $GITHUB_TOKEN" \ | |
| "https://api.github.com/repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/artifacts" \ | |
| | jq -r ".artifacts[] | select(.name == \"${{ steps.get_version.outputs.artifact_name }}\") | .archive_download_url") | |
| if [ -z "$ARTIFACT_URL" ] || [ "$ARTIFACT_URL" = "null" ]; then | |
| echo "Artifact not found: ${{ steps.get_version.outputs.artifact_name }}" | |
| exit 1 | |
| fi | |
| curl -sSL -H "Authorization: Bearer $GITHUB_TOKEN" "$ARTIFACT_URL" -o "${{ steps.get_version.outputs.artifact_name }}.zip" | |
| MESSAGE="📦 <b>Box 模块自动构建</b> | |
| <b>提交:</b> <code>${{ steps.commit_info.outputs.commit_hash }}</code> | |
| <b>作者:</b> ${{ steps.commit_info.outputs.commit_author }} | |
| <b>日期:</b> ${{ steps.commit_info.outputs.commit_date }} | |
| <b>内容:</b> ${{ steps.commit_info.outputs.commit_msg }} | |
| <a href='https://github.com/boxproxy/box'>仓库地址</a> | <a href='https://github.com/boxproxy/box/actions/runs/${{ github.run_id }}'>构建详情</a> | |
| #模块更新" | |
| curl -sS -f -F "chat_id=$TG_CHAT_ID" \ | |
| -F "document=@${{ steps.get_version.outputs.artifact_name }}.zip" \ | |
| -F "caption=$MESSAGE" \ | |
| -F "parse_mode=HTML" \ | |
| "https://api.telegram.org/bot$TG_BOT_TOKEN/sendDocument" |