diff --git a/generators/gh-maven-build/index.js b/generators/gh-maven-build/index.js index f130ac7..68549a3 100644 --- a/generators/gh-maven-build/index.js +++ b/generators/gh-maven-build/index.js @@ -74,6 +74,13 @@ export default class extends Generator { this.log( ' ' + chalk.dim('Example: super-project-backend-war'), ); + this.log( + ' ' + + chalk.bold('Client ID: ') + + chalk.dim( + 'The client id of the Broker account to use. Leave blank to use manually set BROKER_JWT secret.', + ), + ); this.log( ' ' + chalk.bold('Artifactory: ') + @@ -128,6 +135,13 @@ export default class extends Generator { message: 'Service:', store: true, }, + { + type: 'input', + name: 'clientId', + message: 'Client ID:', + default: '', + store: true, + }, { type: 'input', name: 'pomRoot', @@ -233,12 +247,19 @@ export default class extends Generator { // Generate GitHub workflows and NR Broker intention files writingWorkflow() { + const brokerJwt = this.answers.clientId.trim() + ? `broker-jwt:${this.answers.clientId.trim()}`.replace( + /[^a-zA-Z0-9_]/g, + '_', + ) + : 'BROKER_JWT'; this.fs.copyTpl( this.templatePath('build-release.yaml'), this.destinationPath('.github/workflows/build-release.yaml'), { projectName: this.answers.projectName, serviceName: this.answers.serviceName, + brokerJwt, artifactoryProject: this.answers.artifactoryProject, pomRoot: this.answers.pomRoot, unitTestsPath: this.answers.unitTestsPath, @@ -266,6 +287,7 @@ export default class extends Generator { { projectName: this.answers.projectName, serviceName: this.answers.serviceName, + brokerJwt, artifactoryProject: this.answers.artifactoryProject, pomRoot: this.answers.pomRoot, gitHubPackages: this.answers.gitHubPackages, diff --git a/generators/gh-maven-build/templates/build-release.yaml b/generators/gh-maven-build/templates/build-release.yaml index a51f78d..f212542 100644 --- a/generators/gh-maven-build/templates/build-release.yaml +++ b/generators/gh-maven-build/templates/build-release.yaml @@ -15,7 +15,7 @@ concurrency: env: BROKER_URL: https://broker.io.nrs.gov.bc.ca - BROKER_JWT: ${{ secrets.BROKER_JWT }} + BROKER_JWT: ${{ secrets.<%= brokerJwt %> }} SERVICE_PROJECT: <%= projectName %> SERVICE_NAME: <%= serviceName %> @@ -93,7 +93,7 @@ jobs: - name: Open intention uses: bcgov-nr/action-broker-intention-open@v2 with: - broker_jwt: ${{ secrets.BROKER_JWT }} + broker_jwt: ${{ secrets.<%= brokerJwt %> }} intention_path: intention.json quickstart: true - name: Set intention ID for deployment job diff --git a/generators/gh-maven-build/templates/deploy.yaml b/generators/gh-maven-build/templates/deploy.yaml index c10048e..6768f5d 100644 --- a/generators/gh-maven-build/templates/deploy.yaml +++ b/generators/gh-maven-build/templates/deploy.yaml @@ -59,7 +59,7 @@ jobs: echo "artifact_sha256=${artifact_checksum#sha256:}" >> $GITHUB_OUTPUT env: BROKER_URL: https://broker.io.nrs.gov.bc.ca - BROKER_JWT: ${{ secrets.BROKER_JWT }} + BROKER_JWT: ${{ secrets.<%= brokerJwt %> }} SERVICE_PROJECT: ${{ env.SERVICE_PROJECT }} SERVICE_NAME: ${{ env.SERVICE_NAME }} GITHUB_SHA: ${{ github.sha }} @@ -144,7 +144,7 @@ jobs: echo "artifact_sha256=${artifact_checksum#sha256:}" >> $GITHUB_OUTPUT env: BROKER_URL: https://broker.io.nrs.gov.bc.ca - BROKER_JWT: ${{ secrets.BROKER_JWT }} + BROKER_JWT: ${{ secrets.<%= brokerJwt %> }} SERVICE_PROJECT: ${{ env.SERVICE_PROJECT }} SERVICE_NAME: ${{ env.SERVICE_NAME }} - name: Checkout repository diff --git a/generators/util/yaml.js b/generators/util/yaml.js index d7d03e7..7ecfd76 100644 --- a/generators/util/yaml.js +++ b/generators/util/yaml.js @@ -98,6 +98,10 @@ export const pathToProps = [ ], prop: 'addWebadeConfig', }, + { + path: ['metadata', 'annotations', 'playbook.io.nrs.gov.bc.ca/clientId'], + prop: 'clientId', + }, ]; export function extractFromYaml(doc, pathToProps) { diff --git a/package-lock.json b/package-lock.json index a4b0801..e0bac7b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,19 +9,19 @@ "version": "1.0.0", "license": "Apache-2.0", "dependencies": { - "yaml": "^2.5.0", + "yaml": "^2.5.1", "yeoman-generator": "^7.3.2", "yosay": "^3.0.0" }, "devDependencies": { - "eslint": "^9.8.0", + "eslint": "^9.11.1", "eslint-config-prettier": "^9.1.0", "eslint-plugin-prettier": "^5.2.1", "jest": "^29.7.0", - "lint-staged": "^15.2.8", + "lint-staged": "^15.2.10", "prettier": "^3.3.3", "yeoman-assert": "^3.1.1", - "yeoman-test": "^9.0.0" + "yeoman-test": "^9.1.0" }, "engines": { "npm": ">= 4.0.0" @@ -674,6 +674,16 @@ "node": "^18.18.0 || ^20.9.0 || >=21.1.0" } }, + "node_modules/@eslint/core": { + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/@eslint/core/-/core-0.6.0.tgz", + "integrity": "sha512-8I2Q8ykA4J0x0o7cg67FPVnehcqWTBehu/lmY+bolPFHGjh49YzGBMXTvpqVgEbBdvNCSxj6iFgiIyHzf03lzg==", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + } + }, "node_modules/@eslint/eslintrc": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-3.1.0.tgz", @@ -699,9 +709,9 @@ } }, "node_modules/@eslint/js": { - "version": "9.9.1", - "resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.9.1.tgz", - "integrity": "sha512-xIDQRsfg5hNBqHz04H1R3scSVwmI+KUbqjsQKHKQ1DAUSaUjYPReZZmS/5PNiKu1fUvzDd6H7DEDKACSEhu+TQ==", + "version": "9.11.1", + "resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.11.1.tgz", + "integrity": "sha512-/qu+TWz8WwPWc7/HcIJKi+c+MOm46GdVaSlTTQcaqaL53+GsoA6MxWp5PtTx48qbSP7ylM1Kn7nhvkugfJvRSA==", "dev": true, "license": "MIT", "engines": { @@ -718,6 +728,19 @@ "node": "^18.18.0 || ^20.9.0 || >=21.1.0" } }, + "node_modules/@eslint/plugin-kit": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/@eslint/plugin-kit/-/plugin-kit-0.2.0.tgz", + "integrity": "sha512-vH9PiIMMwvhCx31Af3HiGzsVNULDbyVkHXwlemn/B0TFj/00ho3y55efXrUZTfQipxoHC5u4xq6zblww1zm1Ig==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "levn": "^0.4.1" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + } + }, "node_modules/@humanwhocodes/module-importer": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/@humanwhocodes/module-importer/-/module-importer-1.0.1.tgz", @@ -1832,6 +1855,13 @@ "integrity": "sha512-nv+GSx77ZtXiJzwKdsASqi+YQ5Z7vwHsTP0JY2SiQgjGckkBRKZnk8nIM+7oUZ1VCtuTz0+By4qVR7fqzp/Dfg==", "license": "MIT" }, + "node_modules/@types/estree": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.6.tgz", + "integrity": "sha512-AYnb1nQyY49te+VRAVgmzfcgjYS91mY5P0TKUDCLEM+gNnA+3T6rWITXRLYCpahpqSQbN5cE+gHpnPyXjHWxcw==", + "dev": true, + "license": "MIT" + }, "node_modules/@types/expect": { "version": "1.20.4", "resolved": "https://registry.npmjs.org/@types/expect/-/expect-1.20.4.tgz", @@ -1892,6 +1922,13 @@ "@types/istanbul-lib-report": "*" } }, + "node_modules/@types/json-schema": { + "version": "7.0.15", + "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.15.tgz", + "integrity": "sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==", + "dev": true, + "license": "MIT" + }, "node_modules/@types/lodash": { "version": "4.17.7", "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.17.7.tgz", @@ -3225,20 +3262,24 @@ } }, "node_modules/eslint": { - "version": "9.9.1", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-9.9.1.tgz", - "integrity": "sha512-dHvhrbfr4xFQ9/dq+jcVneZMyRYLjggWjk6RVsIiHsP8Rz6yZ8LvZ//iU4TrZF+SXWG+JkNF2OyiZRvzgRDqMg==", + "version": "9.11.1", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-9.11.1.tgz", + "integrity": "sha512-MobhYKIoAO1s1e4VUrgx1l1Sk2JBR/Gqjjgw8+mfgoLE2xwsHur4gdfTxyTgShrhvdVFTaJSgMiQBl1jv/AWxg==", "dev": true, "license": "MIT", "dependencies": { "@eslint-community/eslint-utils": "^4.2.0", "@eslint-community/regexpp": "^4.11.0", "@eslint/config-array": "^0.18.0", + "@eslint/core": "^0.6.0", "@eslint/eslintrc": "^3.1.0", - "@eslint/js": "9.9.1", + "@eslint/js": "9.11.1", + "@eslint/plugin-kit": "^0.2.0", "@humanwhocodes/module-importer": "^1.0.1", "@humanwhocodes/retry": "^0.3.0", "@nodelib/fs.walk": "^1.2.8", + "@types/estree": "^1.0.6", + "@types/json-schema": "^7.0.15", "ajv": "^6.12.4", "chalk": "^4.0.0", "cross-spawn": "^7.0.2", @@ -3258,7 +3299,6 @@ "is-glob": "^4.0.0", "is-path-inside": "^3.0.3", "json-stable-stringify-without-jsonify": "^1.0.1", - "levn": "^0.4.1", "lodash.merge": "^4.6.2", "minimatch": "^3.1.2", "natural-compare": "^1.4.0", @@ -6152,9 +6192,9 @@ "license": "MIT" }, "node_modules/lint-staged": { - "version": "15.2.9", - "resolved": "https://registry.npmjs.org/lint-staged/-/lint-staged-15.2.9.tgz", - "integrity": "sha512-BZAt8Lk3sEnxw7tfxM7jeZlPRuT4M68O0/CwZhhaw6eeWu0Lz5eERE3m386InivXB64fp/mDID452h48tvKlRQ==", + "version": "15.2.10", + "resolved": "https://registry.npmjs.org/lint-staged/-/lint-staged-15.2.10.tgz", + "integrity": "sha512-5dY5t743e1byO19P9I4b3x8HJwalIznL5E1FWYnU6OWw33KxNBSLAc6Cy7F2PsFEO8FKnLwjwm5hx7aMF0jzZg==", "dev": true, "license": "MIT", "dependencies": { @@ -6164,7 +6204,7 @@ "execa": "~8.0.1", "lilconfig": "~3.1.2", "listr2": "~8.2.4", - "micromatch": "~4.0.7", + "micromatch": "~4.0.8", "pidtree": "~0.6.0", "string-argv": "~0.3.2", "yaml": "~2.5.0" @@ -8847,9 +8887,9 @@ "license": "ISC" }, "node_modules/yaml": { - "version": "2.5.0", - "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.5.0.tgz", - "integrity": "sha512-2wWLbGbYDiSqqIKoPjar3MPgB94ErzCtrNE1FdqGuaO0pi2JGjmE8aW8TDZwzU7vuxcGRdL/4gPQwQ7hD5AMSw==", + "version": "2.5.1", + "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.5.1.tgz", + "integrity": "sha512-bLQOjaX/ADgQ20isPJRvF0iRUHIxVhYvr53Of7wGcWlO2jvtUlH5m87DsmulFVxRpNLOnI4tB6p/oh8D7kpn9Q==", "license": "ISC", "bin": { "yaml": "bin.mjs" @@ -9091,9 +9131,9 @@ } }, "node_modules/yeoman-test": { - "version": "9.0.0", - "resolved": "https://registry.npmjs.org/yeoman-test/-/yeoman-test-9.0.0.tgz", - "integrity": "sha512-K7Pb7+/Pvy+1wNwt2yrOhfWEfJiYTPyxLjBytdnsShd78V3ieXuiQ+2uaiqVjcYqoukNbAVHcxS2yv5eja9VHg==", + "version": "9.1.0", + "resolved": "https://registry.npmjs.org/yeoman-test/-/yeoman-test-9.1.0.tgz", + "integrity": "sha512-gud8N/HJEFzOVVKCxX0bq/mlN265IBSlpfYejVrJFL/tFHEWBMcnnXH8DSzmggZHJKb46UmsXxdHNoJ9Px7T/Q==", "dev": true, "license": "MIT", "dependencies": { diff --git a/package.json b/package.json index 3d6b066..562ae3f 100644 --- a/package.json +++ b/package.json @@ -17,19 +17,19 @@ "test": "jest" }, "dependencies": { - "yaml": "^2.5.0", + "yaml": "^2.5.1", "yeoman-generator": "^7.3.2", "yosay": "^3.0.0" }, "devDependencies": { - "eslint": "^9.8.0", + "eslint": "^9.11.1", "eslint-config-prettier": "^9.1.0", "eslint-plugin-prettier": "^5.2.1", "jest": "^29.7.0", - "lint-staged": "^15.2.8", + "lint-staged": "^15.2.10", "prettier": "^3.3.3", "yeoman-assert": "^3.1.1", - "yeoman-test": "^9.0.0" + "yeoman-test": "^9.1.0" }, "type": "module", "license": "Apache-2.0"