Skip to content

Refactor components for improved readability and maintainability #11

Refactor components for improved readability and maintainability

Refactor components for improved readability and maintainability #11

Workflow file for this run

name: PR Build and Deploy
on:
pull_request:
branches:
# - main
- showcase-builder
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.tag=${{ needs.build_api_server.outputs.image_tag }} --set traction_adapter.image.tag=${{ needs.build_traction_adapter.outputs.image_tag }} --set showcase_creator.image.tag=${{ needs.build_showcase_creator.outputs.image_tag }} --set demo_web.image.tag=${{ needs.build_demo_web.outputs.image_tag }} --set demo_server.image.tag=${{ needs.build_demo_server.outputs.image_tag }} \
--set api_server.env.ENCRYPTION_KEY=${{secrets.ENCRYPTION_KEY}} \
--set api_server.env.OIDC_CLIENT_SECRET=${{secrets.OIDC_CLIENT_SECRET}} \
--set api_server.env.OIDC_CLIENT_ID=${{secrets.OIDC_CLIENT_ID}} \
--set traction_adapter.env.TRACTION_DEFAULT_API_KEY=${{secrets.TRACTION_DEFAULT_API_KEY}} \
--set demo_server.env.TRACTION_WEBHOOK_SECRET=${{secrets.TRACTION_WEBHOOK_SECRET}} \
--set rabbitmq.auth.password=${{secrets.RABBITMQ_PASSWORD}} \
. --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.