diff --git a/.github/workflows/pull-request-snapshot-release.yml b/.github/workflows/pull-request-snapshot-release.yml index 56614dd994..6480aad482 100644 --- a/.github/workflows/pull-request-snapshot-release.yml +++ b/.github/workflows/pull-request-snapshot-release.yml @@ -3,11 +3,11 @@ name: Release new version for specific pull request (snapshot) on: - workflow_dispatch: - inputs: - pull_request: - description: 'The pull request snapshot that is going to be released (i.e PR-XXXX)' - required: true + pull_request: + branches: [ master, v2.x.x ] + +env: + PR_NUMBER: ${{ github.event.number }} jobs: build: @@ -48,7 +48,7 @@ jobs: - name: Release with Gradle run: | - BRANCH_NAME=${{ github.event.inputs.pull_request }} + BRANCH_NAME=PR-${{ env.PR_NUMBER }} sed -i '/version=/ s/-SNAPSHOT/-'"$BRANCH_NAME"'-SNAPSHOT/' ./gradle.properties ./gradlew build publishAllVersions -Pzowe.deploy.username=$ARTIFACTORY_USERNAME -Pzowe.deploy.password=$ARTIFACTORY_PASSWORD -Partifactory_user=$ARTIFACTORY_USERNAME -Partifactory_password=$ARTIFACTORY_USERNAME -PpullRequest=$BRANCH_NAME env: diff --git a/apiml-sample-extension-package/build.gradle b/apiml-sample-extension-package/build.gradle new file mode 100644 index 0000000000..3bfbf28fbf --- /dev/null +++ b/apiml-sample-extension-package/build.gradle @@ -0,0 +1,56 @@ +/* + * This program and the accompanying materials are made available under the terms of the + * Eclipse Public License v2.0 which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-v20.html + * + * SPDX-License-Identifier: EPL-2.0 + * + * Copyright Contributors to the Zowe Project. + */ + +ext { + artifactName = 'apiml-sample-extension-package' + pullNo = project.hasProperty("pullRequest") && project.getProperty("pullRequest") != null ? "-" + project.getProperty("pullRequest") : "" +} + +configurations { + sampleExtensionJar + zip +} + +dependencies { + sampleExtensionJar(project(path: ":apiml-sample-extension")) +} + +task packageSampleExtension(type: Zip) { + archiveName = artifactName + pullNo + ".zip" + includeEmptyDirs = true + def resourceDir = 'src/main/resources/' + + into('/') { + from "$resourceDir/manifest.yaml" + } + + into('bin/') { + from configurations.sampleExtensionJar + } +} + +jar.dependsOn(packageSampleExtension) +build.dependsOn(packageSampleExtension) + +artifacts { + zip packageSampleExtension +} + +publishing { + publications { + mavenJava(MavenPublication) { + artifact("$buildDir/distributions/$artifactName" + pullNo + ".zip") + } + } +} + +jar { + enabled false +} diff --git a/apiml-sample-extension-package/src/main/resources/manifest.yaml b/apiml-sample-extension-package/src/main/resources/manifest.yaml new file mode 100644 index 0000000000..40e659dad3 --- /dev/null +++ b/apiml-sample-extension-package/src/main/resources/manifest.yaml @@ -0,0 +1,23 @@ +--- +name: apiml-sample-extension +# Component identifier. This identifier matches artifact path in Zowe Artifactory https://zowe.jfrog.io/. +id: org.zowe.apiml.sdk.apiml-sample-extension-package +# Component version is defined in gradle.properties for Gradle project +# Human readable component name +title: A sample extension for API ML +# Human readable component description +description: JAR that contains a simple controller. +license: EPL-2.0 +repository: + type: git + url: https://github.com/zowe/api-layer.git +build: + branch: "{{build.branch}}" + number: "{{build.number}}" + commitHash: "{{build.commitHash}}" + timestamp: "{{build.timestamp}}" +# The following block contains all the extensions directory path +# (or file path) that will be included in the API ML +gatewaySharedLibs: + - bin/apiml-sample-extension.jar + diff --git a/apiml-sample-extension/README.md b/apiml-sample-extension/README.md new file mode 100644 index 0000000000..eec8e7e16a --- /dev/null +++ b/apiml-sample-extension/README.md @@ -0,0 +1,15 @@ +# API ML sample extension + +This is an API ML sample extension. It only contains a simple controller for testing. +The extension is added to the API Gateway class path. Therefore, as a result, the controller is added in the context +of the API Gateway without starting a new service. + +## Usage + +If the extension is correctly added to the API Gateway classpath, it will be possible to +call the REST endpoint defined in the controller via Gateway. +The extension is scanned and added to the classpath during the Zowe instance preparation, therefore +once the Gateway is started, you can: + +1. Call the `https://:/api/v1/greeting` endpoint though Gateway +2. Verify that you get the message `Hello, I'm a sample extension!` as response diff --git a/apiml-sample-extension/build.gradle b/apiml-sample-extension/build.gradle new file mode 100644 index 0000000000..663f760f44 --- /dev/null +++ b/apiml-sample-extension/build.gradle @@ -0,0 +1,44 @@ +buildscript { + repositories mavenRepositories + dependencies { + classpath("gradle.plugin.com.gorylenko.gradle-git-properties:gradle-git-properties:${gradleGitPropertiesVersion}") + classpath ("org.eclipse.jgit:org.eclipse.jgit:5.13.0.202109080827-r") { + force = true + } + } +} + +normalization { + runtimeClasspath { + ignore("**/*git.properties*") + ignore("**/*build-info.properties*") + } +} + +apply plugin: 'com.gorylenko.gradle-git-properties' + +gitProperties { + gitPropertiesDir = new File("${project.rootDir}/${name}/build/resources/main/META-INF") +} + +dependencies { + + implementation libraries.springFox + implementation libraries.spring_webmvc + +} + +jar { + enabled true + baseName = "apiml-sample-extension" + archiveName = "${baseName}.jar" +} + +publishing { + publications { + mavenJavaLib(MavenPublication) { + artifact jar + } + } +} + diff --git a/apiml-sample-extension/src/main/java/org/zowe/apiml/gateway/api/GreetingController.java b/apiml-sample-extension/src/main/java/org/zowe/apiml/gateway/api/GreetingController.java new file mode 100644 index 0000000000..677d3f8dc2 --- /dev/null +++ b/apiml-sample-extension/src/main/java/org/zowe/apiml/gateway/api/GreetingController.java @@ -0,0 +1,31 @@ +/* + * This program and the accompanying materials are made available under the terms of the + * Eclipse Public License v2.0 which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-v20.html + * + * SPDX-License-Identifier: EPL-2.0 + * + * Copyright Contributors to the Zowe Project. + */ +package org.zowe.apiml.gateway.api; + +import io.swagger.annotations.Api; +import org.springframework.web.bind.annotation.*; + +/** + * Controller that returns greetings. + */ +@RestController +@Api(tags = {"Other Operations"}) +@RequestMapping("/api/v1") +public class GreetingController { + private static final String GREETING = "Hello, I'm a sample extension!"; + + /** + * Gets a greeting for anyone. + */ + @GetMapping(value = "/greeting") + public String greeting() { + return GREETING; + } +} diff --git a/build.gradle b/build.gradle index b0426f5e1f..1133dbef34 100644 --- a/build.gradle +++ b/build.gradle @@ -106,7 +106,7 @@ subprojects { } task buildCore(dependsOn: [':gateway-service:build', ':discovery-service:build', ':api-catalog-services:build', ':api-catalog-ui:build', - ':discoverable-client:build', ':zaas-client:build']) { + ':discoverable-client:build', ':zaas-client:build', ':apiml-sample-extension:build']) { description "Build core components" group "build" } diff --git a/gradle/license.gradle b/gradle/license.gradle index 44ac326373..5a307531cb 100644 --- a/gradle/license.gradle +++ b/gradle/license.gradle @@ -29,7 +29,8 @@ ext.projectsNeedLicense = [ 'onboarding-enabler-nodejs', 'zaas-client', 'mock-services', - 'apiml-tomcat-common' + 'apiml-tomcat-common', + 'apiml-sample-extension' ] configure(subprojects.findAll { it.name in projectsNeedLicense }) { diff --git a/gradle/publish.gradle b/gradle/publish.gradle index fbb20e43bb..b3883f07f3 100644 --- a/gradle/publish.gradle +++ b/gradle/publish.gradle @@ -16,10 +16,11 @@ ext.javaLibraries = [ 'zaas-client', 'discoverable-client', 'certificate-analyser', - 'apiml-tomcat-common' + 'apiml-tomcat-common', + 'apiml-sample-extension' ] -ext.serviceJars = ['api-catalog-package', 'discovery-package', 'gateway-package', 'caching-service-package', 'metrics-service-package', 'apiml-common-lib-package'] +ext.serviceJars = ['api-catalog-package', 'discovery-package', 'gateway-package', 'caching-service-package', 'metrics-service-package', 'apiml-common-lib-package', 'apiml-sample-extension-package'] ext.enablers = [ext.javaEnabler, ext.springBootEnabler, ext.micronautEnabler] ext.projectsToPublish = ext.serviceJars + ext.javaLibraries + ext.enablers diff --git a/gradle/sonar.gradle b/gradle/sonar.gradle index a3468ce289..6e6fbde0d7 100644 --- a/gradle/sonar.gradle +++ b/gradle/sonar.gradle @@ -126,6 +126,20 @@ project(":apiml-common-lib-package") { } } +// Packaging project; sonar does not apply +project(":apiml-sample-extension-package") { + sonarqube { + skipProject = true + } +} + +// Packaging project; sonar does not apply +project(":apiml-sample-extension") { + sonarqube { + skipProject = true + } +} + // Packaging project; sonar does not apply project(":mock-services") { sonarqube { diff --git a/settings.gradle b/settings.gradle index bcbf9a0a01..201092a409 100644 --- a/settings.gradle +++ b/settings.gradle @@ -49,4 +49,6 @@ include 'metrics-service-ui' include 'metrics-service-package' include 'apiml-tomcat-common' include 'onboarding-enabler-java-sample-app-plain-java' +include 'apiml-sample-extension' +include 'apiml-sample-extension-package'