Skip to content

Commit

Permalink
fix: Add build info to the manifest.yaml (#2573)
Browse files Browse the repository at this point in the history
* Add build info to the manifest

Signed-off-by: at670475 <andrea.tabone@broadcom.com>

* fix input manifest directory

Signed-off-by: at670475 <andrea.tabone@broadcom.com>

* add env variables

Signed-off-by: at670475 <andrea.tabone@broadcom.com>

* fix env variables

Signed-off-by: at670475 <andrea.tabone@broadcom.com>

Signed-off-by: at670475 <andrea.tabone@broadcom.com>
  • Loading branch information
taban03 committed Sep 8, 2022
1 parent f1935cb commit 93298dd
Show file tree
Hide file tree
Showing 19 changed files with 249 additions and 11 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/automated-release.yml
Expand Up @@ -66,5 +66,7 @@ jobs:
ARTIFACTORY_USERNAME: ${{ secrets.ARTIFACTORY_USERNAME }}
ARTIFACTORY_PASSWORD: ${{ secrets.ARTIFACTORY_PASSWORD }}
DEFAULT_SCOPE: 'patch'
BUILD_NUMBER: ${{ github.run_number }}
BRANCH_NAME: ${{ github.ref_name }}

- uses: ./.github/actions/teardown
2 changes: 2 additions & 0 deletions .github/workflows/binary-snapshot-release.yml
Expand Up @@ -23,5 +23,7 @@ jobs:
env:
ARTIFACTORY_USERNAME: ${{ secrets.ARTIFACTORY_USERNAME }}
ARTIFACTORY_PASSWORD: ${{ secrets.ARTIFACTORY_PASSWORD }}
BUILD_NUMBER: ${{ github.run_number }}
BRANCH_NAME: ${{ github.ref_name }}

- uses: ./.github/actions/teardown
2 changes: 2 additions & 0 deletions .github/workflows/binary-specific-release.yml
Expand Up @@ -61,5 +61,7 @@ jobs:
env:
ARTIFACTORY_USERNAME: ${{ secrets.ARTIFACTORY_USERNAME }}
ARTIFACTORY_PASSWORD: ${{ secrets.ARTIFACTORY_PASSWORD }}
BUILD_NUMBER: ${{ github.run_number }}
BRANCH_NAME: ${{ github.ref_name }}

- uses: ./.github/actions/teardown
10 changes: 6 additions & 4 deletions .github/workflows/pull-request-snapshot-release.yml
Expand Up @@ -6,7 +6,7 @@ on:
workflow_dispatch:
inputs:
pull_request:
description: 'The pull request snapshot that is going to be released (i.e PR-XXXX)'
description: 'The pull request snapshot that is going to be released (i.e XXXX)'
required: true

env:
Expand All @@ -27,12 +27,14 @@ jobs:

- name: Release with Gradle
run: |
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
PR_NUMBER=PR-${{ env.PR_NUMBER }}
sed -i '/version=/ s/-SNAPSHOT/-'"$PR_NUMBER"'-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=$PR_NUMBER
env:
ARTIFACTORY_USERNAME: ${{ secrets.ARTIFACTORY_USERNAME }}
ARTIFACTORY_PASSWORD: ${{ secrets.ARTIFACTORY_PASSWORD }}
BRANCH_NAME: ${{ github.ref_name }}
BUILD_NUMBER: ${{ github.run_number }}

- uses: ./.github/actions/teardown

29 changes: 28 additions & 1 deletion api-catalog-package/build.gradle
Expand Up @@ -18,7 +18,7 @@ task packageApiCatalog(type: Zip) {
def resourceDir = 'src/main/resources/'

into('/') {
from "$resourceDir/manifest.yaml"
from "$buildDir/convert/manifest.yaml"
from "$resourceDir/pluginDefinition.json"
from "../schemas/catalog-schema.json"
}
Expand All @@ -39,6 +39,33 @@ task packageApiCatalog(type: Zip) {
}
}

// save build information to manifest
packageApiCatalog.doFirst {
String manifest = file('src/main/resources/manifest.yaml').text

def getCommitHash = 'git rev-parse --verify HEAD'.execute()
def commit_hash = new ByteArrayOutputStream()
def command_err = new ByteArrayOutputStream()
getCommitHash.consumeProcessOutput(commit_hash, command_err)
getCommitHash.waitForOrKill(1000)

manifest = manifest.replaceAll("\\{\\{build.branch\\}\\}", System.getenv("BRANCH_NAME") ?: "")
.replaceAll("\\{\\{build.number\\}\\}", System.getenv("BUILD_NUMBER") ?: "")
.replaceAll("\\{\\{build.commitHash\\}\\}", commit_hash.toString().trim())
.replaceAll("\\{\\{build.timestamp\\}\\}", (new Date()).getTime().toString())

def scriptOutputDir = new File("$buildDir/convert/");
if (!scriptOutputDir.exists()) {
scriptOutputDir.mkdirs();
}
File convertedManifest = new File("$buildDir/convert/manifest.yaml");
if (convertedManifest.exists()) {
convertedManifest.delete();
}
convertedManifest.createNewFile();
convertedManifest.write(manifest)
}

jar.dependsOn(packageApiCatalog)
build.dependsOn(packageApiCatalog)

Expand Down
5 changes: 5 additions & 0 deletions api-catalog-package/src/main/resources/manifest.yaml
Expand Up @@ -13,6 +13,11 @@ schemas:
repository:
type: git
url: https://github.com/zowe/api-layer.git
build:
branch: "{{build.branch}}"
number: "{{build.number}}"
commitHash: "{{build.commitHash}}"
timestamp: "{{build.timestamp}}"
commands:
start: bin/start.sh
validate: bin/validate.sh
Expand Down
29 changes: 28 additions & 1 deletion apiml-common-lib-package/build.gradle
Expand Up @@ -23,7 +23,7 @@ task packageCommonLib(type: Zip) {
def resourceDir = 'src/main/resources/'

into('/') {
from "$resourceDir/manifest.yaml"
from "$buildDir/convert/manifest.yaml"
from "../schemas/apiml-common-lib-schema.json"
}

Expand All @@ -32,6 +32,33 @@ task packageCommonLib(type: Zip) {
}
}

// save build information to manifest
packageCommonLib.doFirst {
String manifest = file('src/main/resources/manifest.yaml').text

def getCommitHash = 'git rev-parse --verify HEAD'.execute()
def commit_hash = new ByteArrayOutputStream()
def command_err = new ByteArrayOutputStream()
getCommitHash.consumeProcessOutput(commit_hash, command_err)
getCommitHash.waitForOrKill(1000)

manifest = manifest.replaceAll("\\{\\{build.branch\\}\\}", System.getenv("BRANCH_NAME") ?: "")
.replaceAll("\\{\\{build.number\\}\\}", System.getenv("BUILD_NUMBER") ?: "")
.replaceAll("\\{\\{build.commitHash\\}\\}", commit_hash.toString().trim())
.replaceAll("\\{\\{build.timestamp\\}\\}", (new Date()).getTime().toString())

def scriptOutputDir = new File("$buildDir/convert/");
if (!scriptOutputDir.exists()) {
scriptOutputDir.mkdirs();
}
File convertedManifest = new File("$buildDir/convert/manifest.yaml");
if (convertedManifest.exists()) {
convertedManifest.delete();
}
convertedManifest.createNewFile();
convertedManifest.write(manifest)
}

jar.dependsOn(packageCommonLib)
build.dependsOn(packageCommonLib)
packageCommonLib.dependsOn(":liteLibJarAll")
Expand Down
5 changes: 5 additions & 0 deletions apiml-common-lib-package/src/main/resources/manifest.yaml
Expand Up @@ -11,5 +11,10 @@ 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}}"
schemas:
configs: "apiml-common-lib-schema.json"
29 changes: 28 additions & 1 deletion apiml-sample-extension-package/build.gradle
Expand Up @@ -27,7 +27,7 @@ task packageSampleExtension(type: Zip) {
def resourceDir = 'src/main/resources/'

into('/') {
from "$resourceDir/manifest.yaml"
from "$buildDir/convert/manifest.yaml"
from "../schemas/apiml-sample-extension-schema.json"
}

Expand All @@ -36,6 +36,33 @@ task packageSampleExtension(type: Zip) {
}
}

