2023-08-31 20:41:09 +00:00
|
|
|
# Checks pkgs/by-name (see pkgs/by-name/README.md)
|
|
|
|
# using the nixpkgs-check-by-name tool (see pkgs/test/nixpkgs-check-by-name)
|
2023-12-16 02:13:35 +00:00
|
|
|
#
|
|
|
|
# When you make changes to this workflow, also update pkgs/test/nixpkgs-check-by-name/scripts/run-local.sh adequately
|
2023-08-31 20:41:09 +00:00
|
|
|
name: Check pkgs/by-name
|
|
|
|
|
|
|
|
# The pre-built tool is fetched from a channel,
|
2023-09-11 12:02:06 +00:00
|
|
|
# making it work predictable on all PRs.
|
|
|
|
on:
|
|
|
|
# Using pull_request_target instead of pull_request avoids having to approve first time contributors
|
|
|
|
pull_request_target
|
2023-08-31 20:41:09 +00:00
|
|
|
|
2023-12-15 17:49:29 +00:00
|
|
|
permissions:
|
|
|
|
# We need this permission to cancel the workflow run if there's a merge conflict
|
|
|
|
actions: write
|
2023-08-31 20:41:09 +00:00
|
|
|
|
|
|
|
jobs:
|
|
|
|
check:
|
|
|
|
# This is x86_64-linux, for which the tool is always prebuilt on the nixos-* channels,
|
|
|
|
# as specified in nixos/release-combined.nix
|
|
|
|
runs-on: ubuntu-latest
|
2023-11-27 22:55:50 +00:00
|
|
|
# This should take 1 minute at most, but let's be generous.
|
|
|
|
# The default of 6 hours is definitely too long
|
|
|
|
timeout-minutes: 10
|
2023-08-31 20:41:09 +00:00
|
|
|
steps:
|
2023-12-16 02:02:33 +00:00
|
|
|
# This step has to be in this file,
|
|
|
|
# because it's needed to determine which revision of the repository to fetch,
|
|
|
|
# and we can only use other files from the repository once it's fetched.
|
2023-10-04 22:00:24 +00:00
|
|
|
- name: Resolving the merge commit
|
2023-10-17 23:12:06 +00:00
|
|
|
env:
|
|
|
|
GH_TOKEN: ${{ github.token }}
|
2023-10-04 22:00:24 +00:00
|
|
|
run: |
|
2023-10-17 23:12:06 +00:00
|
|
|
# This checks for mergeability of a pull request as recommended in
|
|
|
|
# https://docs.github.com/en/rest/guides/using-the-rest-api-to-interact-with-your-git-database?apiVersion=2022-11-28#checking-mergeability-of-pull-requests
|
2023-11-27 21:42:17 +00:00
|
|
|
|
|
|
|
# Retry the API query this many times
|
|
|
|
retryCount=3
|
|
|
|
# Start with 5 seconds, but double every retry
|
|
|
|
retryInterval=5
|
2023-10-17 23:12:06 +00:00
|
|
|
while true; do
|
|
|
|
echo "Checking whether the pull request can be merged"
|
|
|
|
prInfo=$(gh api \
|
|
|
|
-H "Accept: application/vnd.github+json" \
|
|
|
|
-H "X-GitHub-Api-Version: 2022-11-28" \
|
|
|
|
/repos/"$GITHUB_REPOSITORY"/pulls/${{ github.event.pull_request.number }})
|
|
|
|
mergeable=$(jq -r .mergeable <<< "$prInfo")
|
|
|
|
mergedSha=$(jq -r .merge_commit_sha <<< "$prInfo")
|
|
|
|
|
|
|
|
if [[ "$mergeable" == "null" ]]; then
|
2023-11-27 21:42:17 +00:00
|
|
|
if (( retryCount == 0 )); then
|
|
|
|
echo "Not retrying anymore, probably GitHub is having internal issues"
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
(( retryCount -= 1 )) || true
|
|
|
|
|
|
|
|
# null indicates that GitHub is still computing whether it's mergeable
|
|
|
|
# Wait a couple seconds before trying again
|
|
|
|
echo "GitHub is still computing whether this PR can be merged, waiting $retryInterval seconds before trying again ($retryCount retries left)"
|
|
|
|
sleep "$retryInterval"
|
|
|
|
|
|
|
|
(( retryInterval *= 2 )) || true
|
|
|
|
fi
|
2023-10-17 23:12:06 +00:00
|
|
|
else
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
if [[ "$mergeable" == "true" ]]; then
|
|
|
|
echo "The PR can be merged, checking the merge commit $mergedSha"
|
2023-10-04 22:00:24 +00:00
|
|
|
else
|
2023-12-15 17:49:29 +00:00
|
|
|
echo "The PR cannot be merged, it has a merge conflict, cancelling the workflow.."
|
|
|
|
gh api \
|
|
|
|
--method POST \
|
|
|
|
-H "Accept: application/vnd.github+json" \
|
|
|
|
-H "X-GitHub-Api-Version: 2022-11-28" \
|
|
|
|
/repos/"$GITHUB_REPOSITORY"/actions/runs/"$GITHUB_RUN_ID"/cancel
|
|
|
|
sleep 60
|
|
|
|
# If it's still not canceled after a minute, something probably went wrong, just exit
|
2023-10-04 22:00:24 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
echo "mergedSha=$mergedSha" >> "$GITHUB_ENV"
|
2023-11-28 03:28:58 +00:00
|
|
|
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
|
2023-09-11 12:02:06 +00:00
|
|
|
with:
|
|
|
|
# pull_request_target checks out the base branch by default
|
2023-10-04 22:00:24 +00:00
|
|
|
ref: ${{ env.mergedSha }}
|
2023-09-27 23:20:16 +00:00
|
|
|
# Fetches the merge commit and its parents
|
|
|
|
fetch-depth: 2
|
2023-12-16 02:13:35 +00:00
|
|
|
- name: Checking out base branch
|
2023-09-27 23:20:16 +00:00
|
|
|
run: |
|
2023-12-16 02:13:35 +00:00
|
|
|
base=$(mktemp -d)
|
|
|
|
git worktree add "$base" "$(git rev-parse HEAD^1)"
|
|
|
|
echo "base=$base" >> "$GITHUB_ENV"
|
2023-12-05 00:52:38 +00:00
|
|
|
- uses: cachix/install-nix-action@7ac1ec25491415c381d9b62f0657c7a028df52a7 # v24
|
2023-12-16 02:01:03 +00:00
|
|
|
- name: Fetching the tool
|
2024-01-16 17:30:21 +00:00
|
|
|
run: pkgs/test/nixpkgs-check-by-name/scripts/fetch-pinned-tool.sh result
|
2023-08-31 20:41:09 +00:00
|
|
|
- name: Running nixpkgs-check-by-name
|
2023-09-27 23:20:16 +00:00
|
|
|
run: |
|
2023-12-19 22:12:41 +00:00
|
|
|
if result/bin/nixpkgs-check-by-name --base "$base" .; then
|
2023-12-16 02:13:35 +00:00
|
|
|
exit 0
|
2023-09-27 23:20:16 +00:00
|
|
|
else
|
2023-12-16 02:13:35 +00:00
|
|
|
exitCode=$?
|
2023-12-21 22:09:50 +00:00
|
|
|
echo "To run locally: ./maintainers/scripts/check-by-name.sh $GITHUB_BASE_REF https://github.com/$GITHUB_REPOSITORY.git"
|
2023-12-16 02:13:35 +00:00
|
|
|
exit "$exitCode"
|
2023-09-27 23:20:16 +00:00
|
|
|
fi
|