-
Notifications
You must be signed in to change notification settings - Fork 99
Add Auto generate Connector Template #8440
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
Merged
TharmiganK
merged 13 commits into
ballerina-platform:connector-automation
from
nostoc:connector-automation
Nov 6, 2025
Merged
Changes from 12 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
aba6d76
Add connector automation source code
nostoc daf9c34
Update org name
nostoc e11d565
Implement the auto-generate-workflow partially
nostoc f5fb018
Add directory name extraction function and update example README gene…
nostoc 5f37395
Remove user confirmation prompt from full pipeline execution
nostoc 50e06fd
Add auto-generate connector workflow
nostoc b625e9a
Update doc generator to support relative paths
nostoc 3b7d332
Add auto generate connector template
nostoc b0f3cf3
Merge branch 'connector-automation' of https://github.com/nostoc/ball…
nostoc dc762e8
Merge branch 'connector-automation' of github.com:ballerina-platform/…
nostoc 5d7c4c9
Address PR review comments
nostoc afacee2
Remove auto-confirm input and simplify pipeline arguments in connecto…
nostoc 0234687
Remove unused inputs from auto-generate connector workflow and update…
nostoc 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,216 @@ | ||
| name: Auto-Generate Connector Template | ||
|
|
||
| on: | ||
| workflow_call: | ||
| inputs: | ||
| openapi-url: | ||
| description: "URL of the OpenAPI specification (JSON/YAML)" | ||
| required: false | ||
| type: string | ||
| ballerina-version: | ||
| description: "Ballerina version to use" | ||
| required: false | ||
| type: string | ||
| default: "nightly" | ||
| use-pipeline: | ||
| description: "Runs all steps of the connector generation process" | ||
| required: false | ||
| type: boolean | ||
| default: true | ||
| generation-path: | ||
| description: "Path where Ballerina client should be generated" | ||
| required: false | ||
| type: string | ||
| default: "ballerina" | ||
| license-file: | ||
| description: "Path to license file relative to docs directory" | ||
| required: false | ||
| type: string | ||
| default: "license.txt" | ||
| quiet-mode: | ||
| description: "Enable quiet mode" | ||
| required: false | ||
| type: boolean | ||
| default: true | ||
|
|
||
| jobs: | ||
| auto-generate: | ||
| name: Auto-generate connector | ||
| runs-on: ubuntu-22.04 | ||
| env: | ||
| ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} | ||
|
|
||
| steps: | ||
| - name: Checkout Repository | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| token: ${{ secrets.BALLERINA_BOT_TOKEN }} | ||
|
|
||
| - name: Setup Ballerina | ||
| uses: ballerina-platform/setup-ballerina@v1.1.3 | ||
| with: | ||
| version: ${{ inputs.ballerina-version }} | ||
|
|
||
| - name: Verify API Key | ||
| run: | | ||
| if [ -z "$ANTHROPIC_API_KEY" ]; then | ||
| echo "Error: ANTHROPIC_API_KEY secret is not set" | ||
| echo "AI-powered features require Claude API access" | ||
| echo "Please configure the ANTHROPIC_API_KEY secret in your repository and try again" | ||
| exit 1 | ||
| fi | ||
| echo "API key is configured" | ||
|
|
||
| - name: Clone Connector Automator | ||
| run: | | ||
| echo "Cloning connector automator tool from ballerina-library..." | ||
| git clone https://github.com/ballerina-platform/ballerina-library.git temp-library | ||
| cp -r temp-library/connector_automator ./ | ||
| rm -rf temp-library | ||
| echo "Connector automator cloned successfully" | ||
|
|
||
| - name: Download OpenAPI Specification | ||
| if: inputs.openapi-url | ||
| working-directory: docs/spec | ||
| run: | | ||
| echo "Downloading openapi spec from provided URL..." | ||
| if [[ "${{ inputs.openapi-url }}" == *.json ]]; then | ||
| rm -f openapi.json | ||
| wget -O openapi.json "${{ inputs.openapi-url }}" | ||
| elif [[ "${{ inputs.openapi-url }}" == *.yaml || "${{ inputs.openapi-url }}" == *.yml ]]; then | ||
| rm -f openapi.yaml openapi.yml | ||
| wget -O openapi.yaml "${{ inputs.openapi-url }}" | ||
| else | ||
| echo "Unsupported file extension: ${{ inputs.openapi-url }}" | ||
| exit 1 | ||
| fi | ||
|
|
||
| - name: Read File Extension | ||
| working-directory: docs/spec | ||
| run: | | ||
| file=$(echo openapi.*) | ||
| if [[ "$file" == "openapi.*" ]]; then | ||
| echo "Error: No OpenAPI specification found in docs/spec/" | ||
| echo "Either provide openapi-url input or commit a spec file to docs/spec/" | ||
| echo "Supported files: openapi.json, openapi.yaml, openapi.yml" | ||
| exit 1 | ||
| fi | ||
| ext="${file##*.}" | ||
| echo "EXTENSION=$ext" >> "$GITHUB_ENV" | ||
| echo "SPEC_FILE=$file" >> "$GITHUB_ENV" | ||
| echo "Found OpenAPI spec: $file" | ||
|
|
||
| - name: Create Branch | ||
| run: | | ||
| git checkout -b auto-generate-connector | ||
| echo "Created branch: auto-generate-connector" | ||
|
|
||
| - name: Run Full Connector Generation Pipeline | ||
| if: inputs.use-pipeline | ||
| run: | | ||
| cd connector_automator | ||
| SPEC_PATH="../docs/spec/${{ env.SPEC_FILE }}" | ||
| OUTPUT_PATH="../." | ||
|
|
||
| echo "Running full connector generation pipeline..." | ||
| echo "Spec path : $SPEC_PATH" | ||
| echo "Output path: $OUTPUT_PATH" | ||
|
|
||
| # Build pipeline arguments | ||
| PIPELINE_ARGS=("$SPEC_PATH" "$OUTPUT_PATH" "yes") | ||
|
|
||
| if [ "${{ inputs.quiet-mode }}" = "true" ]; then | ||
| PIPELINE_ARGS+=("quiet") | ||
| fi | ||
|
|
||
| # Run the complete pipeline | ||
| bal run -- pipeline "${PIPELINE_ARGS[@]}" | ||
|
|
||
| echo "Full connector generation pipeline completed" | ||
|
|
||
| - name: Cleanup and Organize Spec Files | ||
| run: | | ||
| cd docs/spec | ||
| echo "Cleaning up OpenAPI spec files..." | ||
|
|
||
| # List all files before cleanup | ||
| echo "Files before cleanup:" | ||
| ls -la | ||
|
|
||
| # Rename original spec to original_openapi.* | ||
| if [ -f "${{ env.SPEC_FILE }}" ]; then | ||
| mv "${{ env.SPEC_FILE }}" "original_openapi.${{ env.EXTENSION }}" | ||
| echo "Renamed ${{ env.SPEC_FILE }} to original_openapi.${{ env.EXTENSION }}" | ||
| fi | ||
|
|
||
| # Rename final aligned spec to openapi.json | ||
| if [ -f "aligned_ballerina_openapi.json" ]; then | ||
| mv "aligned_ballerina_openapi.json" "openapi.json" | ||
| echo "Renamed aligned_ballerina_openapi.json to openapi.json" | ||
| fi | ||
|
|
||
| # Remove intermediate files (flattened_openapi.*) | ||
| rm -f flattened_openapi.json flattened_openapi.yaml flattened_openapi.yml | ||
| echo "Removed intermediate flattened files" | ||
|
|
||
| # Remove any other aligned files if they exist | ||
| rm -f aligned_ballerina_openapi.yaml aligned_ballerina_openapi.yml | ||
| echo "Removed remaining aligned files" | ||
|
|
||
| # List files after cleanup | ||
| echo "Files after cleanup:" | ||
| ls -la | ||
|
|
||
| echo "OpenAPI spec file cleanup completed" | ||
|
|
||
| - name: Cleanup Connector Automator Tool | ||
| run: | | ||
| echo "Removing connector automator tool from repository..." | ||
| rm -rf connector_automator | ||
| echo "Connector automator tool removed" | ||
|
|
||
| - name: Configure Git Identity | ||
| run: | | ||
| git config user.name "ballerina-bot" | ||
| git config user.email "ballerina-bot@ballerina.org" | ||
|
|
||
| - name: Commit Generated Files | ||
| id: commitFiles | ||
| run: | | ||
| # Build commit message | ||
| COMMIT_MSG="[AUTOMATED] Auto-generate connector from OpenAPI spec | ||
|
|
||
| Complete connector generation using full pipeline with all components. | ||
| Generated using Ballerina with AI-powered automation." | ||
|
|
||
| # Add all changes | ||
| git add . | ||
|
|
||
| # Check if there are changes to commit | ||
| if git diff --cached --quiet; then | ||
| echo "hasChanged=false" >> $GITHUB_OUTPUT | ||
| echo "No changes to commit" | ||
| else | ||
| echo "$COMMIT_MSG" | git commit -F - | ||
| echo "hasChanged=true" >> $GITHUB_OUTPUT | ||
| echo "Changes committed successfully" | ||
| fi | ||
|
|
||
| - name: Push Results | ||
| if: ${{ steps.commitFiles.outputs.hasChanged == 'true' }} | ||
| run: git push origin auto-generate-connector | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.BALLERINA_BOT_TOKEN }} | ||
|
|
||
| - name: Create Pull Request | ||
| id: createPR | ||
| if: ${{ steps.commitFiles.outputs.hasChanged == 'true' }} | ||
| run: | | ||
| prUrl=$(gh pr create \ | ||
| --title "[Automated] Auto-generate connector from OpenAPI specification" \ | ||
| --body $'## Auto-Generated Connector from OpenAPI Specification\n\n**WARNING: This PR contains AI-generated content. Please review thoroughly before merging.**\n\n### Generation Details\n- **Generation Path**: `${{ inputs.generation-path }}`\n- **Ballerina Version**: ${{ inputs.ballerina-version }}\n- \n### Generated Components\n- Complete connector generation using full pipeline\n- All components: sanitization, client generation, examples generation, tests generation, documentation\n\n### AI Generation Disclaimer\nThis connector was generated using AI technology. Manual validation is essential to ensure correctness, security, and compatibility with the target API.\n\nPlease do not merge this PR without thorough review and testing.' \ | ||
| --base ${{ github.ref }} \ | ||
| --head auto-generate-connector) | ||
| echo "prUrl=$prUrl" >> $GITHUB_OUTPUT | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.BALLERINA_BOT_TOKEN }} | ||
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
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.
Uh oh!
There was an error while loading. Please reload this page.