| 1 | #!/usr/bin/env -S nix shell --inputs-from . nixpkgs#bash nixpkgs#git-absorb --command bash |
| 2 | # shellcheck shell=bash |
| 3 | set -euo pipefail |
| 4 | |
| 5 | # This script runs nix fmt and git absorb to update a pull request |
| 6 | # It's designed to be run in a GitHub Actions workflow |
| 7 | |
| 8 | echo "::group::Running nix fmt" |
| 9 | nix fmt |
| 10 | echo "::endgroup::" |
| 11 | |
| 12 | echo "::group::Checking for changes" |
| 13 | if git diff --quiet; then |
| 14 | echo "No formatting changes needed" |
| 15 | exit 0 |
| 16 | fi |
| 17 | echo "::endgroup::" |
| 18 | |
| 19 | echo "::group::Running git absorb" |
| 20 | # Run git absorb with --force to automatically absorb changes |
| 21 | git add -A |
| 22 | # Create fixup commits |
| 23 | # Find the merge base to properly identify which commits can absorb changes |
| 24 | MERGE_BASE=$(git merge-base origin/main HEAD) |
| 25 | git absorb --force --base "$MERGE_BASE" |
| 26 | # Then do a non-interactive autosquash rebase with git identity set |
| 27 | export GIT_EDITOR=: |
| 28 | export GIT_SEQUENCE_EDITOR=: |
| 29 | export GIT_AUTHOR_NAME="github-actions[bot]" |
| 30 | export GIT_AUTHOR_EMAIL="github-actions[bot]@users.noreply.github.com" |
| 31 | export GIT_COMMITTER_NAME="github-actions[bot]" |
| 32 | export GIT_COMMITTER_EMAIL="github-actions[bot]@users.noreply.github.com" |
| 33 | git rebase -i --autosquash origin/main |
| 34 | echo "::endgroup::" |
| 35 | |
| 36 | echo "::group::Pushing changes" |
| 37 | git push --force-with-lease |
| 38 | echo "::endgroup::" |
| 39 | |
| 40 | echo "Successfully formatted code and absorbed changes!" |