31
31
runs-on : ubuntu-latest
32
32
timeout-minutes : 40
33
33
if : github.event_name != 'schedule' || github.repository == 'nix-community/nixvim'
34
+ env :
35
+ repo : ${{ github.repository }}
36
+ branch : update/${{ github.ref_name }}
34
37
35
38
steps :
36
39
- name : Checkout repository
49
52
git config user.name 'github-actions[bot]'
50
53
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
51
54
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
+
52
87
- name : Update flake.lock
53
88
id : flake_lock
54
89
if : inputs.lock || github.event_name == 'schedule'
@@ -63,10 +98,12 @@ jobs:
63
98
fi
64
99
65
100
- 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
67
103
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' }}
70
107
run : |
71
108
getAttr() {
72
109
nix eval --raw --impure \
@@ -76,10 +113,7 @@ jobs:
76
113
getNixpkgsRev() {
77
114
getAttr "$1" 'inputs.nixpkgs.rev'
78
115
}
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")
83
117
new=$(getNixpkgsRev "$PWD")
84
118
if [[ "$old" = "$new" ]]; then
85
119
(
@@ -89,7 +123,13 @@ jobs:
89
123
(
90
124
echo '## Update cancelled'
91
125
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 '```'
93
133
echo
94
134
echo 'You can re-run the workflow manually to update anyway.'
95
135
echo
0 commit comments