Sync Version from dbg #148
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: Sync Version from dbg | |
| on: | |
| schedule: | |
| - cron: "0 0 * * *" | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| issues: read | |
| jobs: | |
| sync-version: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout current repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Clone dbg | |
| run: | | |
| git clone https://github.com/George-Ogden/dbg.git /tmp/external-repo | |
| - name: Read new version | |
| run: | | |
| NEW_VERSION=$(cat /tmp/external-repo/version.txt) | |
| echo "New version: '$NEW_VERSION'" | |
| echo "NEW_VERSION=${NEW_VERSION}" >> "$GITHUB_ENV" | |
| - name: Read current version | |
| run: | | |
| CURRENT_VERSION=$(cat version.txt) | |
| echo "Current version: '$CURRENT_VERSION'" | |
| echo "CURRENT_VERSION=${CURRENT_VERSION}" >> "$GITHUB_ENV" | |
| - name: Compare versions | |
| id: compare | |
| run: | | |
| BRANCH_NAME="update-version-${{ env.NEW_VERSION }}" | |
| echo "BRANCH_NAME=${BRANCH_NAME}" >> "$GITHUB_ENV" | |
| if [ "${{ env.NEW_VERSION }}" != "${{ env.CURRENT_VERSION }}" ] && ! ( git ls-remote --heads origin "${{ env.BRANCH_NAME }}" | grep -q "${{ env.BRANCH_NAME }}" ); then | |
| echo "update_needed=true" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "update_needed=false" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Create pull request branch and setup Git identity | |
| if: steps.compare.outputs.update_needed == 'true' | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git checkout -b "${{ env.BRANCH_NAME }}" | |
| - name: Update version file | |
| if: steps.compare.outputs.update_needed == 'true' | |
| run: | | |
| echo ${{ env.NEW_VERSION }} > version.txt | |
| sed "s,^debug @.*,debug @ git+https://github.com/George-Ogden/dbg.git@v${{ env.NEW_VERSION }}#egg=debug," -i requirements.txt | |
| git add version.txt requirements.txt | |
| git commit -m "Automated version change" | |
| - name: Push changes | |
| if: steps.compare.outputs.update_needed == 'true' | |
| run: | | |
| git push origin "${{ env.BRANCH_NAME }}" | |
| - name: Create Pull Request | |
| if: steps.compare.outputs.update_needed == 'true' | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }} | |
| run: | | |
| gh pr create --title "Automated Version Sync" --body "Update version to ${{ steps.compare.outputs.new_version }}" --head "$BRANCH_NAME" --base "master" |