release #4
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 | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| tag: | |
| description: '发布标签' | |
| required: true | |
| branch: | |
| description: '目标分支(用于版本文件更新)' | |
| required: true | |
| changelog: | |
| description: '更新日志内容' | |
| required: true | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| # 1. Checkout repository | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| # 2. Generate version date | |
| - name: Get Version | |
| id: get_version | |
| run: echo "date=$(date +%Y%m%d)" >> "$GITHUB_OUTPUT" | |
| # 3. Update update.json, module.prop, and CHANGELOG.md | |
| - name: Update files | |
| run: | | |
| VERSION="${{ github.event.inputs.tag }}" | |
| DATE_NUM="${{ steps.get_version.outputs.date }}" | |
| DATE_HUMAN=$(date +%d-%m-%Y) | |
| CHANGELOG="${{ github.event.inputs.changelog }}" | |
| dos2unix module.prop || true | |
| # update.json | |
| cat > update.json <<EOF | |
| { | |
| "version": "$VERSION", | |
| "versionCode": "$DATE_NUM", | |
| "zipUrl": "https://github.com/boxproxy/box/releases/download/$VERSION/box-$VERSION.zip", | |
| "changelog": "https://github.com/boxproxy/box/raw/master/CHANGELOG.md" | |
| } | |
| EOF | |
| # module.prop | |
| sed -i "s/^version=.*/version=$VERSION/" module.prop | |
| sed -i "s/^versionCode=.*/versionCode=$DATE_NUM/" module.prop | |
| # Changelog | |
| if [ ! -f CHANGELOG.md ]; then | |
| echo "# Changelog" > CHANGELOG.md | |
| echo "" >> CHANGELOG.md | |
| fi | |
| { | |
| echo "#### Changelog $VERSION - $DATE_HUMAN" | |
| echo "$CHANGELOG" | sed 's/^/- /' | |
| echo "" | |
| cat CHANGELOG.md | |
| } > CHANGELOG.tmp && mv CHANGELOG.tmp CHANGELOG.md | |
| # 4. Commit and push changes | |
| - name: Commit and push changes | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git add update.json module.prop CHANGELOG.md | |
| git commit -m "${{ github.event.inputs.tag }}" || echo "No changes to commit" | |
| git push https://github-actions:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git HEAD:${{ github.event.inputs.branch }} --force | |
| # 5. Run build script | |
| - name: Run build.sh | |
| run: | | |
| chmod +x build.sh | |
| ./build.sh | |
| # 6. Create GitHub Release | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| tag_name: ${{ github.event.inputs.tag }} | |
| files: box-*.zip | |
| generate_release_notes: true | |
| body: | | |
| #### Changelog ${{ github.event.inputs.tag }} | |
| ${{ github.event.inputs.changelog }} | |