go.yml•1.98 kB
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
name: Go tests and checks
on:
  pull_request:
    paths:
      - "go/**"
      - "genkit-tools/**"
      - ".github/workflows/go.yml"
jobs:
  tests:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        go-version: ['1.24.x']
    steps:
      - name: Checkout Repo
        uses: actions/checkout@main
      - uses: pnpm/action-setup@v3
      - name: Set up Node
        uses: actions/setup-node@v4
        with:
          node-version: 20.x
          cache: 'pnpm'
      - name: Enable corepack
        run: corepack enable
      - name: Install dependencies
        run: |
          pnpm install
          cd genkit-tools && pnpm install
      - name: Generate JSON Schema from Zod
        run: npm --prefix genkit-tools run export:schemas
      - name: Set up Go
        uses: actions/setup-go@main
        with:
          go-version: ${{ matrix.go-version }}
      - name: Check if generated code is up to date
        run: bash .github/workflows/scripts/check-generated-go.sh
      - name: Check gofmt
        run: |
          fmt_files=$(go fmt ./...)
          if [ -n "$fmt_files" ]; then
            echo "Go files are not formatted. Please run 'go fmt ./...' and commit the changes:"
            echo "$fmt_files"
            exit 1
          fi
        working-directory: ./go
      - name: Run tests
        run: go test -C go -v ./...