From 02c1c4f4cb3afd9ddc65b678caad997a2dd61c62 Mon Sep 17 00:00:00 2001 From: Paul Ganssle Date: Mon, 23 Sep 2024 16:29:56 -0700 Subject: [PATCH] fixup! Add automatic PR action --- .github/workflows/check-for-updates.yml | 31 ++++++++++++++++++------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/.github/workflows/check-for-updates.yml b/.github/workflows/check-for-updates.yml index ed3b546..3448cef 100644 --- a/.github/workflows/check-for-updates.yml +++ b/.github/workflows/check-for-updates.yml @@ -7,9 +7,10 @@ on: workflow_dispatch: jobs: - update-tzdata: + check-pr-exists: runs-on: ubuntu-latest - + outputs: + pr_exists: ${{ steps.check_pr_exists.outputs.pr_exists }} steps: - name: Check if PR already exists id: check_pr_exists @@ -20,10 +21,20 @@ jobs: list --search "Update tzdata to version" \ --json number --jq '.[] | .number') if [ -n "$PR_EXISTS" ]; then - echo "A PR updating the tzdata version already exists, see http://github.com/python/tzdata/pulls/${PR_EXISTS}" + echo "A PR updating the tzdata version already exists: https://github.com/python/tzdata/pulls/${PR_EXISTS}" + echo "::set-output name=pr_exists::true" exit 0 + else + echo "::set-output name=pr_exists::false" fi + check-for-updates: + runs-on: ubuntu-latest + needs: check-pr-exists + if: needs.check-pr-exists.outputs.pr_exists == 'false' # Run only if no PR exists + outputs: + changes_detected: ${{ steps.check_changes.outputs.changes_detected }} + steps: - name: Check out repository (shallow) uses: actions/checkout@v3 with: @@ -42,7 +53,7 @@ jobs: - name: Run tox update run: tox -e update - - name: Check for repository changes + - name: Check for repository changes and commit id: check_changes run: | git config --global user.email "action@github.com" @@ -51,6 +62,7 @@ jobs: # Check for changes if git diff --quiet; then echo "No changes detected." + echo "::set-output name=changes_detected::false" exit 0 fi @@ -76,15 +88,18 @@ jobs: echo "TZDATA_VERSION=$TZDATA_VERSION" >> $GITHUB_ENV echo "TZDATA_NEWS=$TZDATA_NEWS" >> $GITHUB_ENV - - name: Commit and push changes - if: steps.check_changes.outcome == 'success' - run: | git add . git commit -m "Update tzdata to version $TZDATA_VERSION" git push origin HEAD + echo "::set-output name=changes_detected::true" + + create-pr: + runs-on: ubuntu-latest + needs: check-for-updates + if: needs.check-for-updates.outputs.changes_detected == 'true' # Run only if changes are detected + steps: - name: Create pull request - if: steps.check_pr_exists.outcome == 'success' env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: |