// save build information to manifest
packageSampleExtension.doFirst {
String manifest = file('src/main/resources/manifest.yaml').text

def getCommitHash = 'git rev-parse --verify HEAD'.execute()
def commit_hash = new ByteArrayOutputStream()
def command_err = new ByteArrayOutputStream()
getCommitHash.consumeProcessOutput(commit_hash, command_err)
getCommitHash.waitForOrKill(1000)

manifest = manifest.replaceAll("\\{\\{build.branch\\}\\}", System.getenv("BRANCH_NAME") ?: "")
.replaceAll("\\{\\{build.number\\}\\}", System.getenv("BUILD_NUMBER") ?: "")
.replaceAll("\\{\\{build.commitHash\\}\\}", commit_hash.toString().trim())
.replaceAll("\\{\\{build.timestamp\\}\\}", (new Date()).getTime().toString())

def scriptOutputDir = new File("$buildDir/convert/");
if (!scriptOutputDir.exists()) {
scriptOutputDir.mkdirs();
}
File convertedManifest = new File("$buildDir/convert/manifest.yaml");
if (convertedManifest.exists()) {
convertedManifest.delete();
}
convertedManifest.createNewFile();
convertedManifest.write(manifest)
}

jar.dependsOn(packageSampleExtension)
build.dependsOn(packageSampleExtension)

