Repository navigation
validate each pull request commit in ci #70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| base=${1:?Usage: fetch-validation-history.sh <base-sha>} | ||
| head=$(git rev-parse HEAD) | ||
|
|
||
| if ! git cat-file -e "$base^{commit}" 2>/dev/null; then | ||
| git fetch --no-tags --depth=1 origin "$base" | ||
| fi | ||
|
|
||
| base=$(git rev-parse "$base^{commit}") | ||
| shallow_file=$(git rev-parse --git-path shallow) | ||
|
|
||
| # Deepening is needed until no range commit can reach $base through unfetched history. | ||
| range_needs_deepening() { | ||
| [[ -s $shallow_file ]] || return 1 | ||
|
|
||
| local roots joins join | ||
| roots=$(git rev-list --max-parents=0 "$base..$head") || exit "$?" | ||
| [[ -z $roots ]] || return 0 | ||
|
|
||
| joins=$(git rev-list --boundary "$base..$head" | sed -n 's/^-//p') || exit "$?" | ||
| for join in $joins; do | ||
| roots=$(git rev-list --max-parents=0 "$base" --not "$join") || exit "$?" | ||
| [[ -z $roots ]] || return 0 | ||
| done | ||
| return 1 | ||
| } | ||
|
|
||
| deepen=8 | ||
| while range_needs_deepening; do | ||
| git fetch --no-tags --deepen="$deepen" origin "$head" "$base" | ||
| deepen=$((deepen * 2)) | ||
| done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,21 +1,34 @@ | ||
| name: Flake checks | ||
| on: | ||
| pull_request: | ||
| merge_group: | ||
| types: [checks_requested] | ||
| permissions: | ||
| actions: read # lets hestia detect evicted cache entries upfront | ||
| contents: read | ||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: true | ||
| jobs: | ||
| check: | ||
| validate-commits: | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 30 | ||
| env: | ||
| BASE_SHA: ${{ github.event.pull_request.base.sha || github.event.merge_group.base_sha }} | ||
|
yuval-block marked this conversation as resolved.
Resolved
|
||
| steps: | ||
| - name: Compute initial fetch depth | ||
| id: fetch-depth | ||
| env: | ||
| PR_COMMITS: ${{ github.event.pull_request.commits || 0 }} | ||
| run: echo "depth=$((PR_COMMITS + 2))" >> "$GITHUB_OUTPUT" | ||
| - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | ||
| with: | ||
| fetch-depth: ${{ steps.fetch-depth.outputs.depth }} | ||
| - name: Fetch validation history | ||
| run: bash .github/scripts/fetch-validation-history.sh "$BASE_SHA" | ||
| - uses: DeterminateSystems/nix-installer-action@3138316df39ed29be04236d7ffc686fa525866aa # v23 | ||
| - uses: Mic92/hestia@dfed9ced335d28978ba74e513939a10db1f71025 # v3.1.0 | ||
| with: | ||
| # Do not upload paths that cache.nixos.org already serves. | ||
| upstream-cache-filter: true | ||
| - run: nix flake check --no-update-lock-file | ||
| - name: Validate commits | ||
| run: nix run --no-update-lock-file '.?shallow=1#validate-commits' -- "$BASE_SHA..HEAD" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ | |
| ./nix/site.nix | ||
| ./nix/devshell.nix | ||
| ./nix/spellcheck.nix | ||
| ./nix/apps/validate-commits | ||
| ]; | ||
| }; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| { | ||
| perSystem = | ||
| { pkgs, ... }: | ||
| let | ||
| validate-commits = pkgs.writeShellApplication { | ||
| name = "validate-commits"; | ||
| runtimeInputs = [ | ||
| pkgs.git | ||
| pkgs.nix | ||
| ]; | ||
| text = builtins.readFile ./validate-commits.sh; | ||
| }; | ||
| in | ||
| { | ||
| packages.validate-commits = validate-commits; | ||
| apps.validate-commits = { | ||
| type = "app"; | ||
| program = "${validate-commits}/bin/validate-commits"; | ||
| meta.description = "Validate the flake across pull request commits"; | ||
| }; | ||
| }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| usage() { | ||
| echo "Usage: validate-commits <revision-range>" | ||
| } | ||
|
|
||
| if [[ ${1:-} == --help ]]; then | ||
| usage | ||
| exit 0 | ||
| fi | ||
|
|
||
| if [[ $# -ne 1 ]]; then | ||
| usage >&2 | ||
| exit 2 | ||
| fi | ||
|
|
||
| repo_root=$(git rev-parse --show-toplevel) | ||
| revision_range=$1 | ||
| commits=$(git rev-list --reverse "$revision_range") | ||
|
|
||
| if [[ -z $commits ]]; then | ||
| echo "No commits in range." | ||
| exit 0 | ||
| fi | ||
|
|
||
| while read -r commit; do | ||
| echo "Validating $commit" | ||
| nix flake check --no-update-lock-file --print-build-logs \ | ||
| "git+file://$repo_root?rev=$commit&shallow=1" | ||
| done <<<"$commits" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.