Skip to content

Commit

Permalink
Add build flows
Browse files Browse the repository at this point in the history
  • Loading branch information
aneeshafedo committed Aug 7, 2023
1 parent 77c1e74 commit 4e96afd
Show file tree
Hide file tree
Showing 10 changed files with 231 additions and 373 deletions.
69 changes: 69 additions & 0 deletions .github/workflows/cli-central-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Publish OpenAPI CLI tools to the Ballerina central

on:
workflow_dispatch:
inputs:
environment:
type: choice
description: Select environment
required: true
options:
- CENTRAL
- DEV CENTRAL
- STAGE CENTRAL

jobs:
publish-release:
runs-on: ubuntu-latest
if: github.repository_owner == 'ballerina-platform'
steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v2
with:
distribution: 'adopt'
java-version: 11
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
env:
packageUser: ${{ github.actor }}
packagePAT: ${{ secrets.GITHUB_TOKEN }}
run: ./gradlew build -x check -x test
- name: Ballerina Central Push
if: ${{ github.event.inputs.environment == 'CENTRAL' }}
env:
BALLERINA_DEV_CENTRAL: false
BALLERINA_STAGE_CENTRAL: false
BALLERINA_CENTRAL_ACCESS_TOKEN: ${{ secrets.BALLERINA_CENTRAL_ACCESS_TOKEN }}
packageUser: ${{ secrets.BALLERINA_BOT_USERNAME }}
packagePAT: ${{ secrets.BALLERINA_BOT_TOKEN }}
GITHUB_TOKEN: ${{ secrets.BALLERINA_BOT_TOKEN }}
run: |
./gradlew clean build :tool-openapi:publishToCentral -PpublishToCentral=true
- name: Ballerina Central Dev Push
if: ${{ github.event.inputs.environment == 'DEV CENTRAL' }}
env:
BALLERINA_DEV_CENTRAL: true
BALLERINA_STAGE_CENTRAL: false
BALLERINA_CENTRAL_ACCESS_TOKEN: ${{ secrets.BALLERINA_CENTRAL_DEV_ACCESS_TOKEN }}
packageUser: ${{ secrets.BALLERINA_BOT_USERNAME }}
packagePAT: ${{ secrets.BALLERINA_BOT_TOKEN }}
GITHUB_TOKEN: ${{ secrets.BALLERINA_BOT_TOKEN }}
run: |
sed -i 's/version=\(.*\)-SNAPSHOT/version=\1/g' gradle.properties
./gradlew clean build :tool-openapi:publishToCentral -PpublishToCentral=true
- name: Ballerina Central Stage Push
if: ${{ github.event.inputs.environment == 'STAGE CENTRAL' }}
env:
BALLERINA_DEV_CENTRAL: false
BALLERINA_STAGE_CENTRAL: true
BALLERINA_CENTRAL_ACCESS_TOKEN: ${{ secrets.BALLERINA_CENTRAL_STAGE_ACCESS_TOKEN }}
packageUser: ${{ secrets.BALLERINA_BOT_USERNAME }}
packagePAT: ${{ secrets.BALLERINA_BOT_TOKEN }}
GITHUB_TOKEN: ${{ secrets.BALLERINA_BOT_TOKEN }}
run: |
sed -i 's/version=\(.*\)-SNAPSHOT/version=\1/g' gradle.properties
./gradlew clean build :tool-openapi:publishToCentral -PpublishToCentral=true
2 changes: 1 addition & 1 deletion openapi-cli/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ dependencies {

task copyDependencies(type: Copy) {
from configurations.runtimeClasspath
into 'libs'
into '../tool-openapi/resources/libs'
}

def bDistribution = file("$project.buildDir/extracted-distribution/jballerina-tools-${ballerinaLangVersion}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package io.ballerina.openapi.cmd;

import io.ballerina.cli.BLauncherCmd;
import io.ballerina.cli.launcher.LauncherUtils;
import io.ballerina.openapi.converter.diagnostic.DiagnosticMessages;
import io.ballerina.openapi.converter.diagnostic.ExceptionDiagnostic;
import io.ballerina.openapi.converter.diagnostic.IncompatibleResourceDiagnostic;
Expand Down Expand Up @@ -140,7 +141,7 @@ public TestOpenApiCmd(PrintStream outStream, Path executionDir, boolean exitWhen
public void execute() {

if (helpFlag) {
String commandUsageInfo = BLauncherCmd.getCommandUsageInfo(getName());
String commandUsageInfo = getCommandUsageInfo(getName());
outStream.println(commandUsageInfo);
return;
}
Expand Down Expand Up @@ -212,7 +213,8 @@ public void execute() {
exitError(this.exitWhenFinish);
}
} else {
String commandUsageInfo = BLauncherCmd.getCommandUsageInfo(getName());
// String commandUsageInfo = BLauncherCmd.getCommandUsageInfo(getName());
String commandUsageInfo = getCommandUsageInfo(getName());
outStream.println(commandUsageInfo);
exitError(this.exitWhenFinish);
return;
Expand All @@ -223,6 +225,56 @@ public void execute() {
}
}

private static String getCommandUsageInfo(String commandName) {
String fileName = "ballerina-openapi.help";
try {
return readFileAsString(fileName);
} catch (IOException var3) {
throw LauncherUtils.createUsageExceptionWithHelp(
"usage info not available for command: " + commandName);
}
}
private static String readFileAsString(String path) throws IOException {
Class<?> openApiCmdClass = TestOpenApiCmd.class; // Replace `YourClass` with the actual class name
ClassLoader classLoader = openApiCmdClass.getClassLoader();
InputStream is = classLoader.getResourceAsStream(path);
InputStreamReader inputStreamREader = null;
BufferedReader br = null;
StringBuilder sb = new StringBuilder();

try {
inputStreamREader = new InputStreamReader(is, StandardCharsets.UTF_8);
br = new BufferedReader(inputStreamREader);
String content = br.readLine();
if (content == null) {
String var6 = sb.toString();
return var6;
}

sb.append(content);

while ((content = br.readLine()) != null) {
sb.append('\n').append(content);
}
} finally {
if (inputStreamREader != null) {
try {
inputStreamREader.close();
} catch (IOException var18) {
}
}

if (br != null) {
try {
br.close();
} catch (IOException var17) {
}
}

}
return sb.toString();
}

/**
* This util method to generate openApi contract based on the given service ballerina file.
* @param fileName input resource file
Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public static Process executeRun(String distributionName, Path sourceDirectory,
*/
public static boolean executeOpenAPI(String distributionName, Path sourceDirectory, List<String> args) throws
IOException, InterruptedException {
args.add(0, "openapi");
args.add(0, "test-openapi");
Process process = getProcessBuilderResults(distributionName, sourceDirectory, args);
int exitCode = process.waitFor();
logOutput(process.getInputStream());
Expand Down
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ include(':openapi-validator')
include(':openapi-extension')
include(':openapi-extension-tests')
include(':openapi-integration-tests')
include(':tool-openapi')
//include(':openapi-tests')

gradleEnterprise {
Expand Down
Loading

0 comments on commit 4e96afd

Please sign in to comment.