Expand Down
Expand Up @@ -11,6 +11,11 @@ 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:
Expand Down
29 changes: 28 additions & 1 deletion caching-service-package/build.gradle
Expand Up @@ -18,7 +18,7 @@ task packageCachingService(type: Zip) {
def resourceDir = 'src/main/resources/'

into('/') {
from "$resourceDir/manifest.yaml"
from "$buildDir/convert/manifest.yaml"
from "../schemas/caching-schema.json"
}

Expand All @@ -29,6 +29,33 @@ task packageCachingService(type: Zip) {
}
}

// save build information to manifest
packageCachingService.doFirst {
String manifest = file('src/main/resources/manifest.yaml').text

def getCommitHash = 'git rev-parse --verify HEAD'.execute()
def commit_hash = new ByteArrayOutputStream()
def command_err = new ByteArrayOutputStream()
getCommitHash.consumeProcessOutput(commit_hash, command_err)
getCommitHash.waitForOrKill(1000)

manifest = manifest.replaceAll("\\{\\{build.branch\\}\\}", System.getenv("BRANCH_NAME") ?: "")
.replaceAll("\\{\\{build.number\\}\\}", System.getenv("BUILD_NUMBER") ?: "")
.replaceAll("\\{\\{build.commitHash\\}\\}", commit_hash.toString().trim())
.replaceAll("\\{\\{build.timestamp\\}\\}", (new Date()).getTime().toString())

def scriptOutputDir = new File("$buildDir/convert/");
if (!scriptOutputDir.exists()) {
scriptOutputDir.mkdirs();
}
File convertedManifest = new File("$buildDir/convert/manifest.yaml");
if (convertedManifest.exists()) {
convertedManifest.delete();
}
convertedManifest.createNewFile();
convertedManifest.write(manifest)
}

jar.dependsOn(packageCachingService)
build.dependsOn(packageCachingService)

