name: E2E Build and Deploy Micro-Frontend for Dashboard on: workflow_call: inputs: ENVIRONMENT: description: Environment type: string required: true default: "qa" MFE_NAME: description: MFE Name type: string required: true BASE_URL: description: Base url for the bff api type: string required: false AGGREGATED_BASE_URL: description: Temp base url for the bff api type: string required: false COMPASS_SETTINGS_API_BASE_URL: description: Compass settings base url type: string required: false SETTLEMENTS_API_BASE_URL: description: Settlements API base url type: string required: false TRANSACTIONS_API_BASE_URL: description: Transactions API base url type: string required: false TRANSACTIONS_BREAKDOWN_API_BASE_URL: description: Transactions Breakdown API base url type: string required: false OPEN_BANKING_BASE_URL: description: Open banking API base url type: string required: false ROLE_TO_ASSUME: type: string required: true BUCKET_NAME: description: Bucket where your MFE will be persisted type: string required: true NO_BUMP_MESSAGE: description: Partial commit message that indicates build should be skipped type: string required: false default: "#none" jobs: make-build-decision: name: Make build decision runs-on: [self-hosted, linux, eks] steps: - id: make-build-decision uses: cko-tech-finance/gh-actions-workflows/.github/actions/make-build-decision@v1 with: no-bump-message: ${{ inputs.NO_BUMP_MESSAGE }} outputs: decision: ${{ steps.make-build-decision.outputs.decision }} build-and-deploy: name: Build and Deploy environment: cko-${{inputs.ENVIRONMENT}} needs: make-build-decision if: needs.make-build-decision.outputs.decision == 'build' runs-on: [self-hosted, linux, eks] steps: - name: Checkout repository uses: actions/checkout@v4 with: fetch-depth: 0 - name: Configure AWS credentials for NPMRC uses: aws-actions/configure-aws-credentials@v1 with: aws-region: eu-west-1 role-duration-seconds: 3600 role-skip-session-tagging: false - name: Create npmrc uses: cko-core-engineering/actions/create-npmrc@v4 - name: Setup AWS CodeArtifact run: npm config --location project set @infinity:registry=https://cko-packages-791259062566.d.codeartifact.eu-west-1.amazonaws.com/npm/cko-packages/ - name: Copy npmrc run: | if [ -d "./packages" ]; then cp .npmrc ./packages/microfrontend-ui/.npmrc cp .npmrc ./packages/standalone-ui/.npmrc else echo "Packages folder does not exist. Skipping npmrc copy." fi - name: Install Python uses: actions/setup-python@v4 with: python-version: "3.7" - name: Install AWS cli shell: bash run: | python -m pip install --upgrade pip pip install awscli - name: Configure AWS credentials for deployment uses: aws-actions/configure-aws-credentials@v1 with: aws-region: eu-west-1 role-to-assume: ${{ inputs.ROLE_TO_ASSUME }} role-duration-seconds: 3600 role-skip-session-tagging: false - name: Setup Node Environment uses: actions/setup-node@v3 with: node-version-file: ".nvmrc" cache: 'yarn' - name: Setup yarn run: npm install -g yarn - name: Install dependencies run: yarn install - name: Install GitVersion uses: GitTools/actions/gitversion/setup@v0 with: versionSpec: 5.x - name: Run GitVersion id: gitversion uses: GitTools/actions/gitversion/execute@v0 - name: Display build version run: echo "Building version ${{ steps.gitversion.outputs.FullSemVer }}" - name: Determine working directory and prepare build command id: build-prep shell: bash run: | MFE_NAME_SLUG=$(echo "${{ inputs.MFE_NAME }}" | sed 's/_/-/g') VERSION="${{ steps.gitversion.outputs.FullSemVer }}" if [ -d "./packages/microfrontend-ui" ]; then echo "working-directory=." >> $GITHUB_OUTPUT echo "build-command=cd packages/microfrontend-ui && yarn build:dashboard-module && cd ../.. && mkdir -p $MFE_NAME_SLUG/$VERSION && cp -r packages/microfrontend-ui/dist/${{ inputs.MFE_NAME }}/$VERSION/* $MFE_NAME_SLUG/$VERSION/" >> $GITHUB_OUTPUT echo "build-output-path=$MFE_NAME_SLUG/$VERSION" >> $GITHUB_OUTPUT else echo "working-directory=." >> $GITHUB_OUTPUT echo "build-command=yarn build:dashboard-module && mkdir -p $MFE_NAME_SLUG/$VERSION && cp -r dist/${{ inputs.MFE_NAME }}/$VERSION/* $MFE_NAME_SLUG/$VERSION/" >> $GITHUB_OUTPUT echo "build-output-path=$MFE_NAME_SLUG/$VERSION" >> $GITHUB_OUTPUT fi - name: Build artifact id: build-artifact-step uses: cko-core-engineering/actions/build-frontend-artifact@7.4.0 env: BASE_URL: ${{ inputs.BASE_URL }} AGGREGATED_BASE_URL: ${{ inputs.AGGREGATED_BASE_URL }} COMPASS_SETTINGS_API_BASE_URL: ${{ inputs.COMPASS_SETTINGS_API_BASE_URL }} SETTLEMENTS_API_BASE_URL: ${{ inputs.SETTLEMENTS_API_BASE_URL }} TRANSACTIONS_API_BASE_URL: ${{ inputs.TRANSACTIONS_API_BASE_URL }} TRANSACTIONS_BREAKDOWN_API_BASE_URL: ${{ inputs.TRANSACTIONS_BREAKDOWN_API_BASE_URL }} VERSION_NUMBER: ${{ steps.gitversion.outputs.FullSemVer }} OPEN_BANKING_BASE_URL: ${{ inputs.OPEN_BANKING_BASE_URL }} with: build-command: ${{ steps.build-prep.outputs.build-command }} working-directory: ${{ steps.build-prep.outputs.working-directory }} build-output-path: ${{ steps.build-prep.outputs.build-output-path }} artifact-name: ${{ inputs.MFE_NAME }}-${{ inputs.ENVIRONMENT }}-${{ steps.gitversion.outputs.FullSemVer }} - name: Upload artifact uses: cko-core-engineering/actions/upload-frontend-artifact-s3@7.4.0 with: artifact-name: ${{ inputs.MFE_NAME }}-${{ inputs.ENVIRONMENT }}-${{ steps.gitversion.outputs.FullSemVer }} aws-role-arn: ${{ inputs.ROLE_TO_ASSUME }} datadog-api-key: ${{ secrets.DATADOG_API_KEY }} mfe-name: ${{ inputs.MFE_NAME }} s3-bucket: ${{ inputs.BUCKET_NAME }} version: ${{ steps.gitversion.outputs.FullSemVer }} # - name: Upload new build artifacts and replace remoteEntry.js # shell: bash # run: | # VERSION="${{ steps.gitversion.outputs.FullSemVer }}" # # if [ -d "./packages/microfrontend-ui" ]; then # cd packages/microfrontend-ui # VERSIONED_FOLDER="./dist/$VERSION" # else # VERSIONED_FOLDER="./dist/$VERSION" # fi # # aws s3 cp $VERSIONED_FOLDER s3://${{ inputs.BUCKET_NAME }}/$VERSION/ --recursive --content-type "application/javascript" # # if [ -f "$VERSIONED_FOLDER/remoteEntry.js" ]; then # aws s3 cp $VERSIONED_FOLDER/remoteEntry.js s3://${{ inputs.BUCKET_NAME }}/remoteEntry.js --content-type "application/javascript" # fi