Skip to content

Commit

Permalink
fixup! Add automatic PR action
Browse files Browse the repository at this point in the history
  • Loading branch information
pganssle committed Sep 23, 2024
1 parent 7a52e8b commit 02c1c4f
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions .github/workflows/check-for-updates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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 "[email protected]"
Expand All @@ -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
Expand All @@ -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: |
Expand Down

0 comments on commit 02c1c4f

Please sign in to comment.