From 2f37a60c534975f5be5bad58937cd42fb8f71029 Mon Sep 17 00:00:00 2001 From: Alex McKinney Date: Sun, 11 Feb 2024 22:07:41 -0800 Subject: [PATCH] Setup Go generator for monorepo (#2943) --- .github/dependabot.yml | 8 +- .github/workflows/go-generator.yml | 30 ++++ .github/workflows/publish-generator.yml | 148 ++++++++++++++++++ generators/go/.circleci/config.yml | 61 -------- .../go/.github/ISSUE_TEMPLATE/bug_report.md | 34 ---- generators/go/.github/dependabot.yml | 6 - generators/go/.github/workflows/ci.yml | 23 --- generators/go/CHANGELOG.md | 73 +++++++++ generators/go/VERSION | 1 + generators/go/version.go | 2 +- 10 files changed, 259 insertions(+), 127 deletions(-) create mode 100644 .github/workflows/go-generator.yml delete mode 100644 generators/go/.circleci/config.yml delete mode 100644 generators/go/.github/ISSUE_TEMPLATE/bug_report.md delete mode 100644 generators/go/.github/dependabot.yml delete mode 100644 generators/go/.github/workflows/ci.yml create mode 100644 generators/go/CHANGELOG.md create mode 100644 generators/go/VERSION diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 3a3cce5763e..2753a15d746 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -5,7 +5,11 @@ version: 2 updates: - - package-ecosystem: "npm" # See documentation for possible values - directory: "/" # Location of package manifests + - package-ecosystem: "npm" + directory: "/" + schedule: + interval: "weekly" + - package-ecosystem: "gomod" + directory: "/generators/go" schedule: interval: "weekly" diff --git a/.github/workflows/go-generator.yml b/.github/workflows/go-generator.yml new file mode 100644 index 00000000000..a95a38c6121 --- /dev/null +++ b/.github/workflows/go-generator.yml @@ -0,0 +1,30 @@ +name: go + +on: + pull_request: + paths: + - "generators/go/**" + branches: + - main + workflow_call: + +jobs: + compile: + runs-on: ubuntu-latest + steps: + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Compile + working-directory: ./generators/go + run: go build ./... + + test: + runs-on: ubuntu-latest + steps: + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Run Tests + working-directory: ./generators/go + run: make test diff --git a/.github/workflows/publish-generator.yml b/.github/workflows/publish-generator.yml index 3cd1afaad10..fe3df9c61a7 100644 --- a/.github/workflows/publish-generator.yml +++ b/.github/workflows/publish-generator.yml @@ -17,6 +17,7 @@ on: - "generators/java/spring/VERSION" - "generators/typescript/sdk/VERSION" - "generators/typescript/express/VERSION" + - "generators/go/VERSION" workflow_dispatch: inputs: generator: @@ -36,6 +37,9 @@ on: - java-spring - typescript-sdk - typescript-express + - go-sdk + - go-model + - go-fiber jobs: versions-changed: @@ -53,6 +57,9 @@ jobs: spring: ${{ steps.filter.outputs.spring }} ts-sdk: ${{ steps.filter.outputs.ts-sdk }} ts-express: ${{ steps.filter.outputs.ts-express }} + go-sdk: ${{ steps.filter.outputs.go-sdk }} + go-model: ${{ steps.filter.outputs.go-model }} + go-fiber: ${{ steps.filter.outputs.go-fiber }} steps: - uses: actions/checkout@v2 - uses: dorny/paths-filter@v2 @@ -71,6 +78,9 @@ jobs: spring: 'generators/java/spring/VERSION' ts-sdk: 'generators/typescript/sdk/VERSION' ts-express: 'generators/typescript/express/VERSION' + go-sdk: 'generators/go/VERSION' + go-model: 'generators/go/VERSION' + go-fiber: 'generators/go/VERSION' pydantic-model: runs-on: ubuntu-latest @@ -733,3 +743,141 @@ jobs: run: | yarn workspace @fern-typescript/sdk-generator-cli dockerTagVersion:node "$VERSION" docker push fernapi/fern-typescript-node-sdk:"$VERSION" + + go-sdk: + runs-on: ubuntu-latest + needs: versions-changed + if: ${{ needs.versions-changed.outputs.go-sdk == 'true' || inputs.generator == 'go-sdk' }} + steps: + - name: Checkout repo + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Log in to Docker Hub + uses: docker/login-action@v3 + with: + username: fernapi + password: ${{ secrets.FERN_API_DOCKERHUB_PASSWORD }} + + - name: Build CLI + working-directory: ./generators/go + run: go build ./... + + - name: Print Version + if: ${{ inputs.generator != 'go-sdk' }} + run: | + projectVersion=$(cat generators/go/VERSION) + echo $projectVersion + echo "VERSION=$projectVersion" >> $GITHUB_ENV + - name: Print Version Dev + if: ${{ inputs.generator == 'go-sdk' }} + run: | + projectVersion=$(cat generators/go/VERSION) + commitNumber=$(git log --oneline | wc -l ) + sha_short=$(git rev-parse --short HEAD) + echo $projectVersion-$commitNumber-$sha_short + echo "VERSION=$projectVersion-$commitNumber-$sha_short" >> $GITHUB_ENV + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Build and push Docker image + uses: docker/build-push-action@v2 + with: + context: ./generators/go + file: ./generators/go/docker/Dockerfile.sdk + platforms: linux/amd64,linux/arm64 + push: true + tags: fernapi/fern-go-sdk:${{env.VERSION}} + + go-model: + runs-on: ubuntu-latest + needs: versions-changed + if: ${{ needs.versions-changed.outputs.go-model == 'true' || inputs.generator == 'go-model' }} + steps: + - name: Checkout repo + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Log in to Docker Hub + uses: docker/login-action@v3 + with: + username: fernapi + password: ${{ secrets.FERN_API_DOCKERHUB_PASSWORD }} + + - name: Build CLI + working-directory: ./generators/go + run: go build ./... + + - name: Print Version + if: ${{ inputs.generator != 'go-model' }} + run: | + projectVersion=$(cat generators/go/VERSION) + echo $projectVersion + echo "VERSION=$projectVersion" >> $GITHUB_ENV + - name: Print Version Dev + if: ${{ inputs.generator == 'go-model' }} + run: | + projectVersion=$(cat generators/go/VERSION) + commitNumber=$(git log --oneline | wc -l ) + sha_short=$(git rev-parse --short HEAD) + echo $projectVersion-$commitNumber-$sha_short + echo "VERSION=$projectVersion-$commitNumber-$sha_short" >> $GITHUB_ENV + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Build and push Docker image + uses: docker/build-push-action@v2 + with: + context: ./generators/go + file: ./generators/go/docker/Dockerfile.model + platforms: linux/amd64,linux/arm64 + push: true + tags: fernapi/fern-go-model:${{env.VERSION}} + + go-fiber: + runs-on: ubuntu-latest + needs: versions-changed + if: ${{ needs.versions-changed.outputs.go-fiber == 'true' || inputs.generator == 'go-fiber' }} + steps: + - name: Checkout repo + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Log in to Docker Hub + uses: docker/login-action@v3 + with: + username: fernapi + password: ${{ secrets.FERN_API_DOCKERHUB_PASSWORD }} + + - name: Build CLI + working-directory: ./generators/go + run: go build ./... + + - name: Print Version + if: ${{ inputs.generator != 'go-fiber' }} + run: | + projectVersion=$(cat generators/go/VERSION) + echo $projectVersion + echo "VERSION=$projectVersion" >> $GITHUB_ENV + - name: Print Version Dev + if: ${{ inputs.generator == 'go-fiber' }} + run: | + projectVersion=$(cat generators/go/VERSION) + commitNumber=$(git log --oneline | wc -l ) + sha_short=$(git rev-parse --short HEAD) + echo $projectVersion-$commitNumber-$sha_short + echo "VERSION=$projectVersion-$commitNumber-$sha_short" >> $GITHUB_ENV + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Build and push Docker image + uses: docker/build-push-action@v2 + with: + context: ./generators/go + file: ./generators/go/docker/Dockerfile.fiber + platforms: linux/amd64,linux/arm64 + push: true + tags: fernapi/fern-go-fiber:${{env.VERSION}} diff --git a/generators/go/.circleci/config.yml b/generators/go/.circleci/config.yml deleted file mode 100644 index 5248a668d95..00000000000 --- a/generators/go/.circleci/config.yml +++ /dev/null @@ -1,61 +0,0 @@ -version: 2.1 - -jobs: - test: - machine: - image: ubuntu-2004:current - steps: - - checkout - - run: - name: Run tests - command: make test - - publish-dockers: - machine: - image: ubuntu-2004:current - steps: - - checkout - - run: - name: Setup Buildx - command: | - docker buildx create --name multiplatform --driver docker-container --bootstrap --use - - run: - name: Publish Model Docker - command: | - projectVersion=$(./scripts/git-version.sh) - echo "$FERNAPI_DOCKER_HUB_PASSWORD" | docker login --username fernapi --password-stdin - docker buildx build --platform linux/amd64,linux/arm64 -f ./docker/Dockerfile.model -t fernapi/fern-go-model:${projectVersion} . --push - - run: - name: Publish SDK Docker - command: | - projectVersion=$(./scripts/git-version.sh) - echo "$FERNAPI_DOCKER_HUB_PASSWORD" | docker login --username fernapi --password-stdin - docker buildx build --platform linux/amd64,linux/arm64 -f ./docker/Dockerfile.sdk -t fernapi/fern-go-sdk:${projectVersion} . --push - - run: - name: Publish Fiber Docker - command: | - projectVersion=$(./scripts/git-version.sh) - echo "$FERNAPI_DOCKER_HUB_PASSWORD" | docker login --username fernapi --password-stdin - docker buildx build --platform linux/amd64,linux/arm64 -f ./docker/Dockerfile.fiber -t fernapi/fern-go-fiber:${projectVersion} . --push - -workflows: - build: - jobs: - - test: - filters: - tags: - only: /.*/ - context: - - github - - publish-dockers: - filters: - branches: - only: main - tags: - only: - - /.*/ - requires: - - test - context: - - docker-hub - - github diff --git a/generators/go/.github/ISSUE_TEMPLATE/bug_report.md b/generators/go/.github/ISSUE_TEMPLATE/bug_report.md deleted file mode 100644 index a69e9f07d66..00000000000 --- a/generators/go/.github/ISSUE_TEMPLATE/bug_report.md +++ /dev/null @@ -1,34 +0,0 @@ ---- -name: Bug report -about: Create a report to help us improve -title: "[Bug]" -labels: '' -assignees: '' - ---- - -**Describe the bug** -A clear and concise description of what the bug is. - -**Fern Definition To Reproduce** -``` -# shape.yml - -types: - Shape: - union: - triangle: ... -``` - -**Expected behavior** - - -**Screenshots** -If applicable, add screenshots to help explain your problem. - -**Versioning:** - - Fern CLI: [e.g. iOS] - - Generator [e.g. chrome, safari] - -**Additional context** -Add any other context about the problem here. diff --git a/generators/go/.github/dependabot.yml b/generators/go/.github/dependabot.yml deleted file mode 100644 index 6f0493426ea..00000000000 --- a/generators/go/.github/dependabot.yml +++ /dev/null @@ -1,6 +0,0 @@ -version: 2 -updates: - - package-ecosystem: "gomod" # See documentation for possible values - directory: "/" # Location of package manifests - schedule: - interval: "weekly" diff --git a/generators/go/.github/workflows/ci.yml b/generators/go/.github/workflows/ci.yml deleted file mode 100644 index e70bf5d4587..00000000000 --- a/generators/go/.github/workflows/ci.yml +++ /dev/null @@ -1,23 +0,0 @@ -name: Dependabot auto-merge -on: pull_request - -permissions: - contents: write - pull-requests: write - -jobs: - dependabot: - runs-on: ubuntu-latest - if: ${{ github.actor == 'dependabot[bot]' }} - steps: - - name: Dependabot metadata - id: metadata - uses: dependabot/fetch-metadata@v1 - with: - github-token: "${{ secrets.GITHUB_TOKEN }}" - - name: Enable auto-merge for Dependabot PRs - if: ${{contains(steps.metadata.outputs.dependency-names, 'my-dependency') && steps.metadata.outputs.update-type == 'version-update:semver-patch'}} - run: gh pr merge --auto --merge "$PR_URL" - env: - PR_URL: ${{github.event.pull_request.html_url}} - GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} diff --git a/generators/go/CHANGELOG.md b/generators/go/CHANGELOG.md new file mode 100644 index 00000000000..d4ef540f203 --- /dev/null +++ b/generators/go/CHANGELOG.md @@ -0,0 +1,73 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + + + +## [0.15.0] - 2024-02-09 + +- Feature: Enforce RFC3339 for date[time] serialization in request bodies. + +## [0.14.1] - 2024-02-07 + +- Fix: Query parameter supoort for optional `time.Time` types. + +## [0.14.0] - 2024-02-06 + +- Feature: Add support for `deepObject` query parameters. +- Chore: Refactor query parameter serialization with `url` struct tags. + +## [0.13.0] - 2024-01-31 + +- Feature: Add `packageName` generator configuration. +- Feature: Add support for `bytes` request bodies wrapped in an in-lined request. + +## [0.12.1] - 2024-01-31 + +- Fix: `text/plain` response handling. + +## [0.12.0] - 2024-01-30 + +- Feature: Add support for `bytes` request bodies with `Content-Type` set to + `application/octet-stream`. + +## [0.11.0] - 2024-01-29 + +- Feature: Add automatic retry with exponential backoff. + +## [0.10.0] - 2024-01-25 + +- Feature: Refactor `ClientOption` as `RequestOption`. +- Feature: Add `includeLegacyClientOptions` generator configuration. +- Feature: Support idempotency headers as a special `RequestOption` only available on + idempotent endpoints. +- Fix: Placement of path parameter documentation. +- Fix: Naming collision issue for undiscriminated unions that define more than one + literal. + +## [0.9.4] - 2024-01-10 + +- Fix: File upload requests that specify query parameters. + +## [0.9.3] - 2023-12-04 + +- Fix: Optional query parameter dereferencing issue. + +## [0.9.2] - 2023-11-30 + +- Fix: Append version suffix for modules tagged with major versions greater than `1.X.X`. + +## [0.9.1] - 2023-11-08 + +- Fix: Support boolean literals. +- Fix: Union subt-ypes with no properties are now go 1.13 compatible. + +## [0.9.0] - 2023-10-31 + +- Feature: Add support for streaming endpoints. +- Feature: Add support for non-primitive file upload properties. +- Chore: Refactor `core.DoRequest` with `core.Caller` abstraction. +- Chore: Update pinned dependencies in generated `go.mod`. diff --git a/generators/go/VERSION b/generators/go/VERSION new file mode 100644 index 00000000000..a5510516948 --- /dev/null +++ b/generators/go/VERSION @@ -0,0 +1 @@ +0.15.0 diff --git a/generators/go/version.go b/generators/go/version.go index 7a144bf09e0..dc05f35203c 100644 --- a/generators/go/version.go +++ b/generators/go/version.go @@ -1,4 +1,4 @@ package fern // Version represents the current version of the fern-go generator. -const Version = "0.0.1" +const Version = "0.15.0"