Skip to content

Commit bd3184f

Browse files
committed
ci/update: check whether a PR is already open
1 parent 16f92ff commit bd3184f

File tree

1 file changed

+48
-8
lines changed

1 file changed

+48
-8
lines changed

.github/workflows/update.yml

+48-8
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ jobs:
3131
runs-on: ubuntu-latest
3232
timeout-minutes: 40
3333
if: github.event_name != 'schedule' || github.repository == 'nix-community/nixvim'
34+
env:
35+
repo: ${{ github.repository }}
36+
branch: update/${{ github.ref_name }}
3437

3538
steps:
3639
- name: Checkout repository
@@ -49,6 +52,38 @@ jobs:
4952
git config user.name 'github-actions[bot]'
5053
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
5154
55+
- name: Get info on the current PR
56+
id: open_pr_info
57+
env:
58+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
59+
run: |
60+
# Query for info about the already open update PR
61+
info=$(
62+
gh api graphql -F owner='{owner}' -F repo='{repo}' -F branch="$branch" -f query='
63+
query($owner:String!, $repo:String!, $branch:String!){
64+
repository(owner: $owner, name: $repo) {
65+
pullRequests(first: 1, states: OPEN, headRefName: $branch) {
66+
nodes {
67+
number
68+
url
69+
}
70+
}
71+
}
72+
}
73+
' | jq --raw-output '
74+
.data.repository.pullRequests.nodes[]
75+
| to_entries | map("\(.key)=\(.value)")
76+
| .[]
77+
'
78+
)
79+
if [[ -n "$info" ]]; then
80+
echo "PR info:"
81+
echo "$info"
82+
echo "$info" >> $GITHUB_OUTPUT
83+
else
84+
echo "No PR is currently open"
85+
fi
86+
5287
- name: Update flake.lock
5388
id: flake_lock
5489
if: inputs.lock || github.event_name == 'schedule'
@@ -63,10 +98,12 @@ jobs:
6398
fi
6499
65100
- name: Check if nixpkgs input was changed
66-
if: github.event_name == 'schedule'
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
67103
env:
68-
repo: ${{ github.repository }}
69-
branch: update/${{ github.ref_name }}
104+
pr_num: ${{ steps.open_pr_info.outputs.number }}
105+
pr_url: ${{ steps.open_pr_info.outputs.url }}
106+
changes: ${{ steps.flake_lock.outputs.body || 'No changes' }}
70107
run: |
71108
getAttr() {
72109
nix eval --raw --impure \
@@ -76,10 +113,7 @@ jobs:
76113
getNixpkgsRev() {
77114
getAttr "$1" 'inputs.nixpkgs.rev'
78115
}
79-
old=$(
80-
getNixpkgsRev "github:$repo/$branch" \
81-
|| echo "" # Could fail, e.g. if the branch is deleted
82-
)
116+
old=$(getNixpkgsRev "github:$repo/$branch")
83117
new=$(getNixpkgsRev "$PWD")
84118
if [[ "$old" = "$new" ]]; then
85119
(
@@ -89,7 +123,13 @@ jobs:
89123
(
90124
echo '## Update cancelled'
91125
echo
92-
echo 'The `nixpkgs` rev has not changed (`'"$new"'`).'
126+
echo -n 'The `nixpkgs` rev has not changed (`'"$new"'`)'
127+
echo " compared to the already open PR [#$pr_num]($pr_url)."
128+
echo
129+
echo 'The following changes would have been made:'
130+
echo '```'
131+
echo "$changes"
132+
echo '```'
93133
echo
94134
echo 'You can re-run the workflow manually to update anyway.'
95135
echo

0 commit comments

Comments
 (0)