Integration/showcase builder may (#279) #6
This file contains hidden or 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
name: PR Build and Deploy | ||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
paths: | ||
- "apps/**" | ||
- "packages/**" | ||
- "charts/**" | ||
types: | ||
- opened | ||
- synchronize | ||
- reopened | ||
- ready_for_review | ||
jobs: | ||
ready: | ||
name: "Check if PR is ready for review" | ||
runs-on: ubuntu-latest | ||
outputs: | ||
deploy: ${{ steps.ready_for_review.outputs.true_false }} | ||
build: ${{ steps.ready_for_review.outputs.owner_true_false }} | ||
steps: | ||
- id: ready_for_review | ||
run: | | ||
echo "true_false=${{ toJSON(github.event.pull_request.draft != true && github.repository_owner == 'bcgov') }}" >> $GITHUB_OUTPUT | ||
echo "owner_true_false=${{ toJSON(github.repository_owner == 'bcgov') }}" >> $GITHUB_OUTPUT | ||
test: | ||
name: "Run Tests" | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 15 | ||
needs: | ||
- ready | ||
if: ${{ always() && fromJSON(needs.ready.outputs.deploy) == true }} | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
- name: Run Tests | ||
id: run-tests | ||
uses: ./.github/actions/test | ||
with: | ||
node-version: '20' | ||
pnpm-version: '8' | ||
outputs: | ||
status: ${{ steps.run-tests.outputs.status }} | ||
build_api_server: | ||
name: "Build API Server" | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 10 | ||
needs: | ||
- ready | ||
- test | ||
if: ${{ always() && fromJSON(needs.ready.outputs.deploy) == true && needs.test.outputs.status == 'success' }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Build API Server Image | ||
uses: ./.github/actions/build_docker | ||
id: builder | ||
with: | ||
context: "." | ||
dockerfile: "./apps/bc-wallet-api-server/Dockerfile" | ||
image_name: ${{ github.repository_owner}}/bc-wallet-api-server | ||
registry: ghcr.io | ||
registry_username: ${{ github.repository_owner}} | ||
registry_password: ${{ secrets.GITHUB_TOKEN }} | ||
visibility: "public" | ||
outputs: | ||
image_tag: ${{ steps.builder.outputs.image_tag }} | ||
build_traction_adapter: | ||
name: "Build Traction Adapter" | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 10 | ||
needs: | ||
- ready | ||
- test | ||
if: ${{ always() && fromJSON(needs.ready.outputs.deploy) == true && needs.test.outputs.status == 'success' }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Build Traction Adapter Image | ||
uses: ./.github/actions/build_docker | ||
id: builder | ||
with: | ||
context: "." | ||
dockerfile: "./apps/bc-wallet-traction-adapter/Dockerfile" | ||
image_name: ${{ github.repository_owner}}/bc-wallet-traction-adapter | ||
registry: ghcr.io | ||
registry_username: ${{ github.repository_owner}} | ||
registry_password: ${{ secrets.GITHUB_TOKEN }} | ||
visibility: "public" | ||
outputs: | ||
image_tag: ${{ steps.builder.outputs.image_tag }} | ||
build_showcase_creator: | ||
name: "Build Showcase Creator" | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 10 | ||
needs: | ||
- ready | ||
- test | ||
if: ${{ always() && fromJSON(needs.ready.outputs.deploy) == true && needs.test.outputs.status == 'success' }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Build Showcase Creator Image | ||
uses: ./.github/actions/build_docker | ||
id: builder | ||
with: | ||
context: "." | ||
dockerfile: "./apps/bc-wallet-showcase-creator/Dockerfile" | ||
image_name: ${{ github.repository_owner}}/bc-wallet-showcase-creator | ||
registry: ghcr.io | ||
registry_username: ${{ github.repository_owner}} | ||
registry_password: ${{ secrets.GITHUB_TOKEN }} | ||
visibility: "public" | ||
outputs: | ||
image_tag: ${{ steps.builder.outputs.image_tag }} | ||
build_demo_server: | ||
name: "Build Demo Server" | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 10 | ||
needs: | ||
- ready | ||
- test | ||
if: ${{ always() && fromJSON(needs.ready.outputs.deploy) == true && needs.test.outputs.status == 'success' }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Build Demo Server Image | ||
uses: ./.github/actions/build_docker | ||
id: builder | ||
with: | ||
context: "." | ||
dockerfile: "./apps/bc-wallet-demo-server/Dockerfile" | ||
image_name: ${{ github.repository_owner}}/bc-wallet-demo-server | ||
registry: ghcr.io | ||
registry_username: ${{ github.repository_owner}} | ||
registry_password: ${{ secrets.GITHUB_TOKEN }} | ||
visibility: "public" | ||
outputs: | ||
image_tag: ${{ steps.builder.outputs.image_tag }} | ||
build_demo_web: | ||
name: "Build Demo Web" | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 10 | ||
needs: | ||
- ready | ||
- test | ||
if: ${{ always() && fromJSON(needs.ready.outputs.deploy) == true && needs.test.outputs.status == 'success' }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Build Demo Web Image | ||
uses: ./.github/actions/build_docker | ||
id: builder | ||
with: | ||
context: "." | ||
dockerfile: "./apps/bc-wallet-demo-web/Dockerfile" | ||
image_name: ${{ github.repository_owner}}/bc-wallet-demo-web | ||
registry: ghcr.io | ||
registry_username: ${{ github.repository_owner}} | ||
registry_password: ${{ secrets.GITHUB_TOKEN }} | ||
visibility: "public" | ||
outputs: | ||
image_tag: ${{ steps.builder.outputs.image_tag }} | ||
image-scan: | ||
name: "Image Scan" | ||
needs: [build_api_server, build_traction_adapter, build_showcase_creator, build_demo_server, build_demo_web, ready] | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 10 | ||
if: ${{ always() && fromJSON(needs.ready.outputs.deploy) == true && !(contains(needs.*.result, 'failure')) }} | ||
steps: | ||
- name: Run Trivy Image Scan | ||
uses: ./.github/actions/trivy-scan | ||
with: | ||
images: | | ||
ghcr.io/${{ github.repository_owner }}/bc-wallet-api-server:${{ needs.build_api_server.outputs.image_tag }}, | ||
ghcr.io/${{ github.repository_owner }}/bc-wallet-traction-adapter:${{ needs.build_traction_adapter.outputs.image_tag }}, | ||
ghcr.io/${{ github.repository_owner }}/bc-wallet-demo-web:${{ needs.build_demo_web.outputs.image_tag }}, | ||
ghcr.io/${{ github.repository_owner }}/bc-wallet-showcase-creator:${{ needs.build_showcase_creator.outputs.image_tag }}, | ||
ghcr.io/${{ github.repository_owner }}/bc-wallet-demo-server:${{ needs.build_demo_server.outputs.image_tag }} | ||
# scan-ref: '' | ||
# scan-title: '' | ||
# scan-type: '' | ||
deploy: | ||
name: "Deploy PR Environment" | ||
environment: development | ||
runs-on: ubuntu-latest | ||
needs: | ||
- ready | ||
- build_api_server | ||
- build_traction_adapter | ||
- build_showcase_creator | ||
- build_demo_server | ||
- build_demo_web | ||
if: ${{ always() && fromJSON(needs.ready.outputs.deploy) == true && !(contains(needs.*.result, 'failure')) }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Install OpenShift CLI tools | ||
uses: redhat-actions/openshift-tools-installer@v1 | ||
with: | ||
oc: "4.14" | ||
- name: Authenticate and set context | ||
uses: redhat-actions/oc-login@v1 | ||
with: | ||
openshift_server_url: ${{ secrets.OPENSHIFT_SERVER }} | ||
openshift_token: ${{ secrets.OPENSHIFT_TOKEN }} | ||
certificate_authority_data: ${{ secrets.OPENSHIFT_CA_CRT }} | ||
namespace: ${{ secrets.OPENSHIFT_NAMESPACE }} | ||
- name: Deploy PR Environment with Helm | ||
run: | | ||
cd charts/bc-wallet | ||
# helm dependency update | ||
helm upgrade --install pr-${{ github.event.number }}-bc-wallet --namespace ${{ secrets.OPENSHIFT_NAMESPACE }} -f ./values.yaml \ | ||
--set api_server.image.repository=ghcr.io/${{ github.repository_owner }}/bc-wallet-api-server --set api_server.image.tag=${{ needs.build_api_server.outputs.image_tag }} --set traction_adapter.image.repository=ghcr.io/${{ github.repository_owner }}/bc-wallet-traction-adapter --set traction_adapter.image.tag=${{ needs.build_traction_adapter.outputs.image_tag }} --set showcase_creator.image.repository=ghcr.io/${{ github.repository_owner }}/bc-wallet-showcase-creator --set showcase_creator.image.tag=${{ needs.build_showcase_creator.outputs.image_tag }} --set demo_web.image.repository=ghcr.io/${{ github.repository_owner }}/bc-wallet-demo-web --set demo_web.image.tag=${{ needs.build_demo_web.outputs.image_tag }} --set demo_server.image.repository=ghcr.io/${{ github.repository_owner }}/bc-wallet-demo-server --set demo_server.image.tag=${{ needs.build_demo_server.outputs.image_tag }} . --wait | ||
- name: Restart PR Deployments | ||
run: | | ||
oc rollout restart deployment/pr-${{ github.event.number }}-bc-wallet-api-server | ||
oc rollout restart deployment/pr-${{ github.event.number }}-bc-wallet-traction-adapter | ||
oc rollout restart deployment/pr-${{ github.event.number }}-bc-wallet-showcase-creator | ||
oc rollout restart deployment/pr-${{ github.event.number }}-bc-wallet-demo-server | ||
oc rollout restart deployment/pr-${{ github.event.number }}-bc-wallet-demo-web | ||
deploymenturls: | ||
name: PR Deployment URLs comment | ||
runs-on: ubuntu-latest | ||
needs: | ||
- deploy | ||
if: ${{ always() && fromJSON(needs.ready.outputs.deploy) == true && !(contains(needs.*.result, 'failure')) }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Find Comment | ||
uses: peter-evans/find-comment@v3 | ||
id: fc | ||
with: | ||
issue-number: ${{ github.event.number }} | ||
comment-author: "github-actions[bot]" | ||
body-includes: PR Deployment URLs ready for review. | ||
- name: Create comment | ||
if: steps.fc.outputs.comment-id == '' | ||
uses: peter-evans/create-or-update-comment@v4 | ||
with: | ||
issue-number: ${{ github.event.number }} | ||
body: | | ||
| Deployment | Resource | Location | | ||
| --- | --- | --- | | ||
| API Server | | https://pr-${{ github.event.number }}-api-server-dev.apps.silver.devops.gov.bc.ca/ | | ||
| Traction Adapter | | https://pr-${{ github.event.number }}-traction-adapter-dev.apps.silver.devops.gov.bc.ca/ | | ||
| Demo Web | | https://pr-${{ github.event.number }}-demo-web-dev.apps.silver.devops.gov.bc.ca/ | | ||
| Showcase Creator | | https://pr-${{ github.event.number }}-showcase-creator-dev.apps.silver.devops.gov.bc.ca/ | | ||
| Demo Server | | https://pr-${{ github.event.number }}-demo-server-dev.apps.silver.devops.gov.bc.ca/ | | ||
PR Deployment URLs ready for review. |