Skip to content
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

Improve connector initialization workflow #6821

Merged
merged 3 commits into from
Aug 5, 2024
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
26 changes: 20 additions & 6 deletions .github/workflows/apply-library-repo-templates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,43 @@ on:
target_repo:
description: 'Target repository to apply the template'
required: true
example: 'module-ballerinax-github'
example: 'module-ballerinax-openai.chat'
module_name:
description: 'Module name of the connector'
description: 'Module name of the library used in Ballerina.toml'
required: true
example: 'github'
example: 'openai.chat'
ballerina_version:
description: 'Compatible Ballerina version to be used for the connector'
description: 'Compatible Ballerina version to be used for the library'
required: true
example: '2201.9.0'
module_version:
description: 'Connector version'
description: 'Library module version'
required: true
default: '0.1.0'
example: '1.0.0'
target_branch:
description: 'Target branch'
required: false
default: 'main'
library_name:
description: 'Descriptive name of the library to be used in the documentation (If not provided, module name will be used)'
required: false
example: 'OpenAI Chat'
default: ''

jobs:
apply_templates:
runs-on: ubuntu-latest
steps:
- name: Print Inputs
run: |
echo "Template Type: ${{ github.event.inputs.template_type }}"
echo "Target Repository: ${{ github.event.inputs.target_repo }}"
echo "Module Name: ${{ github.event.inputs.module_name }}"
echo "Ballerina Version: ${{ github.event.inputs.ballerina_version }}"
echo "Module Version: ${{ github.event.inputs.module_version }}"
echo "Target Branch: ${{ github.event.inputs.target_branch }}"
echo "Library Name: ${{ github.event.inputs.library_name }}"
- name: Checkout template repository
uses: actions/checkout@v3
with:
Expand All @@ -57,7 +71,7 @@ jobs:
run: |
cp -r template-repo/library-templates/generated-connector-template/files/* target-repo/
cd template-repo/library-templates/generated-connector-template/scripts/
bal run replace_placeholders.bal -- ../../../../target-repo/ ${{ github.event.inputs.module_name }} ${{ github.event.inputs.target_repo }} ${{ github.event.inputs.module_version }} ${{ github.event.inputs.ballerina_version }}
bal run replace_placeholders.bal -- ../../../../target-repo/ ${{ github.event.inputs.module_name }} ${{ github.event.inputs.target_repo }} ${{ github.event.inputs.module_version }} ${{ github.event.inputs.ballerina_version }} "${{ github.event.inputs.library_name }}"
cd ../../../../target-repo
git config user.name "ballerina-bot"
git config user.email "[email protected]"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

## Overview

//TODO: Add overview mentioning the purpose of the module, supported REST API versions, and other high-level details.
[//]: # (TODO: Add overview mentioning the purpose of the module, supported REST API versions, and other high-level details.)

## Setup guide

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ name = "{{MODULE_NAME_CC}}"
version = "{{MODULE_VERSION}}"
license = ["Apache-2.0"]
authors = ["Ballerina"]
keywords = [] // TODO: Add keywords
icon = "icon.png" // TODO: Add icon path
keywords = []
icon = "icon.png"
repository = "https://github.com/ballerina-platform/{{REPO_NAME}}"

[build-options]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Overview

//TODO: Add overview mentioning the purpose of the module, supported REST API versions, and other high-level details.
[//]: # (TODO: Add overview mentioning the purpose of the module, supported REST API versions, and other high-level details.)

## Setup guide

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Overview

//TODO: Add overview mentioning the purpose of the module, supported REST API versions, and other high-level details.
[//]: # (TODO: Add overview mentioning the purpose of the module, supported REST API versions, and other high-level details.)

## Setup guide

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ name = "{{MODULE_NAME_CC}}"
version = "@toml.version@"
license = ["Apache-2.0"]
authors = ["Ballerina"]
keywords = [] // TODO: Add keywords
icon = "icon.png" // TODO: Add icon path
keywords = [] # TODO: Add keywords
icon = "icon.png" # TODO: Add icon
repository = "https://github.com/ballerina-platform/{{REPO_NAME}}"

[build-options]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
_Author_: <!-- TODO: Add author name --> \
_Created_: <!-- TODO: Add date --> \
_Updated_: <!-- TODO: Add date --> \
_Edition_: Swan Lake

# Sanitation for OpenAPI specification

This document records the sanitation done on top of the official OpenAPI specification from {{MODULE_NAME_PC}}.
The OpenAPI specification is obtained from (TODO: Add source link).
These changes are done in order to improve the overall usability, and as workarounds for some known language limitations.

1.
2.
3.

## OpenAPI cli command

The following command was used to generate the Ballerina client from the OpenAPI specification. The command should be executed from the repository root directory.

```bash
# TODO: Add OpenAPI CLI command used to generate the client
```
Note: The license year is hardcoded to 2024, change if necessary.
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,18 @@ import ballerina/log;
import ballerina/time;

// Define the file extensions that are considered as template files
public type TemplateFileExt "bal"|"md"|"json"|"yaml"|"yml"|"toml"|"gradle"|"properties";
public type TemplateFileExt "bal"|"md"|"json"|"yaml"|"yml"|"toml"|"gradle"|"properties"|"gitignore";

public function main(string path, string moduleName, string repoName, string moduleVersion, string balVersion) returns error? {
public function main(string path, string moduleName, string repoName, string moduleVersion, string balVersion, string connectorName) returns error? {
log:printInfo("Generating connector template with the following metadata:");
log:printInfo("Module Name: " + moduleName);
log:printInfo("Repository Name: " + repoName);
log:printInfo("Module Version: " + moduleVersion);
log:printInfo("Ballerina Version: " + balVersion);
log:printInfo("Connector Name: " + connectorName);

map<string> placeholders = {
"MODULE_NAME_PC": moduleName[0].toUpperAscii() + moduleName.substring(1),
"MODULE_NAME_PC": connectorName == "" ? moduleName[0].toUpperAscii() + moduleName.substring(1) : connectorName,
"MODULE_NAME_CC": moduleName[0].toLowerAscii() + moduleName.substring(1),
"REPO_NAME": repoName,
"MODULE_VERSION": moduleVersion,
Expand Down Expand Up @@ -72,6 +73,7 @@ function processFile(string filePath, map<string> placeholders) returns error? {
}

check io:fileWriteString(filePath, content);
log:printInfo("Added file: " + filePath);
}

function getExtension(string filePath) returns string {
Expand Down
Loading