-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: workflow changes for tagging and deploying releases
- Loading branch information
Showing
7 changed files
with
268 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,8 @@ | |
}, | ||
"package": { | ||
"version": "", | ||
"buildVersion": "" | ||
"buildVersion": "", | ||
"buildNumber": 0 | ||
} | ||
} | ||
], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
generator-nr-maven-build/generators/app/templates/deploy.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
name: Deploy | ||
|
||
on: | ||
workflow_dispatch: | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
env: | ||
SERVICE_PROJECT: <%= projectName %> | ||
SERVICE_NAME: <%= serviceName %> | ||
JOB: buildByToken/buildWithParameters?job=<%= projectName %>/<%= serviceName %> | ||
URL: https://cd.io.nrs.gov.bc.ca | ||
|
||
jobs: | ||
call-build: | ||
name: Build | ||
if: ${{ ! startsWith(github.ref, 'refs/tags/') }} | ||
uses: ./.github/workflows/build.yaml | ||
secrets: inherit | ||
|
||
deploy-build: | ||
name: Deploy development version | ||
if: ${{ ! startsWith(github.ref, 'refs/tags/') }} | ||
needs: call-build | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Submit a job to Jenkins | ||
run: | | ||
curl \ | ||
--data-urlencode "token=${{ secrets.JENKINS_TOKEN }}" \ | ||
--data-urlencode "githubToken=${{ secrets.GITHUB_TOKEN }}" \ | ||
--data-urlencode "artifactoryBuildNumber=${{ github.run_number }}" \ | ||
--data-urlencode "cdVersion=${{ needs.call-build.outputs.project_version }}" \ | ||
--data-urlencode "gitBranch=${{ needs.call-build.outputs.branch }}" \ | ||
--data-urlencode "intentionId=${{ needs.call-build.outputs.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 | ||
|
||
deploy-tag: | ||
name: Deploy release version | ||
if: ${{ startsWith(github.ref, 'refs/tags/') }} | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Set project version | ||
id: set-project-version | ||
run: | | ||
TAG=${{ github.ref_name }} | ||
VERSION=${TAG#v} | ||
echo "project_version=${VERSION}" >> $GITHUB_OUTPUT | ||
- name: Set build number and build guid (intention) | ||
id: set-build-guid-number | ||
run: | | ||
RESPONSE=$(curl -s -X 'POST' \ | ||
"${BROKER_URL}/v1/intention/search?where=%7B%22actions.action%22%3A%22package-build%22%2C%22actions.service.project%22%3A%22${SERVICE_PROJECT}%22%2C%22actions.service.name%22%3A%22${SERVICE_NAME}%22%2C%22actions.package.version%22%3A%22${PROJECT_VERSION}%22%7D&offset=0&limit=1" \ | ||
-H 'accept: application/json' \ | ||
-H 'Authorization: Bearer '"${BROKER_JWT}"'' \ | ||
-d '') | ||
echo "build_number=$(echo ${RESPONSE} | jq -r '.data[].actions[].package.buildNumber')" >> $GITHUB_OUTPUT | ||
echo "build_guid=$(echo ${RESPONSE} | jq -r '.data[].id')" >> $GITHUB_OUTPUT | ||
env: | ||
BROKER_URL: https://nr-broker.apps.silver.devops.gov.bc.ca | ||
BROKER_JWT: ${{ secrets.BROKER_JWT }} | ||
SERVICE_PROJECT: ${{ env.SERVICE_PROJECT }} | ||
SERVICE_NAME: ${{ env.SERVICE_NAME }} | ||
PROJECT_VERSION: ${{ steps.set-project-version.outputs.project_version }} | ||
- name: Submit a job to Jenkins | ||
run: | | ||
curl \ | ||
--data-urlencode "token=${{ secrets.JENKINS_TOKEN }}" \ | ||
--data-urlencode "githubToken=${{ secrets.GITHUB_TOKEN }}" \ | ||
--data-urlencode "artifactoryBuildNumber=${{ steps.set-build-guid-number.outputs.build_number }}" \ | ||
--data-urlencode "cdVersion=${{ steps.set-project-version.outputs.project_version }}" \ | ||
--data-urlencode "gitBranch=main" \ | ||
--data-urlencode "intentionId=${{ steps.set-build-guid-number.outputs.build_guid }}" \ | ||
--data-urlencode "gitTag=${{ github.ref_name }}" \ | ||
-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 |
Oops, something went wrong.