diff --git a/.github/workflows/update_version.yml b/.github/workflows/update_version_pr.yml similarity index 64% rename from .github/workflows/update_version.yml rename to .github/workflows/update_version_pr.yml index 9e788ae7..6f650aa2 100644 --- a/.github/workflows/update_version.yml +++ b/.github/workflows/update_version_pr.yml @@ -1,14 +1,12 @@ name: Update Version on: - pull_request_target: + push: paths: + - .github/workflows/update_version_pr.yml - zhenxun/** - resources/** - bot.py - types: - - opened - - synchronize branches: - main - dev @@ -20,7 +18,7 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 with: - ref: ${{ github.event.pull_request.head.sha }} + token: ${{ secrets.GH_TOKEN }} - name: Read current version id: read_version @@ -46,20 +44,30 @@ jobs: run: echo "commit_hash=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT - name: Update version file + id: update_version if: steps.check_diff.outputs.version_changed == 'false' run: | current_version="${{ steps.read_version.outputs.current_version }}" commit_hash="${{ steps.get_commit_hash.outputs.commit_hash }}" new_version="v${current_version}-${commit_hash}" + echo "new_version=$new_version" >> $GITHUB_OUTPUT echo "Updating version to: $new_version" echo "__version__: $new_version" > __version__ - git config --global user.name "${{ github.event.pull_request.user.login }}" - git config --global user.email "${{ github.event.pull_request.user.login }}@users.noreply.github.com" - git add __version__ - git remote set-url origin https://github.com/${{ github.event.pull_request.head.repo.full_name }}.git - git commit -m "chore(version): Update version to $new_version" - git push origin HEAD:${{ github.event.pull_request.head.ref }} - name: Check updated version if: steps.check_diff.outputs.version_changed == 'false' run: cat __version__ + + - name: Create or update PR + if: steps.check_diff.outputs.version_changed == 'false' + uses: peter-evans/create-pull-request@v7 + with: + token: ${{ secrets.GH_TOKEN }} + branch: create-pr/update_version + title: ":tada: chore(version): 自动更新版本到 ${{ steps.update_version.outputs.new_version }}" + body: "This PR updates the version file." + commit-message: ":tada: chore(version): Update version to ${{ steps.update_version.outputs.new_version }}" + add-paths: __version__ + author: "AkashiCoin " + committer: "${{ github.actor }} <${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com>" + labels: automated-update