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
57 changes: 49 additions & 8 deletions .github/workflows/update-and-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ on:
repository_dispatch:
types: [update-sdk]
workflow_dispatch:
inputs:
force_release:
description: "Create a release from the current HEAD even if OPENAPI_VERSION did not change."
required: false
type: boolean
default: false
release_version:
description: "Required when force_release is true. Example: 1.45.2"
required: false
type: string

jobs:
update-and-release:
Expand Down Expand Up @@ -53,16 +63,36 @@ jobs:
- name: Compare versions
id: compare
run: |
if [ "${{ steps.fetch-version.outputs.new_version }}" = "${{ steps.current-version.outputs.current_version }}" ]; then
FORCE_RELEASE="${{ github.event_name == 'workflow_dispatch' && inputs.force_release || 'false' }}"
RELEASE_VERSION="${{ inputs.release_version }}"
SWAGGER_VERSION="${{ steps.fetch-version.outputs.new_version }}"
CURRENT_VERSION="${{ steps.current-version.outputs.current_version }}"

if [ "$FORCE_RELEASE" = "true" ]; then
if [ -z "$RELEASE_VERSION" ]; then
echo "release_version is required when force_release is true" >&2
exit 1
fi
echo "needs_update=true" >> "$GITHUB_OUTPUT"
echo "target_version=$RELEASE_VERSION" >> "$GITHUB_OUTPUT"
echo "commit_message=chore: release CLI $RELEASE_VERSION" >> "$GITHUB_OUTPUT"
echo "force_release=true" >> "$GITHUB_OUTPUT"
echo "Manual release requested: $RELEASE_VERSION"
elif [ "$SWAGGER_VERSION" = "$CURRENT_VERSION" ]; then
echo "needs_update=false" >> "$GITHUB_OUTPUT"
echo "target_version=$CURRENT_VERSION" >> "$GITHUB_OUTPUT"
echo "force_release=false" >> "$GITHUB_OUTPUT"
echo "Versions match. No update needed."
else
echo "needs_update=true" >> "$GITHUB_OUTPUT"
echo "Version changed: ${{ steps.current-version.outputs.current_version }} -> ${{ steps.fetch-version.outputs.new_version }}"
echo "target_version=$SWAGGER_VERSION" >> "$GITHUB_OUTPUT"
echo "commit_message=chore: update CLI to API version $SWAGGER_VERSION" >> "$GITHUB_OUTPUT"
echo "force_release=false" >> "$GITHUB_OUTPUT"
echo "Version changed: $CURRENT_VERSION -> $SWAGGER_VERSION"
fi

- name: Generate client and docs
if: steps.compare.outputs.needs_update == 'true'
if: steps.compare.outputs.needs_update == 'true' && steps.compare.outputs.force_release != 'true'
run: |
chmod +x ./scripts/generate-client.sh
./scripts/generate-client.sh
Expand All @@ -78,24 +108,35 @@ jobs:
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"

- name: Commit changes
- name: Detect generated changes
if: steps.compare.outputs.needs_update == 'true'
id: changes
run: |
if git diff --quiet; then
echo "has_changes=false" >> "$GITHUB_OUTPUT"
echo "No working tree changes to commit."
else
echo "has_changes=true" >> "$GITHUB_OUTPUT"
echo "Working tree changes detected."
fi

- name: Commit changes
if: steps.compare.outputs.needs_update == 'true' && steps.changes.outputs.has_changes == 'true'
run: |
NEW_VERSION="${{ steps.fetch-version.outputs.new_version }}"
git add .
git commit -m "chore: update CLI to API version $NEW_VERSION"
git commit -m "${{ steps.compare.outputs.commit_message }}"

- name: Create and push tag
if: steps.compare.outputs.needs_update == 'true'
run: |
NEW_VERSION="${{ steps.fetch-version.outputs.new_version }}"
NEW_VERSION="${{ steps.compare.outputs.target_version }}"
git tag "v$NEW_VERSION"
git push origin main
git push origin "v$NEW_VERSION"

- name: Checkout tag for release
if: steps.compare.outputs.needs_update == 'true'
run: git checkout "v${{ steps.fetch-version.outputs.new_version }}"
run: git checkout "v${{ steps.compare.outputs.target_version }}"

- name: Run GoReleaser
if: steps.compare.outputs.needs_update == 'true'
Expand Down
51 changes: 51 additions & 0 deletions internal/client/generated/model_list_links_response_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package linkbreakers

import (
"encoding/json"
"testing"
)

func TestListLinksResponseUnmarshalJSONAcceptsStringTotalCount(t *testing.T) {
var resp ListLinksResponse

err := json.Unmarshal([]byte(`{
"links": [],
"nextPageToken": "cursor_123",
"totalCount": "42"
}`), &resp)
if err != nil {
t.Fatalf("unexpected unmarshal error: %v", err)
}

if resp.TotalCount == nil {
t.Fatal("expected totalCount to be set")
}

if got := *resp.TotalCount; got != 42 {
t.Fatalf("expected totalCount 42, got %d", got)
}

if got := resp.GetNextPageToken(); got != "cursor_123" {
t.Fatalf("expected nextPageToken cursor_123, got %q", got)
}
}

func TestListLinksResponseUnmarshalJSONAcceptsNumericTotalCount(t *testing.T) {
var resp ListLinksResponse

err := json.Unmarshal([]byte(`{
"links": [],
"totalCount": 7
}`), &resp)
if err != nil {
t.Fatalf("unexpected unmarshal error: %v", err)
}

if resp.TotalCount == nil {
t.Fatal("expected totalCount to be set")
}

if got := *resp.TotalCount; got != 7 {
t.Fatalf("expected totalCount 7, got %d", got)
}
}