test: improve error handling in migration and tag rendering tests #221
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: CI | |
| permissions: | |
| contents: write | |
| on: | |
| push: | |
| branches: [ main ] | |
| tags: | |
| # Run on all tags except for release tags (e.g. v1.2.3) | |
| - '!v[0-9]+.[0-9]+.[0-9]+' | |
| pull_request: | |
| branches: [ main ] | |
| jobs: | |
| test: | |
| name: Run tests | |
| runs-on: ubuntu-latest | |
| env: | |
| KEYMASTER_DB_MAX_OPEN_CONNS: '1' | |
| KEYMASTER_DB_MAX_IDLE_CONNS: '1' | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Set up Go | |
| uses: actions/setup-go@v6 | |
| with: | |
| go-version: '1.25.5' | |
| - name: Cache Go modules | |
| uses: actions/cache@v5 | |
| with: | |
| path: | | |
| ~/.cache/go-build | |
| ~/go/pkg/mod | |
| key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} | |
| - name: Install tools | |
| run: | | |
| go install github.com/golang-migrate/migrate/v4/cmd/migrate@latest | |
| - name: Check formatting | |
| run: | | |
| echo 'Checking gofmt...' | |
| UNFORMATTED=$(gofmt -s -l .) | |
| if [ -n "${UNFORMATTED}" ]; then | |
| echo "gofmt found unformatted files:" && echo "$UNFORMATTED" | |
| exit 1 | |
| fi | |
| - name: Run golangci-lint | |
| uses: golangci/golangci-lint-action@v9 | |
| continue-on-error: true | |
| with: | |
| version: v1.59.0 | |
| # Use colored-line-number output. Excludes should be configured in .golangci.yml | |
| args: run ./... --out-format=colored-line-number | |
| - name: Static vet | |
| run: go vet ./... | |
| - name: Run tests (race on Linux) | |
| run: | | |
| echo "Running tests with race detector on Linux, fallback to non-race on other OS" | |
| if [ "${{ runner.os }}" = "Linux" ]; then | |
| sudo apt-get update && sudo apt-get install -y build-essential | |
| export CGO_ENABLED=1 | |
| go test ./... -v -race | |
| else | |
| go test ./... -v | |
| fi | |
| build: | |
| name: Build binary with version | |
| runs-on: ubuntu-latest | |
| needs: test | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Set up Go | |
| uses: actions/setup-go@v6 | |
| with: | |
| go-version: '1.25.5' | |
| - name: Compute version and git sha | |
| id: ver | |
| run: | | |
| echo "GITHUB_REF=${GITHUB_REF}" | |
| GIT_SHA=$(git rev-parse --short=8 HEAD) | |
| echo "git_sha=$GIT_SHA" >> $GITHUB_OUTPUT | |
| if [[ "${GITHUB_REF}" == refs/tags/* ]]; then | |
| TAG=${GITHUB_REF#refs/tags/} | |
| echo "tag=$TAG" >> $GITHUB_OUTPUT | |
| # Version string: <tag> (sha) | |
| VERSION="$TAG ($GIT_SHA)" | |
| else | |
| VERSION="$GIT_SHA" | |
| fi | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| - name: Build | |
| run: | | |
| echo "Building with version ${{ steps.ver.outputs.version }} (git ${GITHUB_SHA::8})" | |
| BUILD_DATE=$(date -u +%Y-%m-%dT%H:%M:%SZ) | |
| go build -ldflags "-X main.version='${{ steps.ver.outputs.version }}' -X main.gitCommit='${{ steps.ver.outputs.git_sha }}' -X main.buildDate='${BUILD_DATE}'" -o keymaster ./cmd/keymaster | |
| - name: Upload binary | |
| uses: actions/upload-artifact@v6 | |
| with: | |
| name: keymaster-${{ steps.ver.outputs.version }} | |
| path: keymaster |