diff --git a/generator-nr-maven-build/generators/app/index.js b/generator-nr-maven-build/generators/app/index.js index 8d636b5..faed13f 100644 --- a/generator-nr-maven-build/generators/app/index.js +++ b/generator-nr-maven-build/generators/app/index.js @@ -21,22 +21,36 @@ module.exports = class extends Generator { { type: 'input', name: 'serviceName', - message: 'what is your service name?', + message: 'What is your service name?', store: true }, { type: 'input', name: 'artifactoryProject', - message: 'what is your Artifactory project?', + message: 'What is your Artifactory project?', default: "cc20", store: true }, { type: 'input', name: 'pomRoot', - message: 'what is your Maven pom file root?', + message: 'What is your Maven pom file root?', default: "./", store: true + }, + { + type: 'confirm', + name: 'gitHubPackages', + message: 'Publish to GitHub Packages?', + default: false, + store: true + }, + { + type: 'confirm', + name: 'deployOnPrem', + message: 'Will you be deploying to on-premise servers?', + default: false, + store: true } ]; @@ -51,7 +65,7 @@ module.exports = 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 } + pomRoot: this.props.pomRoot, gitHubPackages: this.props.gitHubPackages, deployOnPrem: this.props.deployOnPrem } ); this.fs.copyTpl( this.templatePath('build-intention.json'), @@ -62,10 +76,12 @@ module.exports = class extends Generator { this.templatePath('build-intention.sh'), this.destinationPath('.github/workflows/build-intention.sh') ); - this.fs.copyTpl( - this.templatePath('deployment-intention.json'), - this.destinationPath('.jenkins/deployment-intention.json'), - { projectName: this.props.projectName, serviceName: this.props.serviceName } - ); + if (this.props.deployOnPrem) { + this.fs.copyTpl( + this.templatePath('deployment-intention.json'), + this.destinationPath('.jenkins/deployment-intention.json'), + { projectName: this.props.projectName, serviceName: this.props.serviceName } + ); + } } }; diff --git a/generator-nr-maven-build/generators/app/templates/ci.yaml b/generator-nr-maven-build/generators/app/templates/ci.yaml index e00f232..409f66e 100644 --- a/generator-nr-maven-build/generators/app/templates/ci.yaml +++ b/generator-nr-maven-build/generators/app/templates/ci.yaml @@ -20,6 +20,8 @@ jobs: # Map a step output to a job output outputs: project_version: ${{ steps.set-build-output-parameters.outputs.project_version }} + intention_id: ${{ steps.set-intention-id.outputs.intention_id }} + steps: - uses: actions/checkout@v4 - name: Set up Java for publishing to OpenShift Artifactory @@ -69,6 +71,13 @@ jobs: with: action_token: ${{ env.ACTION_TOKEN_LOGIN }} + - name: Set intention ID for deployment job + id: set-intention-id + run: | + echo "intention_id=${INTENTION_ID}" >> $GITHUB_OUTPUT + env: + INTENTION_ID: ${{ env.INTENTION_ID }} + - name: Publish to OpenShift Artifactory run: mvn --batch-mode -Dmaven.test.skip=true -Partifactory deploy env: @@ -111,44 +120,45 @@ jobs: uses: bcgov-nr/action-broker-intention-close@v1 with: intention_token: ${{ env.INTENTION_TOKEN }} - - # ghcr: - # name: GHCR - # runs-on: ubuntu-latest - # permissions: - # contents: read - # packages: write - # steps: - # - uses: actions/checkout@v4 - # - name: Set up Java for publishing to GitHub Packages - # uses: actions/setup-java@v3 - # with: - # java-version: '8' - # distribution: 'temurin' - # cache: maven - # - name: Publish to GitHub Packages - # run: mvn --batch-mode -Dmaven.test.skip=true -Pgithub deploy - # env: - # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - +<% if (gitHubPackages) { %> + ghcr: + name: GHCR + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - uses: actions/checkout@v4 + - name: Set up Java for publishing to GitHub Packages + uses: actions/setup-java@v3 + with: + java-version: '8' + distribution: 'temurin' + cache: maven + - 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 }}<% } %> +<% if (deployOnPrem) { %> # https://www.jenkins.io/doc/book/using/remote-access-api/ # https://plugins.jenkins.io/build-token-root/ - # jenkins: - # name: Jenkins Build - # needs: [build] - # runs-on: ubuntu-latest - # steps: - # - name: Submit a job to Jenkins - # env: - # job: buildByToken/buildWithParameters?job=edqa/edqa-war - # url: https://cd-io.nrs.gov.bc.ca - # PROJECT_VERSION: ${{ needs.build.outputs.project_version }} - # TRACE_ID: ${{ needs.build.outputs.build_trace_id }} - # run: | - # curl -v --data-urlencode "token=${{ secrets.JENKINS_TOKEN }}" --data-urlencode "githubToken=${{ secrets.GITHUB_TOKEN }}" \ - # --data-urlencode "artifactoryBuildNumber=${{ github.run_number }}" --data-urlencode "cdVersion=${{ env.PROJECT_VERSION }}" \ - # --data-urlencode "traceId=${{ env.TRACE_ID }}" -H "Connection: close" ${{ env.url }}/${{ env.job }} - # # The automatically generated GitHub token will expire when the workflow ends. We need to wait so the job has time to clone the repo. - # - name: Sleep for 30 seconds - # run: sleep 30s - # shell: bash + jenkins: + name: Jenkins Build + needs: [build] + runs-on: ubuntu-latest + steps: + - name: Submit a job to Jenkins + env: + job: buildByToken/buildWithParameters?job=<%= projectName %>/<%= serviceName %> + url: https://cd.io.nrs.gov.bc.ca/ + PROJECT_VERSION: ${{ needs.build.outputs.project_version }} + INTENTION_ID: ${{ needs.build.outputs.intention_id }} + run: | + curl -v --data-urlencode "token=${{ secrets.JENKINS_TOKEN }}" --data-urlencode "githubToken=${{ secrets.GITHUB_TOKEN }}" \ + --data-urlencode "artifactoryBuildNumber=${{ github.run_number }}" --data-urlencode "cdVersion=${{ env.PROJECT_VERSION }}" \ + --data-urlencode "intentionId=${{ env.INTENTION_ID }}" -H "Connection: close" ${{ env.url }}/${{ env.job }} + # The automatically generated GitHub token will expire when the workflow ends. We need to wait so the job has time to clone the repo. + - name: Sleep for 30 seconds + run: sleep 30s + shell: bash +<% } -%> \ No newline at end of file