Skip to content

Commit 93298dd

Browse files
authored
fix: Add build info to the manifest.yaml (#2573)
* 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>
1 parent f1935cb commit 93298dd

File tree

19 files changed

+249
-11
lines changed

19 files changed

+249
-11
lines changed

.github/workflows/automated-release.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,7 @@ jobs:
6666
ARTIFACTORY_USERNAME: ${{ secrets.ARTIFACTORY_USERNAME }}
6767
ARTIFACTORY_PASSWORD: ${{ secrets.ARTIFACTORY_PASSWORD }}
6868
DEFAULT_SCOPE: 'patch'
69+
BUILD_NUMBER: ${{ github.run_number }}
70+
BRANCH_NAME: ${{ github.ref_name }}
6971

7072
- uses: ./.github/actions/teardown

.github/workflows/binary-snapshot-release.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,7 @@ jobs:
2323
env:
2424
ARTIFACTORY_USERNAME: ${{ secrets.ARTIFACTORY_USERNAME }}
2525
ARTIFACTORY_PASSWORD: ${{ secrets.ARTIFACTORY_PASSWORD }}
26+
BUILD_NUMBER: ${{ github.run_number }}
27+
BRANCH_NAME: ${{ github.ref_name }}
2628

2729
- uses: ./.github/actions/teardown

.github/workflows/binary-specific-release.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,7 @@ jobs:
6161
env:
6262
ARTIFACTORY_USERNAME: ${{ secrets.ARTIFACTORY_USERNAME }}
6363
ARTIFACTORY_PASSWORD: ${{ secrets.ARTIFACTORY_PASSWORD }}
64+
BUILD_NUMBER: ${{ github.run_number }}
65+
BRANCH_NAME: ${{ github.ref_name }}
6466

6567
- uses: ./.github/actions/teardown

.github/workflows/pull-request-snapshot-release.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
workflow_dispatch:
77
inputs:
88
pull_request:
9-
description: 'The pull request snapshot that is going to be released (i.e PR-XXXX)'
9+
description: 'The pull request snapshot that is going to be released (i.e XXXX)'
1010
required: true
1111

1212
env:
@@ -27,12 +27,14 @@ jobs:
2727

2828
- name: Release with Gradle
2929
run: |
30-
BRANCH_NAME=PR-${{ env.PR_NUMBER }}
31-
sed -i '/version=/ s/-SNAPSHOT/-'"$BRANCH_NAME"'-SNAPSHOT/' ./gradle.properties
32-
./gradlew build publishAllVersions -Pzowe.deploy.username=$ARTIFACTORY_USERNAME -Pzowe.deploy.password=$ARTIFACTORY_PASSWORD -Partifactory_user=$ARTIFACTORY_USERNAME -Partifactory_password=$ARTIFACTORY_USERNAME -PpullRequest=$BRANCH_NAME
30+
PR_NUMBER=PR-${{ env.PR_NUMBER }}
31+
sed -i '/version=/ s/-SNAPSHOT/-'"$PR_NUMBER"'-SNAPSHOT/' ./gradle.properties
32+
./gradlew build publishAllVersions -Pzowe.deploy.username=$ARTIFACTORY_USERNAME -Pzowe.deploy.password=$ARTIFACTORY_PASSWORD -Partifactory_user=$ARTIFACTORY_USERNAME -Partifactory_password=$ARTIFACTORY_USERNAME -PpullRequest=$PR_NUMBER
3333
env:
3434
ARTIFACTORY_USERNAME: ${{ secrets.ARTIFACTORY_USERNAME }}
3535
ARTIFACTORY_PASSWORD: ${{ secrets.ARTIFACTORY_PASSWORD }}
36+
BRANCH_NAME: ${{ github.ref_name }}
37+
BUILD_NUMBER: ${{ github.run_number }}
3638

3739
- uses: ./.github/actions/teardown
3840

api-catalog-package/build.gradle

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ task packageApiCatalog(type: Zip) {
1818
def resourceDir = 'src/main/resources/'
1919

2020
into('/') {
21-
from "$resourceDir/manifest.yaml"
21+
from "$buildDir/convert/manifest.yaml"
2222
from "$resourceDir/pluginDefinition.json"
2323
from "../schemas/catalog-schema.json"
2424
}
@@ -39,6 +39,33 @@ task packageApiCatalog(type: Zip) {
3939
}
4040
}
4141

42+
// save build information to manifest
43+
packageApiCatalog.doFirst {
44+
String manifest = file('src/main/resources/manifest.yaml').text
45+
46+
def getCommitHash = 'git rev-parse --verify HEAD'.execute()
47+
def commit_hash = new ByteArrayOutputStream()
48+
def command_err = new ByteArrayOutputStream()
49+
getCommitHash.consumeProcessOutput(commit_hash, command_err)
50+
getCommitHash.waitForOrKill(1000)
51+
52+
manifest = manifest.replaceAll("\\{\\{build.branch\\}\\}", System.getenv("BRANCH_NAME") ?: "")
53+
.replaceAll("\\{\\{build.number\\}\\}", System.getenv("BUILD_NUMBER") ?: "")
54+
.replaceAll("\\{\\{build.commitHash\\}\\}", commit_hash.toString().trim())
55+
.replaceAll("\\{\\{build.timestamp\\}\\}", (new Date()).getTime().toString())
56+
57+
def scriptOutputDir = new File("$buildDir/convert/");
58+
if (!scriptOutputDir.exists()) {
59+
scriptOutputDir.mkdirs();
60+
}
61+
File convertedManifest = new File("$buildDir/convert/manifest.yaml");
62+
if (convertedManifest.exists()) {
63+
convertedManifest.delete();
64+
}
65+
convertedManifest.createNewFile();
66+
convertedManifest.write(manifest)
67+
}
68+
4269
jar.dependsOn(packageApiCatalog)
4370
build.dependsOn(packageApiCatalog)
4471

api-catalog-package/src/main/resources/manifest.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ schemas:
1313
repository:
1414
type: git
1515
url: https://github.com/zowe/api-layer.git
16+
build:
17+
branch: "{{build.branch}}"
18+
number: "{{build.number}}"
19+
commitHash: "{{build.commitHash}}"
20+
timestamp: "{{build.timestamp}}"
1621
commands:
1722
start: bin/start.sh
1823
validate: bin/validate.sh

apiml-common-lib-package/build.gradle

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ task packageCommonLib(type: Zip) {
2323
def resourceDir = 'src/main/resources/'
2424

2525
into('/') {
26-
from "$resourceDir/manifest.yaml"
26+
from "$buildDir/convert/manifest.yaml"
2727
from "../schemas/apiml-common-lib-schema.json"
2828
}
2929

@@ -32,6 +32,33 @@ task packageCommonLib(type: Zip) {
3232
}
3333
}
3434

35+
// save build information to manifest
36+
packageCommonLib.doFirst {
37+
String manifest = file('src/main/resources/manifest.yaml').text
38+
39+
def getCommitHash = 'git rev-parse --verify HEAD'.execute()
40+
def commit_hash = new ByteArrayOutputStream()
41+
def command_err = new ByteArrayOutputStream()
42+
getCommitHash.consumeProcessOutput(commit_hash, command_err)
43+
getCommitHash.waitForOrKill(1000)
44+
45+
manifest = manifest.replaceAll("\\{\\{build.branch\\}\\}", System.getenv("BRANCH_NAME") ?: "")
46+
.replaceAll("\\{\\{build.number\\}\\}", System.getenv("BUILD_NUMBER") ?: "")
47+
.replaceAll("\\{\\{build.commitHash\\}\\}", commit_hash.toString().trim())
48+
.replaceAll("\\{\\{build.timestamp\\}\\}", (new Date()).getTime().toString())
49+
50+
def scriptOutputDir = new File("$buildDir/convert/");
51+
if (!scriptOutputDir.exists()) {
52+
scriptOutputDir.mkdirs();
53+
}
54+
File convertedManifest = new File("$buildDir/convert/manifest.yaml");
55+
if (convertedManifest.exists()) {
56+
convertedManifest.delete();
57+
}
58+
convertedManifest.createNewFile();
59+
convertedManifest.write(manifest)
60+
}
61+
3562
jar.dependsOn(packageCommonLib)
3663
build.dependsOn(packageCommonLib)
3764
packageCommonLib.dependsOn(":liteLibJarAll")

apiml-common-lib-package/src/main/resources/manifest.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,10 @@ license: EPL-2.0
1111
repository:
1212
type: git
1313
url: https://github.com/zowe/api-layer.git
14+
build:
15+
branch: "{{build.branch}}"
16+
number: "{{build.number}}"
17+
commitHash: "{{build.commitHash}}"
18+
timestamp: "{{build.timestamp}}"
1419
schemas:
1520
configs: "apiml-common-lib-schema.json"

apiml-sample-extension-package/build.gradle

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ task packageSampleExtension(type: Zip) {
2727
def resourceDir = 'src/main/resources/'
2828

2929
into('/') {
30-
from "$resourceDir/manifest.yaml"
30+
from "$buildDir/convert/manifest.yaml"
3131
from "../schemas/apiml-sample-extension-schema.json"
3232
}
3333

@@ -36,6 +36,33 @@ task packageSampleExtension(type: Zip) {
3636
}
3737
}
3838

39+
// save build information to manifest
40+
packageSampleExtension.doFirst {
41+
String manifest = file('src/main/resources/manifest.yaml').text
42+
43+
def getCommitHash = 'git rev-parse --verify HEAD'.execute()
44+
def commit_hash = new ByteArrayOutputStream()
45+
def command_err = new ByteArrayOutputStream()
46+
getCommitHash.consumeProcessOutput(commit_hash, command_err)
47+
getCommitHash.waitForOrKill(1000)
48+
49+
manifest = manifest.replaceAll("\\{\\{build.branch\\}\\}", System.getenv("BRANCH_NAME") ?: "")
50+
.replaceAll("\\{\\{build.number\\}\\}", System.getenv("BUILD_NUMBER") ?: "")
51+
.replaceAll("\\{\\{build.commitHash\\}\\}", commit_hash.toString().trim())
52+
.replaceAll("\\{\\{build.timestamp\\}\\}", (new Date()).getTime().toString())
53+
54+
def scriptOutputDir = new File("$buildDir/convert/");
55+
if (!scriptOutputDir.exists()) {
56+
scriptOutputDir.mkdirs();
57+
}
58+
File convertedManifest = new File("$buildDir/convert/manifest.yaml");
59+
if (convertedManifest.exists()) {
60+
convertedManifest.delete();
61+
}
62+
convertedManifest.createNewFile();
63+
convertedManifest.write(manifest)
64+
}
65+
3966
jar.dependsOn(packageSampleExtension)
4067
build.dependsOn(packageSampleExtension)
4168

apiml-sample-extension-package/src/main/resources/manifest.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ license: EPL-2.0
1111
repository:
1212
type: git
1313
url: https://github.com/zowe/api-layer.git
14+
build:
15+
branch: "{{build.branch}}"
16+
number: "{{build.number}}"
17+
commitHash: "{{build.commitHash}}"
18+
timestamp: "{{build.timestamp}}"
1419
# The following block contains all the extensions directory path
1520
# (or file path) that will be included in the API ML
1621
gatewaySharedLibs:

0 commit comments

Comments
 (0)