From cd88d805ce36db21e31fd7a31eec29080a6adc6a Mon Sep 17 00:00:00 2001 From: AkashiCoin Date: Mon, 16 Sep 2024 19:13:20 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=B3=20chore:=20=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E4=BF=AE=E6=94=B9=E7=89=88=E6=9C=AC=E5=8F=B7?= =?UTF-8?q?=20(#1629)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/update_version.yml | 65 ++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 .github/workflows/update_version.yml diff --git a/.github/workflows/update_version.yml b/.github/workflows/update_version.yml new file mode 100644 index 00000000..9e788ae7 --- /dev/null +++ b/.github/workflows/update_version.yml @@ -0,0 +1,65 @@ +name: Update Version + +on: + pull_request_target: + paths: + - zhenxun/** + - resources/** + - bot.py + types: + - opened + - synchronize + branches: + - main + - dev + +jobs: + update-version: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.sha }} + + - name: Read current version + id: read_version + run: | + version_line=$(grep '__version__' __version__) + version=$(echo $version_line | sed -E 's/__version__:\s*v([0-9]+\.[0-9]+\.[0-9]+)(-.+)?/\1/') + echo "Current version: $version" + echo "current_version=$version" >> $GITHUB_OUTPUT + + - name: Check for version file changes + id: check_diff + run: | + if git diff --name-only HEAD~1 HEAD | grep -q '__version__'; then + echo "Version file has changes" + echo "version_changed=true" >> $GITHUB_OUTPUT + else + echo "Version file has no changes" + echo "version_changed=false" >> $GITHUB_OUTPUT + fi + + - name: Get commit hash + id: get_commit_hash + run: echo "commit_hash=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT + + - name: Update version file + 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 "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__