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

Add a github workflow to regenerate and build all the workflows #809

Closed
wants to merge 8 commits into from
Closed
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
53 changes: 53 additions & 0 deletions .github/workflows/test-connectors.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Regenerate Connectors

on:
# # Run nightly at 2:00 AM
# schedule:
# - cron: '0 2 * * *'
# Trigger manually with specified Ballerina Docker version
workflow_dispatch:
inputs:
bal_docker_version:
description: Ballerina Docker version
required: true
default: 'nightly'
client_method:
description: Expected Client Method Type
required: true
default: 'remote'
options: ['remote', 'resource']

jobs:
# regenerate_connectors_with_nightly:
# if: github.event_name == 'schedule'
# runs-on: ubuntu-latest
# container:
# image: ballerina/ballerina:nightly
# options: --user root
# steps:
# - name: Checkout code
# uses: actions/checkout@v2

# - name: Build with Gradle
# env:
# JAVA_OPTS: -DBALLERINA_DEV_COMPILE_BALLERINA_ORG=true
# GRADLE_USER_HOME: ~/.gradle
# run: |
# ./gradlew build -PtestConnectorGeneration=true -PclientMethod=${{ github.event.inputs.client_method }}

regenerate_connectors_with_specified_version:
if: github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
container:
image: ballerina/ballerina:${{ github.event.inputs.bal_docker_version }}
options: --user root
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Build with Gradle
env:
JAVA_OPTS: -DBALLERINA_DEV_COMPILE_BALLERINA_ORG=true
GRADLE_USER_HOME: ~/.gradle
run: |
./gradlew build -PtestConnectorGeneration=true -PclientMethod=${{ github.event.inputs.client_method }}
71 changes: 70 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ boolean release = false;
boolean remote = false;
boolean buildAll = false;
boolean testTool = false;
boolean testConnectorGeneration = false;
String clientMethod = "remote";

if (project.hasProperty("remote")){
remote = new Boolean(project.property("remote").toString())
}
Expand All @@ -36,6 +39,12 @@ if (project.hasProperty("buildAll")){
if (project.hasProperty("testTool")){
testTool = new Boolean(project.property("testTool").toString())
}
if (project.hasProperty("testConnectorGeneration")){
testConnectorGeneration = new Boolean(project.property("testConnectorGeneration").toString())
}
if (project.hasProperty("clientMethod")){
clientMethod = new String(project.property("clientMethod").toString())
}

String toolTestsDirPath = project.projectDir.absolutePath + "/tool-tests";
List<String> toolTestPackages = new ArrayList<>();
Expand All @@ -50,7 +59,7 @@ if (buildAll){
}

task codeBuild {
if (!testTool) {
if (!testTool && !testConnectorGeneration) {
println "Task: Building connectors..."
for (String path : updatedBallerinaPackages) {
Utils.executePrechecks(path);
Expand Down Expand Up @@ -151,3 +160,63 @@ task testOpenAPITool {
}
}
}

task generateNbuildLatestOpenAPIConnectors {
if (testConnectorGeneration) {
println "Task: Re-generate and build connectors..."
def generationFailedConnectors = [] // List to store generation failed connectors
def compilationFailedConnectors = [] // List to store compilation failed connectors

for (String path : ballerinaPackages) {
println "----- Connector : " + path
try {
exec {
commandLine 'sh', '-c', "${ballerinaDistributionPath}/bin/bal openapi -i openapi.* --mode client --client-methods ${clientMethod}"
workingDir(path)
}
println "Connector generation is successful for " + path
} catch (Exception genEx) {
println "Failed to re-generate the connector [" + path + "]. Error : " + genEx.toString()
generationFailedConnectors << path // Add the failed connector to the list
continue
}

try {
exec {
commandLine 'sh', '-c', "${ballerinaDistributionPath}/bin/bal pack ${path}"
}
println "bal pack success for " + path
} catch (Exception buildEx) {
println "Failed to build the re-generate the connector [" + path + "]. Error : " + buildEx.toString()
compilationFailedConnectors << path // Add the failed connector to the list
}
}

// Print summary of re-generation failed connectors
if (generationFailedConnectors.size() > 0) {
println "Summary: ${generationFailedConnectors.size()} connectors failed re-generation:"
generationFailedConnectors.each { connector ->
println "- $connector"
}
}

// Print summary of compilation failed connectors
if (compilationFailedConnectors.size() > 0) {
println "Summary: ${compilationFailedConnectors.size()} connectors failed compilation:"
compilationFailedConnectors.each { connector ->
println "- $connector"
}
}

if (generationFailedConnectors.size() > 0 || compilationFailedConnectors.size() > 0) {
// Throw an exception to fail the build
throw new GradleException("${generationFailedConnectors.size()} connectors failed regeneration & " +
"${compilationFailedConnectors.size()} connectors failed compilation. See the summary above.")

}

if (generationFailedConnectors.size() == 0 && compilationFailedConnectors.size() == 0) {
println "All connectors executed successfully."
}
}
}