Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@
# For syntax help see:
# https://help.github.com/en/github/creating-cloning-and-archiving-repositories/about-code-owners#codeowners-syntax

* @google/gnostic
* @castai/cast-cost
* @castai/cast-core
* @castai/cast-sec
17 changes: 0 additions & 17 deletions .github/sync-repo-settings.yaml

This file was deleted.

115 changes: 88 additions & 27 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,97 @@ name: Go

on:
push:
branches: [ main ]
branches: [main]
pull_request:
branches: [ main ]
branches: [main]

jobs:
concurrency:
group: ${{ github.workflow }}-${{ github.ref_name }}-${{ github.event.pull_request.number || 'branch' }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

jobs:
build:
name: Build
runs-on: ubuntu-22.04
name: Build and Test
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v6

- name: Set up Go
uses: actions/setup-go@v6
with:
go-version-file: go.mod
cache: true

- name: Install protoc
run: |
sudo apt-get update && sudo apt-get install -y protobuf-compiler
protoc --version

- name: Get dependencies
run: go get -v -t -d ./...

- name: Build
run: make all

- name: Lint
if: ${{ github.event_name == 'pull_request' }}
uses: golangci/golangci-lint-action@v9
with:
skip-cache: true
skip-save-cache: true
args: -v --timeout=5m

- name: Test
run: make test

verify-generated-resources:
name: Verify Generated Resources
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v6

- name: Set up Go
uses: actions/setup-go@v6
with:
go-version-file: go.mod
cache: true

- name: Install protoc
run: |
sudo apt-get update && sudo apt-get install -y protobuf-compiler
protoc --version

- name: Generate and format
run: |
go generate ./...
gofmt -w .

- name: Check for uncommitted generated changes
run: |
# Get list of changed files
CHANGED=$(git diff --name-only || true)
if [ -z "$CHANGED" ]; then
echo "Generated resources are up to date."
exit 0
fi

# For each changed file, check if changes are only protoc version comments
REAL_CHANGES=false
for file in $CHANGED; do
# Filter out diff headers (--- / +++), hunk markers (@@), and protoc version comment lines
DIFF=$(git diff -- "$file" | grep -E '^[+-]' | grep -vE '^[+-]{3} ' | grep -vE '^@@' | grep -vE '^[+-]//.*protoc' || true)
if [ -n "$DIFF" ]; then
echo "::error::Non-version-comment changes in $file"
echo "$DIFF"
REAL_CHANGES=true
fi
done

- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.13

- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Get protoc
run: |
sudo curl -L https://github.com/protocolbuffers/protobuf/releases/download/v3.15.0/protoc-3.15.0-linux-x86_64.zip > /tmp/protoc.zip
sudo unzip /tmp/protoc.zip -d /usr/local
sudo chown -R $USER /usr/local

- name: Get dependencies
run: go get -v -t -d ./...

- name: Build
run: make all

- name: Test
run: make test
if [ "$REAL_CHANGES" = true ]; then
echo "::error::Generated resources are out of date. Run 'go generate ./...' && gofmt -w . and commit the changes."
exit 1
else
echo "Generated resources are up to date (version-comment drift is acceptable)."
fi
56 changes: 56 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Release protoc-gen-openapi

on:
push:
tags:
- "cmd/protoc-gen-openapi/v*"

permissions:
contents: write

jobs:
release:
name: Release protoc-gen-openapi
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v6

- name: Set up Go
uses: actions/setup-go@v6
with:
go-version-file: go.mod
cache: true

- name: Extract version from tag
id: version
run: |
TAG="${GITHUB_REF#refs/tags/}"
VERSION="${TAG#cmd/protoc-gen-openapi/v}"
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"

- name: Build binaries
run: |
mkdir -p dist
VERSION=${{ steps.version.outputs.version }}
# linux amd64
GOOS=linux GOARCH=amd64 go build -o dist/protoc-gen-openapi-${VERSION}-linux-amd64 ./cmd/protoc-gen-openapi
# linux arm64
GOOS=linux GOARCH=arm64 go build -o dist/protoc-gen-openapi-${VERSION}-linux-arm64 ./cmd/protoc-gen-openapi
# darwin amd64
GOOS=darwin GOARCH=amd64 go build -o dist/protoc-gen-openapi-${VERSION}-darwin-amd64 ./cmd/protoc-gen-openapi
# darwin arm64
GOOS=darwin GOARCH=arm64 go build -o dist/protoc-gen-openapi-${VERSION}-darwin-arm64 ./cmd/protoc-gen-openapi

- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.version.outputs.tag }}
name: protoc-gen-openapi ${{ steps.version.outputs.version }}
generate_release_notes: true
files: |
dist/protoc-gen-openapi-${{ steps.version.outputs.version }}-linux-amd64
dist/protoc-gen-openapi-${{ steps.version.outputs.version }}-linux-arm64
dist/protoc-gen-openapi-${{ steps.version.outputs.version }}-darwin-amd64
dist/protoc-gen-openapi-${{ steps.version.outputs.version }}-darwin-arm64
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ bundle.json
*~
Package.resolved
extensions/sample/generated
cmd/protoc-gen-openapi/openapi.yaml
49 changes: 49 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
version: "2"

run:
timeout: 5m

linters:
default: none
enable:
- containedctx
- dogsled
- dupword
- durationcheck
- errorlint
- goprintffuncname
- misspell
- nakedret
- sqlclosecheck
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
paths:
- "third_party$"
- "builtin$"
- "examples$"
- "extensions/sample/generated"
- "jsonschema/base.go"

formatters:
enable:
- gci
- gofmt
settings:
gci:
sections:
- standard
- default
- prefix(github.com/google/gnostic)
exclusions:
generated: lax
paths:
- "third_party$"
- "builtin$"
- "examples$"
- "extensions/sample/generated"
- "jsonschema/base.go"
1 change: 0 additions & 1 deletion cmd/parse-linter-output/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,4 @@ func main() {
if *spectralPtr {
lint.LintSpectral(args[0])
}

}
7 changes: 4 additions & 3 deletions cmd/petstore-builder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@ func main() {
if i == 0 {
continue // skip the tool name
}
if arg == "--v2" {
switch arg {
case "--v2":
openAPIv2 = true
} else if arg == "--v3" {
case "--v3":
openAPIv3 = true
} else {
default:
fmt.Printf("Unknown option: %s.\n%s\n", arg, usage())
os.Exit(-1)
}
Expand Down
Loading