Skip to content

Commit

Permalink
Merge pull request #21 from bcgov-nr/feat/unitTests
Browse files Browse the repository at this point in the history
Add unit tests
  • Loading branch information
andrwils authored Feb 8, 2024
2 parents e9a4798 + 32a7a6c commit 9c47868
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
27 changes: 20 additions & 7 deletions generator-nr-maven-build/generators/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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
}
Expand All @@ -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'),
Expand All @@ -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);
}
}
12 changes: 11 additions & 1 deletion generator-nr-maven-build/generators/app/templates/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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/
Expand Down

0 comments on commit 9c47868

Please sign in to comment.