name: Backend CI on: push: branches: [main] paths: - 'server/**' - '.gitea/workflows/backend.yml' pull_request: branches: [main] paths: - 'server/**' - '.gitea/workflows/backend.yml' env: GO_VERSION: '1.21' jobs: lint: name: Lint runs-on: ubuntu-latest steps: - name: Checkout code uses: https://github.com/actions/checkout@v4 - name: Setup Go uses: https://github.com/actions/setup-go@v5 with: go-version: ${{ env.GO_VERSION }} cache: false - name: Tidy modules working-directory: ./server run: go mod tidy - name: Install golangci-lint run: | curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.59.0 - name: Download dependencies working-directory: ./server run: go mod download - name: Run linter working-directory: ./server run: | $(go env GOPATH)/bin/golangci-lint run ./... --timeout=5m build: name: Build needs: lint runs-on: ubuntu-latest steps: - name: Checkout code uses: https://github.com/actions/checkout@v4 - name: Setup Go uses: https://github.com/actions/setup-go@v5 with: go-version: ${{ env.GO_VERSION }} cache: false - name: Tidy modules working-directory: ./server run: go mod tidy - name: Download dependencies working-directory: ./server run: go mod download - name: Build binary working-directory: ./server run: | CGO_ENABLED=0 go build -o chat-switchboard-api -ldflags "-s -w" test: name: Test needs: build runs-on: ubuntu-latest steps: - name: Checkout code uses: https://github.com/actions/checkout@v4 - name: Setup Go uses: https://github.com/actions/setup-go@v5 with: go-version: ${{ env.GO_VERSION }} cache: false - name: Tidy modules working-directory: ./server run: go mod tidy - name: Download dependencies working-directory: ./server run: go mod download - name: Run tests working-directory: ./server run: | go test -v -cover -coverprofile=coverage.out ./... EXIT_CODE=$? echo "EXIT_CODE=$EXIT_CODE" >> $GITHUB_ENV - name: Fail if tests failed if: env.EXIT_CODE != '0' run: exit 1