Skip to content

Commit 950f1b4

Browse files
authored
Merge pull request #684 from PolicyEngine/fix/604-daily-dependency-updates
Run dependency updates daily
2 parents 0c95575 + 491cb8c commit 950f1b4

4 files changed

Lines changed: 114 additions & 40 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env bash
2+
3+
# Commit generated dependency changes and update the reusable PR branch.
4+
5+
set -euo pipefail
6+
7+
: "${GITHUB_OUTPUT:?GITHUB_OUTPUT is required}"
8+
: "${HAS_OPEN_PR:?HAS_OPEN_PR is required}"
9+
10+
if [[ "${HAS_OPEN_PR}" != "true" && "${HAS_OPEN_PR}" != "false" ]]; then
11+
echo "HAS_OPEN_PR must be either true or false" >&2
12+
exit 1
13+
fi
14+
15+
changes_detected=false
16+
if [[ -z "$(git status --porcelain)" ]]; then
17+
echo "No changes detected"
18+
else
19+
echo "Changes detected"
20+
git add --all
21+
git commit -m "Update dependencies ($(date -u +%Y-%m-%d))"
22+
changes_detected=true
23+
fi
24+
25+
branch_pushed=false
26+
if [[ "${HAS_OPEN_PR}" == "true" ]]; then
27+
commits_to_push="$(git rev-list --count origin/update-dependencies..HEAD)"
28+
if [[ "${commits_to_push}" -gt 0 ]]; then
29+
git push origin HEAD:update-dependencies
30+
branch_pushed=true
31+
fi
32+
elif [[ "${changes_detected}" == "true" ]]; then
33+
# No open PR owns this branch, so replacing a stale remote branch cannot
34+
# rewrite active review history.
35+
git push --force-with-lease origin HEAD:update-dependencies
36+
branch_pushed=true
37+
fi
38+
39+
echo "branch_pushed=${branch_pushed}" >> "${GITHUB_OUTPUT}"
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
3+
# Open a dependency-update PR after a new update branch has been pushed.
4+
5+
set -euo pipefail
6+
7+
: "${GITHUB_REPOSITORY:?GITHUB_REPOSITORY is required}"
8+
9+
gh pr create \
10+
--repo "${GITHUB_REPOSITORY}" \
11+
--title "Update dependencies" \
12+
--body "Automated daily dependency updates. Subsequent runs append commits to this branch while the pull request remains open." \
13+
--base main \
14+
--head update-dependencies
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env bash
2+
3+
# Reuse the branch for an open dependency-update PR, or start a new branch
4+
# from current main when no update PR exists.
5+
6+
set -euo pipefail
7+
8+
: "${GITHUB_REPOSITORY:?GITHUB_REPOSITORY is required}"
9+
: "${GITHUB_OUTPUT:?GITHUB_OUTPUT is required}"
10+
11+
git config user.name "policyengine-auto"
12+
git config user.email "policyengine-auto@users.noreply.github.com"
13+
14+
open_pr="$(
15+
gh pr list \
16+
--repo "${GITHUB_REPOSITORY}" \
17+
--base main \
18+
--head update-dependencies \
19+
--state open \
20+
--json number \
21+
--jq '.[0].number // empty'
22+
)"
23+
24+
if [[ -n "${open_pr}" ]]; then
25+
echo "has_open_pr=true" >> "${GITHUB_OUTPUT}"
26+
git fetch origin update-dependencies
27+
git checkout -B update-dependencies origin/update-dependencies
28+
29+
# Preserve the open PR's commits while incorporating current main. Prefer
30+
# main's version of conflicts because later steps regenerate clients and
31+
# recreate dependency lock changes.
32+
git merge --no-edit -X theirs origin/main
33+
else
34+
echo "has_open_pr=false" >> "${GITHUB_OUTPUT}"
35+
git checkout -B update-dependencies origin/main
36+
fi

‎.github/workflows/update-dependencies.yml‎

Lines changed: 25 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@ name: Update dependencies
22

33
on:
44
schedule:
5-
# Run every 15 minutes
6-
- cron: '*/15 * * * *'
5+
# Run daily at 3:00 PM US Eastern time.
6+
- cron: '0 15 * * *'
7+
timezone: 'America/New_York'
78
workflow_dispatch: # Allow manual triggering
89

10+
concurrency:
11+
group: update-dependencies
12+
cancel-in-progress: false
13+
914
jobs:
1015
update-dependencies:
1116
name: File update PR
@@ -25,9 +30,9 @@ jobs:
2530

2631
- name: Checkout repository
2732
uses: actions/checkout@v6
28-
# Checkout main branch
2933
with:
3034
ref: main
35+
fetch-depth: 0
3136
token: ${{ steps.app-token.outputs.token }}
3237

3338
- name: Install uv
@@ -37,47 +42,27 @@ jobs:
3742
uses: actions/setup-python@v6
3843
with:
3944
python-version: "3.13"
45+
46+
- name: Prepare update branch
47+
id: branch
48+
env:
49+
GH_TOKEN: ${{ steps.app-token.outputs.token }}
50+
run: .github/scripts/dependency-update-prepare-branch.sh
4051

4152
- name: Generate API clients
42-
run: |
43-
# Generate clients with correct naming before updating dependencies
44-
./scripts/generate-clients.sh
53+
run: ./scripts/generate-clients.sh
4554

4655
- name: Update dependencies
47-
id: update
48-
run: |
49-
# Run the update command
50-
make update
51-
52-
# Check if there are changes
53-
if [[ -z $(git status --porcelain) ]]; then
54-
echo "No changes detected"
55-
echo "changes_detected=false" >> $GITHUB_OUTPUT
56-
else
57-
echo "Changes detected"
58-
echo "changes_detected=true" >> $GITHUB_OUTPUT
59-
fi
60-
61-
- name: Create pull request
62-
if: steps.update.outputs.changes_detected == 'true'
63-
run: |
64-
git config --global user.name "policyengine-auto"
65-
git config --global user.email "policyengine-auto@users.noreply.github.com"
66-
67-
git checkout -b update-dependencies
68-
git add .
69-
git commit -m "Update dependencies"
70-
git push origin update-dependencies --force
71-
72-
# Try to create PR, ignore if it already exists
73-
gh pr create \
74-
--title "Update dependencies" \
75-
--body "Automated dependency updates
56+
run: make update
7657

77-
This PR was automatically created by the dependency update workflow.
58+
- name: Commit and push update
59+
id: push
60+
env:
61+
HAS_OPEN_PR: ${{ steps.branch.outputs.has_open_pr }}
62+
run: .github/scripts/dependency-update-commit-and-push.sh
7863

79-
Last updated: $(date)" \
80-
--base main \
81-
--head update-dependencies || echo "PR may already exist, continuing..."
64+
- name: Create pull request
65+
if: steps.branch.outputs.has_open_pr == 'false' && steps.push.outputs.branch_pushed == 'true'
8266
env:
83-
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
67+
GH_TOKEN: ${{ steps.app-token.outputs.token }}
68+
run: .github/scripts/dependency-update-create-pr.sh

0 commit comments

Comments
 (0)