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
| # Notes: | |
| # - Pull request workflows creates and validate DBmaestro packages. | |
| # - Linux shell runner executes bash for every job. | |
| # Pull request to Release_Source branch will create package with a names derived from the changed folders/files. | |
| # Execution order will be alphabetical by package name. | |
| # PR merge will trigger upgrade to RS with workflow 'upgrade-environment.yml' | |
| name: Git - Build Package (Linux) | |
| # on: | |
| # pull_request: | |
| # branches: | |
| # - Release_Source | |
| env: | |
| GIT_DEPTH: 1 | |
| AGENT_JAR: "/opt/dbmaestro/agent/DBmaestroAgent.jar" | |
| PROJECT_NAME: "Demo-PSQL" | |
| DBMAESTRO_USE_SSL: "True" | |
| DBMAESTRO_SERVER: "${{ vars.DBMAESTRO_SERVER }}" | |
| DBMAESTRO_AUTH_TYPE: "DBmaestroAccount" | |
| DBMAESTRO_USER: "${{ secrets.DBMAESTRO_USER }}" | |
| DBMAESTRO_PASSWORD: "${{ secrets.DBMAESTRO_PASSWORD }}" | |
| jobs: | |
| # This job detects changed packages by comparing with the base branch | |
| detect_changed_packages: | |
| name: Detect Changed Packages | |
| runs-on: ubuntu-latest | |
| outputs: | |
| matrix: ${{ steps.set-matrix.outputs.matrix }} | |
| has-packages: ${{ steps.set-matrix.outputs.has-packages }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Detect Changed Folders in packages/ | |
| id: set-matrix | |
| shell: bash | |
| run: | | |
| # Get the list of changed files | |
| changed_files=$(git diff --name-only origin/${{ github.base_ref }} HEAD) | |
| # Extract unique package folders (first directory under packages/) | |
| packages=() | |
| while IFS= read -r file; do | |
| if [[ $file =~ ^packages/([^/]+) ]]; then | |
| package_name="${BASH_REMATCH[1]}" | |
| if [[ ! " ${packages[@]} " =~ " ${package_name} " ]]; then | |
| packages+=("$package_name") | |
| fi | |
| fi | |
| done <<< "$changed_files" | |
| if [ ${#packages[@]} -eq 0 ]; then | |
| echo "No changes in packages/ folder detected" | |
| matrix='[{"package":""}]' | |
| echo "has-packages=false" >> $GITHUB_OUTPUT | |
| else | |
| echo "Detected changed packages: ${packages[*]}" | |
| # Sort packages and convert to JSON array | |
| IFS=$'\n' sorted=($(sort <<<"${packages[*]}")) | |
| unset IFS | |
| matrix="[" | |
| for i in "${!sorted[@]}"; do | |
| if [ $i -gt 0 ]; then | |
| matrix="$matrix," | |
| fi | |
| matrix="$matrix{\"package\":\"${sorted[$i]}\"}" | |
| done | |
| matrix="$matrix]" | |
| echo "has-packages=true" >> $GITHUB_OUTPUT | |
| fi | |
| echo "matrix=$matrix" | |
| echo "matrix=$matrix" >> $GITHUB_OUTPUT | |
| create_package: | |
| name: Create Package | |
| runs-on: ubuntu-latest | |
| needs: detect_changed_packages | |
| if: needs.detect_changed_packages.outputs.has-packages == 'true' | |
| strategy: | |
| max-parallel: 1 | |
| matrix: | |
| item: ${{ fromJson(needs.detect_changed_packages.outputs.matrix) }} | |
| env: | |
| PACKAGE_NAME: ${{ matrix.item.package }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Summary | |
| shell: bash | |
| run: | | |
| cat >> $GITHUB_STEP_SUMMARY << EOF | |
| ## :package: Package Creation Summary | |
| | Property | Value | | |
| |----------|-------| | |
| | **Package Name** | $PACKAGE_NAME | | |
| | **Project Name** | $PROJECT_NAME | | |
| | **Target Branch** | ${{ github.base_ref }} | | |
| | **PR Number** | ${{ github.event.pull_request.number }} | | |
| | **Created By** | ${{ github.actor }} | | |
| EOF | |
| - name: Create Package | |
| shell: bash | |
| run: | | |
| # ===== Create Package ===== | |
| echo "==== Branch name: $PACKAGE_NAME ====" | |
| echo "==== Target branch: ${{ github.base_ref }} ====" | |
| echo "==== PR Number: ${{ github.event.pull_request.number }} ====" | |
| if [ ! -d "packages/$PACKAGE_NAME" ]; then | |
| echo "==== Folder $PACKAGE_NAME does not exist. ====" | |
| exit 1 | |
| else | |
| echo "==== Found folder: $PACKAGE_NAME ====" | |
| fi | |
| echo "==== Creating manifest for package $PACKAGE_NAME ====" | |
| java -jar "$AGENT_JAR" -CreateManifestFile \ | |
| -PathToScriptsFolder "packages/$PACKAGE_NAME" \ | |
| -Operation "CreateOrUpdate" \ | |
| -PackageType "Regular" | |
| echo "==== Creating tar archive from $PACKAGE_NAME ====" | |
| cd "packages/$PACKAGE_NAME" | |
| tar -czf "../../${PACKAGE_NAME}.tar.gz" . | |
| cd ../.. | |
| echo "==== Create package $PACKAGE_NAME ====" | |
| java -jar "$AGENT_JAR" -Package \ | |
| -ProjectName "$PROJECT_NAME" \ | |
| -IgnoreScriptWarnings True \ | |
| -FilePath "${PACKAGE_NAME}.tar.gz" \ | |
| -Server "$DBMAESTRO_SERVER" \ | |
| -UseSSL "$DBMAESTRO_USE_SSL" \ | |
| -AuthType "$DBMAESTRO_AUTH_TYPE" \ | |
| -UserName "$DBMAESTRO_USER" \ | |
| -Password "$DBMAESTRO_PASSWORD" | |
| if [ $? -ne 0 ]; then | |
| echo "==== Failed to create package ====" | |
| exit 1 | |
| fi | |
| echo "==== Create package completed successfully ====" | |
| - name: Comment on PR - Package Created | |
| if: success() | |
| shell: bash | |
| run: | | |
| curl -X POST \ | |
| -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ | |
| -H "Accept: application/vnd.github.v3+json" \ | |
| -H "Content-Type: application/json" \ | |
| "https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments" \ | |
| -d "{\"body\":\":white_check_mark: **Package Created Successfully**\n\nPackage Name: **$PACKAGE_NAME**\n\nReady for precheck validation.\"}" | |
| - name: Comment on PR - Package Creation Failed | |
| if: failure() | |
| shell: bash | |
| run: | | |
| curl -X POST \ | |
| -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ | |
| -H "Accept: application/vnd.github.v3+json" \ | |
| -H "Content-Type: application/json" \ | |
| "https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments" \ | |
| -d "{\"body\":\":x: **Package Creation Failed**\n\nPackage Name: **$PACKAGE_NAME**\n\nPlease check the logs for details.\"}" | |
| precheck: | |
| name: Precheck Package | |
| runs-on: ubuntu-latest | |
| needs: [detect_changed_packages, create_package] | |
| if: needs.detect_changed_packages.outputs.has-packages == 'true' | |
| strategy: | |
| max-parallel: 1 | |
| matrix: | |
| item: ${{ fromJson(needs.detect_changed_packages.outputs.matrix) }} | |
| env: | |
| PACKAGE_NAME: ${{ matrix.item.package }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Precheck Package | |
| shell: bash | |
| run: | | |
| # ===== Precheck Package ===== | |
| echo "==== Pre-Checking package $PACKAGE_NAME... ====" | |
| java -jar "$AGENT_JAR" -PreCheck \ | |
| -ProjectName "$PROJECT_NAME" \ | |
| -PackageName "$PACKAGE_NAME" \ | |
| -Server "$DBMAESTRO_SERVER" \ | |
| -UseSSL "$DBMAESTRO_USE_SSL" \ | |
| -AuthType "$DBMAESTRO_AUTH_TYPE" \ | |
| -UserName "$DBMAESTRO_USER" \ | |
| -Password "$DBMAESTRO_PASSWORD" | |
| if [ $? -ne 0 ]; then | |
| echo "==== Precheck failed ====" | |
| exit 1 | |
| fi | |
| echo "==== Precheck completed successfully ====" | |
| - name: Comment on PR - Precheck Passed | |
| if: success() | |
| shell: bash | |
| run: | | |
| curl -X POST \ | |
| -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ | |
| -H "Accept: application/vnd.github.v3+json" \ | |
| -H "Content-Type: application/json" \ | |
| "https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments" \ | |
| -d "{\"body\":\":white_check_mark: **Precheck Validation Passed**\n\nPackage Name: **$PACKAGE_NAME**\n\nReady to merge and deploy to Release Source.\"}" | |
| - name: Comment on PR - Precheck Failed | |
| if: failure() | |
| shell: bash | |
| run: | | |
| curl -X POST \ | |
| -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ | |
| -H "Accept: application/vnd.github.v3+json" \ | |
| -H "Content-Type: application/json" \ | |
| "https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments" \ | |
| -d "{\"body\":\":x: **Precheck Validation Failed**\n\nPackage Name: **$PACKAGE_NAME**\n\nPlease review the validation errors in the logs.\"}" |