diff --git a/.gitea/workflows/ci.yaml b/.gitea/workflows/ci.yaml index 87ed59d..77001d9 100644 --- a/.gitea/workflows/ci.yaml +++ b/.gitea/workflows/ci.yaml @@ -59,6 +59,30 @@ jobs: git clone --depth=1 --branch "$REF_NAME" "$REPO_URL" . fi + # This exists because `go vet` does not look at import order: the move to + # git.ryuvia.com rewrote every import path without re-sorting, the new path sorts + # before github.com/..., and both repos sat unformatted through a green CI run and + # a release before anyone noticed. + # + # Both of gofmt's failure modes need handling, and they are not alike. A file that + # is merely misformatted is listed on stdout with exit 0 -- so the failure has to + # be raised by hand. A file that does not parse is the opposite: nothing on stdout + # and exit 2, which a naive `[ -n "$unformatted" ]` reads as success. The first + # draft of this step had exactly that hole. + - name: Format + run: | + if ! unformatted=$(gofmt -l .); then + echo "::error::gofmt could not parse the tree" + gofmt -l . # re-run unredirected so the parse errors reach the log + exit 1 + fi + if [ -n "$unformatted" ]; then + echo "::error::not gofmt'd:" + echo "$unformatted" + gofmt -d . + exit 1 + fi + - name: Vet run: go vet ./... diff --git a/.gitea/workflows/release.yaml b/.gitea/workflows/release.yaml index 7f56f32..14f0c87 100644 --- a/.gitea/workflows/release.yaml +++ b/.gitea/workflows/release.yaml @@ -41,6 +41,30 @@ jobs: REF_NAME: ${{ github.ref_name }} run: git clone --depth=1 --branch "$REF_NAME" "$REPO_URL" . + # This exists because `go vet` does not look at import order: the move to + # git.ryuvia.com rewrote every import path without re-sorting, the new path sorts + # before github.com/..., and both repos sat unformatted through a green CI run and + # a release before anyone noticed. + # + # Both of gofmt's failure modes need handling, and they are not alike. A file that + # is merely misformatted is listed on stdout with exit 0 -- so the failure has to + # be raised by hand. A file that does not parse is the opposite: nothing on stdout + # and exit 2, which a naive `[ -n "$unformatted" ]` reads as success. The first + # draft of this step had exactly that hole. + - name: Format + run: | + if ! unformatted=$(gofmt -l .); then + echo "::error::gofmt could not parse the tree" + gofmt -l . # re-run unredirected so the parse errors reach the log + exit 1 + fi + if [ -n "$unformatted" ]; then + echo "::error::not gofmt'd:" + echo "$unformatted" + gofmt -d . + exit 1 + fi + - name: Vet run: go vet ./...