diff --git a/README.md b/README.md index 72437c2..d6e458c 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ The generator will output a file saving your answers. This is useful if you want This command will run the 'nr-maven-build' generator: ``` -podman run --rm -it -v $PWD:/src --userns keep-id ghcr.io/bcgov-nr/nr-pipeline-template:latest -- nr-maven-build +podman run --rm -it -v ${PWD}:/src --userns keep-id ghcr.io/bcgov-nr/nr-pipeline-template:latest -- nr-maven-build ``` Note: You can run the command with or without the generator specified. diff --git a/generator-nr-maven-build/generators/app/index.js b/generator-nr-maven-build/generators/app/index.js index ffa91c4..3370490 100644 --- a/generator-nr-maven-build/generators/app/index.js +++ b/generator-nr-maven-build/generators/app/index.js @@ -14,29 +14,36 @@ export default class extends Generator { { type: 'input', name: 'projectName', - message: 'What is your project name?', + message: 'Project name:', store: true }, { type: 'input', name: 'serviceName', - message: 'What is your service name?', + message: 'Service name:', store: true }, { type: 'input', name: 'artifactoryProject', - message: 'What is your Artifactory project?', + message: 'Artifactory project:', default: "cc20", store: true }, { type: 'input', name: 'pomRoot', - message: 'What is your Maven pom file root?', + message: 'Maven pom file root:', default: "./", store: true }, + { + type: 'input', + name: 'unitTestsPath', + message: 'Path to unit tests (./.github/workflows/test.yaml):', + default: "", + store: true + }, { type: 'confirm', name: 'gitHubPackages', @@ -47,7 +54,7 @@ export default class extends Generator { { type: 'confirm', name: 'deployOnPrem', - message: 'Will you be deploying to on-premise servers?', + message: 'Deploy on-prem?', default: false, store: true } @@ -64,7 +71,7 @@ export default class extends Generator { this.templatePath('ci.yaml'), this.destinationPath('.github/workflows/ci.yaml'), { projectName: this.props.projectName, serviceName: this.props.serviceName, artifactoryProject: this.props.artifactoryProject, - pomRoot: this.props.pomRoot, gitHubPackages: this.props.gitHubPackages, deployOnPrem: this.props.deployOnPrem } + pomRoot: this.props.pomRoot, unitTestsPath: this.props.unitTestsPath, gitHubPackages: this.props.gitHubPackages, deployOnPrem: this.props.deployOnPrem } ); this.fs.copyTpl( this.templatePath('build-intention.json'), @@ -83,6 +90,12 @@ export default class extends Generator { ); } - this.config.save(); + this.config.set('projectName', this.props.projectName); + this.config.set('serviceName', this.props.serviceName); + this.config.set('artifactoryProject', this.props.artifactoryProject); + this.config.set('pomRoot', this.props.pomRoot); + this.config.set('unitTestsPath', this.props.unitTestsPath); + this.config.set('gitHubPackages', this.props.gitHubPackages); + this.config.set('deployOnPrem', this.props.deployOnPrem); } } diff --git a/generator-nr-maven-build/generators/app/templates/ci.yaml b/generator-nr-maven-build/generators/app/templates/ci.yaml index 995c9c4..edaca85 100644 --- a/generator-nr-maven-build/generators/app/templates/ci.yaml +++ b/generator-nr-maven-build/generators/app/templates/ci.yaml @@ -11,9 +11,18 @@ env: SERVICE_NAME: <%= serviceName %> jobs: +<% if (unitTestsPath) { -%> + test: + name: Test + uses: <%= unitTestsPath %> +<% } -%> + publish: name: Publish runs-on: ubuntu-latest +<% if (unitTestsPath) { -%> + needs: [test] +<% } -%> permissions: contents: read packages: write @@ -138,7 +147,8 @@ jobs: - name: Publish to GitHub Packages run: mvn --batch-mode -Dmaven.test.skip=true -Pgithub deploy --file <%= pomRoot %>pom.xml env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}<% } %> + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} +<% } -%> <% if (deployOnPrem) { %> # https://www.jenkins.io/doc/book/using/remote-access-api/ # https://plugins.jenkins.io/build-token-root/