Skip to content

Commit

Permalink
ci/update: check whether a PR is already open
Browse files Browse the repository at this point in the history
  • Loading branch information
MattSturgeon committed Jan 24, 2025
1 parent 16f92ff commit f756250
Showing 1 changed file with 38 additions and 8 deletions.
46 changes: 38 additions & 8 deletions .github/workflows/update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 40
if: github.event_name != 'schedule' || github.repository == 'nix-community/nixvim'
env:
repo: ${{ github.repository }}
branch: update/${{ github.ref_name }}

steps:
- name: Checkout repository
Expand All @@ -49,6 +52,28 @@ jobs:
git config user.name 'github-actions[bot]'
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
- name: Get info on the current PR
id: open_pr_info
run: |
# Query for info about the already open update PR
# Sets `number` and `url` step outputs if a PR is open
gh api graphql -F owner='{owner}' -F repo='{repo}' -F branch="$branch" -f query='
query($owner:String!, $repo:String!, $branch:String!){
repository(owner: $owner, name: $repo) {
pullRequests(first: 1, states: OPEN, headRefName: $branch) {
nodes {
number
url
}
}
}
}
' | jq --raw-output '
.data.repository.pullRequests.nodes[]
| to_entries | map("\(.key)=\(.value)")
| .[]
' >> $GITHUB_OUTPUT
- name: Update flake.lock
id: flake_lock
if: inputs.lock || github.event_name == 'schedule'
Expand All @@ -63,10 +88,12 @@ jobs:
fi
- name: Check if nixpkgs input was changed
if: github.event_name == 'schedule'
# The check is run only on scheduled runs & when there is a PR already open
if: github.event_name == 'schedule' && steps.open_pr_info.outputs.number
env:
repo: ${{ github.repository }}
branch: update/${{ github.ref_name }}
pr_num: ${{ steps.open_pr_info.outputs.number }}
pr_url: ${{ steps.open_pr_info.outputs.url }}
changes: ${{ steps.flake_lock.outputs.body || 'No changes' }}
run: |
getAttr() {
nix eval --raw --impure \
Expand All @@ -76,10 +103,7 @@ jobs:
getNixpkgsRev() {
getAttr "$1" 'inputs.nixpkgs.rev'
}
old=$(
getNixpkgsRev "github:$repo/$branch" \
|| echo "" # Could fail, e.g. if the branch is deleted
)
old=$(getNixpkgsRev "github:$repo/$branch")
new=$(getNixpkgsRev "$PWD")
if [[ "$old" = "$new" ]]; then
(
Expand All @@ -89,7 +113,13 @@ jobs:
(
echo '## Update cancelled'
echo
echo 'The `nixpkgs` rev has not changed (`'"$new"'`).'
echo 'The `nixpkgs` rev has not changed (`'"$new"'`)'
echo "compared to the already open PR [#$pr_num]($pr_url)."
echo
echo 'The following changes would have been made:'
echo '```'
echo "$changes"
echo '```'
echo
echo 'You can re-run the workflow manually to update anyway.'
echo
Expand Down

0 comments on commit f756250

Please sign in to comment.