Expand Down
5 changes: 5 additions & 0 deletions caching-service-package/src/main/resources/manifest.yaml
Expand Up @@ -13,6 +13,11 @@ schemas:
repository:
type: git
url: https://github.com/zowe/api-layer.git
build:
branch: "{{build.branch}}"
number: "{{build.number}}"
commitHash: "{{build.commitHash}}"
timestamp: "{{build.timestamp}}"
commands:
start: bin/start.sh
validate: bin/validate.sh
Expand Down
6 changes: 6 additions & 0 deletions containers/prepare-utils.sh
Expand Up @@ -73,6 +73,12 @@ function buildPackage {
package_task=$2
echo ">>>>> build package ${service_package}"
cd $REPO_ROOT_DIR
if [ -n "${GITHUB_PR_ID}" ]; then
export BRANCH_NAME=PR-${GITHUB_PR_ID}
else
export BRANCH_NAME=${GITHUB_REF#refs/heads/}
fi
export BUILD_NUMBER=${GITHUB_RUN_NUMBER}
./gradlew $package_task
if [ ! -f "${REPO_ROOT_DIR}/${service_package}/build/distributions/${service_package}.zip" ]; then
echo "Error: failed to build ${service_package}.zip"
Expand Down
29 changes: 28 additions & 1 deletion discovery-package/build.gradle
Expand Up @@ -18,7 +18,7 @@ task packageDiscovery(type: Zip) {
def resourceDir = 'src/main/resources/'

into('/') {
from "$resourceDir/manifest.yaml", "$resourceDir/zosmf-static-definition.yaml.template"
from "$buildDir/convert/manifest.yaml", "$resourceDir/zosmf-static-definition.yaml.template"
from "../schemas/discovery-schema.json"
}

Expand All @@ -30,6 +30,33 @@ task packageDiscovery(type: Zip) {
}
}

// save build information to manifest
packageDiscovery.doFirst {
String manifest = file('src/main/resources/manifest.yaml').text

def getCommitHash = 'git rev-parse --verify HEAD'.execute()
def commit_hash = new ByteArrayOutputStream()
def command_err = new ByteArrayOutputStream()
getCommitHash.consumeProcessOutput(commit_hash, command_err)
getCommitHash.waitForOrKill(1000)

manifest = manifest.replaceAll("\\{\\{build.branch\\}\\}", System.getenv("BRANCH_NAME") ?: "")
.replaceAll("\\{\\{build.number\\}\\}", System.getenv("BUILD_NUMBER") ?: "")
.replaceAll("\\{\\{build.commitHash\\}\\}", commit_hash.toString().trim())
.replaceAll("\\{\\{build.timestamp\\}\\}", (new Date()).getTime().toString())

def scriptOutputDir = new File("$buildDir/convert/");
if (!scriptOutputDir.exists()) {
scriptOutputDir.mkdirs();
}
File convertedManifest = new File("$buildDir/convert/manifest.yaml");
if (convertedManifest.exists()) {
convertedManifest.delete();
}
convertedManifest.createNewFile();
convertedManifest.write(manifest)
}

jar.dependsOn(packageDiscovery)
build.dependsOn(packageDiscovery)

Expand Down
5 changes: 5 additions & 0 deletions discovery-package/src/main/resources/manifest.yaml
Expand Up @@ -13,6 +13,11 @@ schemas:
repository:
type: git
url: https://github.com/zowe/api-layer.git
build:
branch: "{{build.branch}}"
number: "{{build.number}}"
commitHash: "{{build.commitHash}}"
timestamp: "{{build.timestamp}}"
commands:
start: bin/start.sh
validate: bin/validate.sh
Expand Down
29 changes: 28 additions & 1 deletion gateway-package/build.gradle
Expand Up @@ -18,7 +18,7 @@ task packageApiGateway(type: Zip) {
def resourceDir = 'src/main/resources/'

into('/') {
from "$resourceDir/manifest.yaml"
from "$buildDir/convert/manifest.yaml"
from "../schemas/gateway-schema.json"
}

Expand All @@ -29,6 +29,33 @@ task packageApiGateway(type: Zip) {
}
}

// save build information to manifest
packageApiGateway.doFirst {
String manifest = file('src/main/resources/manifest.yaml').text

def getCommitHash = 'git rev-parse --verify HEAD'.execute()
def commit_hash = new ByteArrayOutputStream()
def command_err = new ByteArrayOutputStream()
getCommitHash.consumeProcessOutput(commit_hash, command_err)
getCommitHash.waitForOrKill(1000)

manifest = manifest.replaceAll("\\{\\{build.branch\\}\\}", System.getenv("BRANCH_NAME") ?: "")
.replaceAll("\\{\\{build.number\\}\\}", System.getenv("BUILD_NUMBER") ?: "")
.replaceAll("\\{\\{build.commitHash\\}\\}", commit_hash.toString().trim())
.replaceAll("\\{\\{build.timestamp\\}\\}", (new Date()).getTime().toString())

def scriptOutputDir = new File("$buildDir/convert/");
if (!scriptOutputDir.exists()) {
scriptOutputDir.mkdirs();
}
File convertedManifest = new File("$buildDir/convert/manifest.yaml");
if (convertedManifest.exists()) {
convertedManifest.delete();
}
convertedManifest.createNewFile();
convertedManifest.write(manifest)
}

jar.dependsOn(packageApiGateway)
build.dependsOn(packageApiGateway)

Expand Down
5 changes: 5 additions & 0 deletions gateway-package/src/main/resources/manifest.yaml
Expand Up @@ -13,6 +13,11 @@ schemas:
repository:
type: git
url: https://github.com/zowe/api-layer.git
build:
branch: "{{build.branch}}"
number: "{{build.number}}"
commitHash: "{{build.commitHash}}"
timestamp: "{{build.timestamp}}"
commands:
start: bin/start.sh
validate: bin/validate.sh
Expand Down

0 comments on commit 93298dd

Please sign in to comment.