Skip to content

Commit c3d9524

Browse files
committed
ci/update: check against base branch if no PR is open
1 parent 635adc0 commit c3d9524

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

.github/workflows/update.yml

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ jobs:
3333
if: github.event_name != 'schedule' || github.repository == 'nix-community/nixvim'
3434
env:
3535
repo: ${{ github.repository }}
36-
branch: update/${{ github.ref_name }}
36+
base_branch: ${{ github.ref_name }}
37+
pr_branch: update/${{ github.ref_name }}
3738

3839
steps:
3940
- name: Checkout repository
@@ -59,7 +60,7 @@ jobs:
5960
run: |
6061
# Query for info about the already open update PR
6162
info=$(
62-
gh api graphql -F owner='{owner}' -F repo='{repo}' -F branch="$branch" -f query='
63+
gh api graphql -F owner='{owner}' -F repo='{repo}' -F branch="$pr_branch" -f query='
6364
query($owner:String!, $repo:String!, $branch:String!) {
6465
repository(owner: $owner, name: $repo) {
6566
pullRequests(first: 1, states: OPEN, headRefName: $branch) {
@@ -98,8 +99,8 @@ jobs:
9899
fi
99100
100101
- name: Check if nixpkgs input was changed
101-
# The check is run only on scheduled runs & when there is a PR already open
102-
if: github.event_name == 'schedule' && steps.open_pr_info.outputs.number
102+
# The check is run only on scheduled runs
103+
if: github.event_name == 'schedule'
103104
env:
104105
pr_num: ${{ steps.open_pr_info.outputs.number }}
105106
pr_url: ${{ steps.open_pr_info.outputs.url }}
@@ -113,8 +114,15 @@ jobs:
113114
getNixpkgsRev() {
114115
getAttr "$1" 'inputs.nixpkgs.rev'
115116
}
116-
old=$(getNixpkgsRev "github:$repo/$branch")
117+
118+
if [[ -n "$pr_num" ]]; then
119+
old_branch=$pr_branch
120+
else
121+
old_branch=$base_branch
122+
fi
123+
old=$(getNixpkgsRev "github:$repo/$old_branch")
117124
new=$(getNixpkgsRev "$PWD")
125+
118126
if [[ "$old" = "$new" ]]; then
119127
(
120128
echo "nixpkgs rev has not changed ($new). Stopping..."
@@ -123,8 +131,13 @@ jobs:
123131
(
124132
echo '## Update cancelled'
125133
echo
126-
echo -n 'The `nixpkgs` input has not changed compared to the already open PR: '
127-
echo -n "[#$pr_num]($pr_url) (\`nixpkgs.rev: $new\`)."
134+
if [[ -n "$pr_num" ]]; then
135+
echo -n 'The `nixpkgs` input has not changed compared to the already open PR: '
136+
echo "[#$pr_num]($pr_url) (\`nixpkgs.rev: $new\`)."
137+
else
138+
echo -n 'The `nixpkgs` input has not changed compared to the base branch: '
139+
echo "\`$base_branch\`"
140+
fi
128141
echo
129142
echo 'The following changes would have been made:'
130143
echo '```'
@@ -165,7 +178,7 @@ jobs:
165178
uses: peter-evans/create-pull-request@v6
166179
with:
167180
add-paths: "!**"
168-
branch: update/${{ github.ref_name }}
181+
pr_branch: update/${{ github.ref_name }}
169182
delete-branch: true
170183
title: |
171184
[${{ github.ref_name }}] Update flake.lock & generated files

0 commit comments

Comments
 (0)