Nova compatibility expansion #55
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
| name: Go Commit Checks | |
| on: | |
| pull_request: | |
| push: | |
| permissions: | |
| contents: read | |
| jobs: | |
| go-commit-checks: | |
| name: Go tests per commit | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.event.pull_request.head.sha || github.sha }} | |
| fetch-depth: 0 | |
| - name: Set up Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version-file: go.mod | |
| cache: true | |
| - name: Verify Go changes per commit | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| default_branch="${{ github.event.repository.default_branch }}" | |
| default_ref="origin/${default_branch}" | |
| git fetch \ | |
| --no-tags \ | |
| origin \ | |
| "+refs/heads/${default_branch}:refs/remotes/origin/${default_branch}" | |
| commit_exists() { | |
| git cat-file -e "$1^{commit}" 2>/dev/null | |
| } | |
| fallback_base() { | |
| local head="$1" | |
| if commit_exists "$default_ref"; then | |
| local merge_base | |
| merge_base="$(git merge-base "$default_ref" "$head" || true)" | |
| if [[ "$merge_base" != "$head" ]]; then | |
| echo "$merge_base" | |
| return | |
| fi | |
| fi | |
| if commit_exists "$head^"; then | |
| git rev-parse "$head^" | |
| return | |
| fi | |
| echo "" | |
| } | |
| if [[ "${{ github.event_name }}" == "pull_request" ]]; then | |
| base="${{ github.event.pull_request.base.sha }}" | |
| head="${{ github.event.pull_request.head.sha }}" | |
| else | |
| base="${{ github.event.before }}" | |
| head="${{ github.sha }}" | |
| fi | |
| if ! commit_exists "$head"; then | |
| echo "::error title=Missing head commit::$head is not available." | |
| exit 1 | |
| fi | |
| if [[ "$base" =~ ^0+$ ]]; then | |
| range_base="$(fallback_base "$head")" | |
| elif commit_exists "$base"; then | |
| range_base="$base" | |
| else | |
| echo "::warning title=Missing base commit::Falling back from $base." | |
| range_base="$(fallback_base "$head")" | |
| fi | |
| if [[ -n "$range_base" ]]; then | |
| commits="$(git rev-list --reverse "$range_base..$head")" | |
| else | |
| commits="$(git rev-list --reverse --max-count=1 "$head")" | |
| fi | |
| if [[ -z "$commits" ]]; then | |
| echo "No commits to verify." | |
| exit 0 | |
| fi | |
| for commit in $commits; do | |
| short_commit="$(git rev-parse --short "$commit")" | |
| subject="$(git log -1 --format=%s "$commit")" | |
| files="$(git diff-tree --no-commit-id --name-only -r "$commit")" | |
| if ! grep -Eq '(^go\.mod$|^go\.sum$|\.go$)' <<<"$files"; then | |
| echo "Skipping $short_commit: $subject" | |
| echo "No Go-relevant changes." | |
| continue | |
| fi | |
| echo "::group::Verifying $short_commit: $subject" | |
| git checkout --quiet "$commit" | |
| if ! go test ./...; then | |
| echo "::endgroup::" | |
| echo "::error title=Go tests failed::$short_commit $subject" | |
| exit 1 | |
| fi | |
| echo "::endgroup::" | |
| done |