-
Notifications
You must be signed in to change notification settings - Fork 7
[CNSL-1930] Add automated OpenAPI spec sync workflow #108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
linhcrl
wants to merge
1
commit into
cockroachdb:main
Choose a base branch
from
linhcrl:ccapi-update
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| I need you to analyze the code changes in this SDK repository and update the CHANGELOG.md file. | ||
|
|
||
| Changes were made by syncing the OpenAPI spec from managed-service. | ||
|
|
||
| ## Environment Variables | ||
|
|
||
| The following environment variables are set. Read each one individually | ||
| using `printenv <VAR>` (one variable per command): | ||
|
|
||
| - MANAGED_SERVICE_PR_URL — The managed-service PR URL that triggered this sync | ||
| - MANAGED_SERVICE_SHA — (optional) The managed-service commit SHA if the PR was merged | ||
|
|
||
| ## Instructions | ||
|
|
||
| Please follow these steps: | ||
|
|
||
| 1. Use git diff to see all changes in the working tree | ||
| 2. Read the current CHANGELOG.md file to understand its existing structure | ||
| 3. Update CHANGELOG.md following Keep a Changelog conventions (https://keepachangelog.com/): | ||
| - Add all new entries under the [Unreleased] section | ||
| - For each change, choose the appropriate subsection: | ||
| - Added: for new features | ||
| - Changed: for changes in existing functionality | ||
| - Deprecated: for soon-to-be removed features | ||
| - Removed: for now removed features | ||
| - Fixed: for any bug fixes | ||
| - Security: in case of vulnerabilities | ||
| - If a subsection header (e.g., ### Added) does not exist under [Unreleased], create it | ||
| - If the subsection header already exists, add new entries at the top of that subsection | ||
| - Maintain the subsection order: Added, Changed, Deprecated, Removed, Fixed, Security | ||
| 4. For each change, determine if it's a breaking change for SDK consumers | ||
| 5. If a change is breaking, prefix that specific entry with "Breaking Change: " | ||
| 6. Write entries as bullet points using past tense (e.g., "Added X field", not "Add X field") | ||
|
|
||
| IMPORTANT: Only modify CHANGELOG.md. Do not modify any other files including generated code, spec files, or configuration files. | ||
|
|
||
| After updating CHANGELOG.md, you MUST output structured metadata in the following format. | ||
| This is critical - end your response with these exact markers: | ||
|
|
||
| ---COMMIT_TITLE--- | ||
| <one line commit title - keep it under 72 characters> | ||
| ---COMMIT_BODY--- | ||
| <multi-line commit body explaining the changes - wrap lines at 72 characters> | ||
|
|
||
| Managed-service-pr-url: $MANAGED_SERVICE_PR_URL | ||
| ---PR_TITLE--- | ||
| <one line PR title - keep it under 72 characters> | ||
| ---PR_DESCRIPTION--- | ||
| <multi-line PR description with summary and details> | ||
|
|
||
| IMPORTANT GUIDANCE FOR COMMIT AND PR TITLES: | ||
| - Describe the actual SDK/API changes from a user perspective | ||
| - NEVER write titles like "Update CHANGELOG.md" - the changelog update is just a side effect, not the main change | ||
| - If changes are focused on one area, describe that (e.g., "Add MFA audit log actions", "Update invoice field descriptions") | ||
| - If there are multiple unrelated changes that can't fit in 72 characters, use "Sync OpenAPI spec from managed-service" | ||
| - Focus on WHAT changed in the API/SDK, not the process of updating files | ||
|
|
||
| The commit body MUST include the trailer "Managed-service-pr-url: $MANAGED_SERVICE_PR_URL" exactly as shown. | ||
| Do not add any text after the PR description section. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| name: Sync OpenAPI Spec from Managed Service | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| inputs: | ||
| event_type: | ||
| description: 'Event type (openapi-spec-changed or openapi-spec-merged)' | ||
| required: true | ||
| type: choice | ||
| options: | ||
| - openapi-spec-changed | ||
| - openapi-spec-merged | ||
| pr_url: | ||
| description: 'Managed-service PR URL' | ||
| required: true | ||
| type: string | ||
| sha: | ||
| description: 'Managed-service commit SHA (required for merged events)' | ||
| required: false | ||
| type: string | ||
|
|
||
| # Required permissions for the workflow | ||
| permissions: | ||
| contents: write | ||
| pull-requests: write | ||
| id-token: write | ||
|
|
||
| jobs: | ||
| openapi-sync: | ||
| runs-on: ubuntu-latest | ||
| env: | ||
| EVENT_TYPE: ${{ github.event.inputs.event_type }} | ||
| MANAGED_SERVICE_PR_URL: ${{ github.event.inputs.pr_url }} | ||
| MANAGED_SERVICE_SHA: ${{ github.event.inputs.sha }} | ||
| MANAGED_SERVICE_TOKEN: ${{ secrets.MANAGED_SERVICE_TOKEN }} | ||
| FORK_OWNER: crl-gh-actions-pr-bot | ||
| FORK_PUSH_TOKEN: ${{ secrets.FORK_PUSH_TOKEN }} | ||
| CREATE_PR_TOKEN: ${{ github.token }} | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v6 | ||
| with: | ||
| fetch-depth: 0 | ||
| token: ${{ github.token }} | ||
| persist-credentials: false | ||
|
|
||
| - name: Set up Go | ||
| uses: actions/setup-go@v6 | ||
| with: | ||
| go-version-file: go.mod | ||
|
|
||
| - name: Authenticate to Google Cloud (Vertex AI) | ||
| uses: google-github-actions/auth@v3 | ||
| with: | ||
| project_id: vertex-model-runners | ||
| service_account: [email protected] | ||
| workload_identity_provider: projects/108106229451/locations/global/workloadIdentityPools/vertex-ai-user/providers/vertex-ai-user | ||
|
|
||
| - name: Run OpenAPI sync workflow | ||
| run: scripts/openapi-sync.sh |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| #!/usr/bin/env bash | ||
| # Find an SDK PR that corresponds to a managed-service PR URL. | ||
| # | ||
| # This searches all open PRs in the current repository and inspects | ||
| # all commits in each PR to find one containing a trailer: | ||
| # Managed-service-pr-url: <pr_url> | ||
| # | ||
| # Usage: | ||
| # find_sdk_pr <managed_service_pr_url> | ||
| # | ||
| # Exports on success: | ||
| # SDK_PR_NUMBER: The SDK PR number | ||
| # SDK_PR_BRANCH: The SDK PR branch name | ||
| # | ||
| # Returns: | ||
| # 0 if found, 1 if not found | ||
|
|
||
| # Get the script directory to find helper functions | ||
| LIB_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
| source "$LIB_DIR/logging.sh" | ||
|
|
||
| find_sdk_pr() { | ||
| local managed_service_pr_url="$1" | ||
|
|
||
| if [[ -z "${managed_service_pr_url:-}" ]]; then | ||
| log_error "managed_service_pr_url is required" | ||
| return 1 | ||
| fi | ||
|
|
||
| if [[ -z "${CREATE_PR_TOKEN:-}" ]]; then | ||
| log_error "CREATE_PR_TOKEN environment variable is not set" | ||
| return 1 | ||
| fi | ||
|
|
||
| if [[ -z "${GITHUB_REPOSITORY:-}" ]]; then | ||
| log_error "GITHUB_REPOSITORY environment variable is not set" | ||
| return 1 | ||
| fi | ||
|
|
||
| log_info "Searching for SDK PR corresponding to: $managed_service_pr_url" | ||
|
|
||
| export GH_TOKEN="$CREATE_PR_TOKEN" | ||
|
|
||
| # Get all open SDK PRs | ||
| local sdk_open_prs | ||
| sdk_open_prs=$(gh pr list --repo "$GITHUB_REPOSITORY" --state open --json number --jq '.[].number') | ||
|
|
||
| for sdk_pr_num in $sdk_open_prs; do | ||
| log_info "Checking SDK PR #$sdk_pr_num" | ||
|
|
||
| # Get all commits in this SDK PR | ||
| local sdk_commits | ||
| sdk_commits=$(gh api "repos/$GITHUB_REPOSITORY/pulls/$sdk_pr_num/commits" --jq '.[].sha') | ||
|
|
||
| # Check each commit's message for the trailer | ||
| for sdk_commit_sha in $sdk_commits; do | ||
| local sdk_commit_msg | ||
| sdk_commit_msg=$(gh api "repos/$GITHUB_REPOSITORY/git/commits/$sdk_commit_sha" --jq '.message') | ||
|
|
||
| if echo "$sdk_commit_msg" | grep --quiet --fixed-strings "Managed-service-pr-url: $managed_service_pr_url"; then | ||
| log_info "Found matching SDK PR #$sdk_pr_num (commit $sdk_commit_sha)" | ||
|
|
||
| # Get the SDK PR branch | ||
| local sdk_pr_branch | ||
| sdk_pr_branch=$(gh pr view "$sdk_pr_num" --repo "$GITHUB_REPOSITORY" --json headRefName --jq '.headRefName') | ||
|
|
||
| # Export results | ||
| export SDK_PR_NUMBER="$sdk_pr_num" | ||
| export SDK_PR_BRANCH="$sdk_pr_branch" | ||
| return 0 | ||
| fi | ||
| done | ||
| done | ||
|
|
||
| log_info "No matching SDK PR found" | ||
| return 1 | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| #!/usr/bin/env bash | ||
| # GIT_ASKPASS script for fork authentication. Reads credentials from | ||
| # environment variables so the token is never written to disk. | ||
| set -euo pipefail | ||
|
|
||
| # Get the script directory to find helper functions | ||
| LIB_DIR="$(cd "$(dirname "$0")" && pwd)" | ||
| source "$LIB_DIR/logging.sh" | ||
|
|
||
| if [ -z "$GIT_FORK_USER" ] || [ -z "$GIT_FORK_PASSWORD" ]; then | ||
| log_error "GIT_FORK_USER and GIT_FORK_PASSWORD must be set" | ||
| exit 1 | ||
| fi | ||
|
|
||
| case "$1" in | ||
| Username*) echo "$GIT_FORK_USER" ;; | ||
| Password*) echo "$GIT_FORK_PASSWORD" ;; | ||
| esac |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need to include the logging.sh? Or is it assumed to included by the invoking script already? If it's assumed we should probably check that it's available when this script is invoked and fail with a message in case someone tries to use it differently.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i decided to source in each file