🧱 Build and Push feature/CB2-12113 #22
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
name: 🧱 Build and Push | |
run-name: 🧱 Build and Push ${{ github.ref_name }} | |
env: | |
bucket-name: cvs-services | |
on: | |
workflow_call: | |
workflow_dispatch: | |
inputs: | |
ignore-test-failures: | |
type: boolean | |
description: Ignore Test Failures | |
default: false | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref_name }} | |
cancel-in-progress: true | |
permissions: | |
id-token: write | |
contents: write | |
jobs: | |
environment: | |
name: 🧹 Prepare Environment | |
runs-on: ubuntu-latest | |
outputs: | |
environment-name: ${{ steps.environment.outputs.environment-name }} | |
environment-type: ${{ steps.environment.outputs.environment-type }} | |
github-branch: ${{ steps.environment.outputs.github-branch }} | |
commit: ${{ steps.commit.outputs.commit }} | |
package-name: ${{ steps.name.outputs.package-name }} | |
steps: | |
- name: Generate Package Name | |
id: name | |
run: | | |
repo=${{ github.repository }} | |
echo "package-name=${repo#dvsa/}" >> $GITHUB_OUTPUT | |
echo "package-name=${repo#dvsa/}" >> $GITHUB_STEP_SUMMARY | |
- name: 🪪 Get Credentials | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
role-to-assume: ${{ secrets.CVS_MGMT_AWS_ROLE }} | |
aws-region: ${{ vars.DVSA_AWS_REGION}} | |
role-session-name: GHA_TagDevelop | |
- name: 📥 Get Codebase | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.ref_name }} | |
- name: ↕️ Get Environment Details | |
id: environment | |
uses: dvsa/cvs-github-actions/environment@develop | |
with: | |
environment: ${{ github.ref_name }} | |
- name: Get Commit SHA | |
id: commit | |
run: | | |
# Get the branch Commit ID | |
commit_id=$(git rev-parse HEAD) | |
echo "commit=${commit_id}" | |
echo "commit=${commit_id}" >> $GITHUB_OUTPUT | |
echo "Commit ID: ${commit_id}" >> $GITHUB_STEP_SUMMARY | |
build-service: | |
name: 🧱 Build ${{ needs.environment.outputs.package-name }} | |
runs-on: | |
- ${{ needs.environment.outputs.package-name }} | |
needs: environment | |
steps: | |
- name: 🪪 Get Credentials | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
role-to-assume: ${{ secrets.CVS_MGMT_AWS_ROLE }} | |
aws-region: ${{ vars.DVSA_AWS_REGION }} | |
role-session-name: GHA_BuildServices | |
- name: 📥 Get Codebase | |
uses: actions/checkout@v4 | |
- name: Get Commit SHA | |
id: commit | |
run: | | |
# Get the branch Commit ID | |
commit_id=$(git rev-parse HEAD) | |
echo "commit=${commit_id}" | |
echo "commit=${commit_id}" >> $GITHUB_OUTPUT | |
echo "Commit ID: ${commit_id}" >> $GITHUB_STEP_SUMMARY | |
- name: 🗒️ Process Manifest Data | |
id: manifest | |
run: | | |
# Generate Manifest Outputs & Identify Build Requirements | |
hash_files="[]" | |
if [[ -f "manifest.json" ]]; then | |
package=$(jq -r '.name' manifest.json) | |
echo "package=$(jq -r '.name' manifest.json)" >> $GITHUB_OUTPUT | |
echo "language=$(jq -r '.language' manifest.json)" >> $GITHUB_OUTPUT | |
echo "liquibase=$(jq -r '.liquibase' manifest.json)" >> $GITHUB_OUTPUT | |
# Check for existing Hash | |
hashes=$(aws s3api list-objects-v2 --bucket ${{ env.bucket-name }} --query "Contents[?Key.contains(@,'${{ steps.commit.outputs.commit }}.zip') && Key.contains(@,'$package')].Key" | jq -rc) | |
if [[ $(awk '{print index($0,"${{ steps.commit.outputs.commit }}")}' <<< $hashes) == 0 ]]; then | |
echo "Current Hash does not exist" | |
build_package=true | |
else | |
echo "Current Hash exists" | |
hash_files=$hashes | |
build_package=false | |
fi | |
else | |
build_package=false | |
fi | |
# Add flag to build or skip | |
echo "build-package=${build_package}" >> $GITHUB_OUTPUT | |
echo "Build Package: ${build_package}" >> $GITHUB_STEP_SUMMARY | |
- name: 🏗️ Build Node Function | |
uses: dvsa/cvs-github-actions/build-node-function@develop | |
if: ${{ steps.manifest.outputs.build-package == 'true' && steps.manifest.outputs.language == 'node' }} | |
env: | |
GH_TOKEN: ${{ secrets.GH_TOKEN }} | |
with: | |
commit-sha: ${{ steps.commit.outputs.commit }} | |
branch: ${{needs.environment.outputs.github-branch }} | |
mysql_liquibase: ${{ steps.manifest.outputs.liquibase }} | |
mysql_user: ${{ secrets.MYSQL_USER }} | |
mysql_password: ${{ secrets.MYSQL_PASS }} | |
continue-on-error: ${{ inputs.ignore-test-failures }} | |
- name: 🏗️ Build Java Function | |
uses: dvsa/cvs-github-actions/build-java-function@develop | |
if: ${{ steps.manifest.outputs.build-package == 'true' && steps.manifest.outputs.language == 'java' }} | |
- name: 📤 Upload Artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ${{ needs.environment.outputs.package-name }} | |
path: | | |
${{ steps.commit.outputs.commit }}*.zip |