Choose and Deploy π #448
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: Choose and Deploy π | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| workflow_choice: | |
| description: 'Select the workflow to run' | |
| required: true | |
| type: choice | |
| options: | |
| - Deploy | |
| - Snapshot Deploy | |
| cf_space: | |
| description: 'Specify the Cloud Foundry space to deploy to' | |
| required: true | |
| default: 'developcap' | |
| deploy_branch: | |
| description: 'Specify the branch to deploy from (only for Deploy workflow)' | |
| required: false | |
| repository_id: | |
| description: 'Specify the Repository ID (leave blank if deploying to developcap)' | |
| required: false | |
| cds_services_version: | |
| description: 'Optional override for <cds.services.version> (e.g. 4.3.1). Leave blank to use existing value.' | |
| required: false | |
| default: '' | |
| permissions: | |
| pull-requests: read | |
| packages: read # Added permission to read packages | |
| jobs: | |
| Deploy: | |
| runs-on: ubuntu-latest | |
| if: ${{ github.event.inputs.workflow_choice == 'Deploy' }} | |
| steps: | |
| - name: Checkout repository π | |
| uses: actions/checkout@v6 | |
| with: | |
| ref: ${{ github.event.inputs.deploy_branch }} | |
| - name: Set up Java 17 β | |
| uses: actions/setup-java@v3 | |
| with: | |
| java-version: 17 | |
| distribution: 'temurin' | |
| - name: Build and package π¨ | |
| run: | | |
| echo "π Building and packaging..." | |
| mvn clean install -P unit-tests -DskipIntegrationTests | |
| echo "β Build and packaging completed successfully!" | |
| - name: Verify and Checkout Deploy Branch π | |
| run: | | |
| git fetch origin | |
| echo "π Verifying 'local_deploy' branch..." | |
| if git rev-parse --verify origin/local_deploy; then | |
| git checkout local_deploy | |
| echo "β Branch checked out successfully!" | |
| else | |
| echo "β Branch 'local_deploy' not found. Please verify the branch name." | |
| exit 1 | |
| fi | |
| - name: Set REPOSITORY_ID π | |
| id: set_repository_id | |
| run: | | |
| echo "π Setting Repository ID..." | |
| if [ "${{ github.event.inputs.cf_space }}" = "developcap" ]; then | |
| echo "Using REPOSITORY_ID from secrets" | |
| echo "::set-output name=repository_id::${{ secrets.REPOSITORY_ID }}" | |
| else | |
| if [ -z "${{ github.event.inputs.repository_id }}" ]; then | |
| echo "β REPOSITORY_ID must be provided for non-developcap spaces" | |
| exit 1 | |
| else | |
| echo "Using provided REPOSITORY_ID" | |
| echo "::set-output name=repository_id::${{ github.event.inputs.repository_id }}" | |
| fi | |
| fi | |
| - name: Prepare and Deploy to Cloud Foundry βοΈ | |
| run: | | |
| echo "π Preparing to deploy..." | |
| echo "Current Branch: π" | |
| git branch | |
| pwd | |
| cd /home/runner/work/sdm/sdm/cap-notebook/demoapp/app | |
| echo "Changed to app directory π" | |
| pwd | |
| echo "π Installing npm dependencies..." | |
| npm i | |
| cd .. | |
| echo "Changed to demoapp directory π" | |
| pwd | |
| echo "π§ Configuring mta.yaml..." | |
| sed -i 's|__REPOSITORY_ID__|'${{ steps.set_repository_id.outputs.repository_id }}'|g' ./mta.yaml | |
| echo "π¦ Downloading and setting up MBT..." | |
| wget -P /tmp https://github.com/SAP/cloud-mta-build-tool/releases/download/v1.2.28/cloud-mta-build-tool_1.2.28_Linux_amd64.tar.gz | |
| tar -xvzf /tmp/cloud-mta-build-tool_1.2.28_Linux_amd64.tar.gz | |
| sudo mv mbt /usr/local/bin/ | |
| echo "π Building with MBT..." | |
| mbt build | |
| echo "β Build completed!" | |
| echo "π§ Installing Cloud Foundry CLI..." | |
| wget -q -O - https://packages.cloudfoundry.org/debian/cli.cloudfoundry.org.key | sudo tee /etc/apt/trusted.gpg.d/cloudfoundry.asc | |
| echo "deb https://packages.cloudfoundry.org/debian stable main" | sudo tee /etc/apt/sources.list.d/cloudfoundry-cli.list | |
| sudo apt update | |
| sudo apt install cf-cli | |
| cf install-plugin multiapps -f | |
| echo "π Logging into Cloud Foundry..." | |
| cf login -a ${{ secrets.CF_API }} -u ${{ secrets.CF_USER }} -p ${{ secrets.CF_PASSWORD }} -o ${{ secrets.CF_ORG }} -s ${{ github.event.inputs.cf_space }} | |
| echo "β Logged in successfully!" | |
| echo "π Running cf deploy..." | |
| cf deploy mta_archives/demoappjava_1.0.0.mtar -f | |
| echo "β Deployment complete!" | |
| SnapshotDeploy: | |
| runs-on: ubuntu-latest | |
| if: ${{ github.event.inputs.workflow_choice == 'Snapshot Deploy' }} | |
| steps: | |
| - name: Checkout repository π | |
| uses: actions/checkout@v6 | |
| with: | |
| ref: develop | |
| - name: Set up Java 17 β | |
| uses: actions/setup-java@v3 | |
| with: | |
| java-version: 17 | |
| distribution: 'temurin' | |
| - name: Verify and Checkout Deploy Branch π | |
| run: | | |
| git fetch origin | |
| echo "π Verifying 'develop_deploy' branch..." | |
| if git rev-parse --verify origin/develop_deploy; then | |
| git checkout develop_deploy | |
| echo "β Branch checked out successfully!" | |
| else | |
| echo "β Branch 'develop_deploy' not found. Please verify the branch name." | |
| exit 1 | |
| fi | |
| - name: Override cds.services.version (runtime only) | |
| if: ${{ github.event.inputs.cds_services_version != '' }} | |
| env: | |
| TARGET_CDS_SERVICES_VERSION: ${{ github.event.inputs.cds_services_version }} | |
| run: | | |
| echo "Override requested: cds.services.version -> ${TARGET_CDS_SERVICES_VERSION}" | |
| FILES=$(grep -Rl "<cds.services.version>" . | grep pom.xml || true) | |
| if [ -z "$FILES" ]; then | |
| echo "No pom.xml files with <cds.services.version> found" >&2; exit 1; | |
| fi | |
| echo "Updating files:"; echo "$FILES" | sed 's/^/ - /' | |
| for f in $FILES; do | |
| sed -i "s|<cds.services.version>[^<]*</cds.services.version>|<cds.services.version>${TARGET_CDS_SERVICES_VERSION}</cds.services.version>|" "$f" | |
| done | |
| echo "Post-update values:"; grep -R "<cds.services.version>" $FILES || true | |
| echo "(Not committing these changes)" | |
| shell: bash | |
| - name: Deleting the sdm directory for fresh build βοΈ | |
| run: | | |
| echo "π Deleting 'sdm' directory for fresh build..." | |
| pwd | |
| cd | |
| rm -rf .m2/repository/com/sap/cds | |
| echo "β 'sdm' directory deleted!" | |
| - name: Set REPOSITORY_ID π | |
| id: set_repository_id | |
| run: | | |
| echo "π Setting Repository ID..." | |
| if [ "${{ github.event.inputs.cf_space }}" = "developcap" ]; then | |
| echo "Using REPOSITORY_ID from secrets" | |
| echo "::set-output name=repository_id::${{ secrets.REPOSITORY_ID }}" | |
| else | |
| if [ -z "${{ github.event.inputs.repository_id }}" ]; then | |
| echo "β REPOSITORY_ID must be provided for non-developcap spaces" | |
| exit 1 | |
| else | |
| echo "Using provided REPOSITORY_ID" | |
| echo "::set-output name=repository_id::${{ github.event.inputs.repository_id }}" | |
| fi | |
| fi | |
| - name: Configure Maven for GitHub Packages π¦ | |
| run: | | |
| echo "π§ Configuring Maven for GitHub Packages..." | |
| mkdir -p ~/.m2 | |
| cat > ~/.m2/settings.xml <<EOF | |
| <settings> | |
| <servers> | |
| <server> | |
| <id>github-snapshot</id> | |
| <username>${{ github.actor }}</username> | |
| <password>${{ secrets.GITHUB_TOKEN }}</password> | |
| </server> | |
| </servers> | |
| </settings> | |
| EOF | |
| echo "β Maven configuration complete!" | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Prepare and Deploy to Cloud Foundry βοΈ | |
| run: | | |
| echo "π Preparing to deploy..." | |
| echo "Current Branch: π" | |
| git branch | |
| pwd | |
| cd /home/runner/work/sdm/sdm/cap-notebook/demoapp | |
| cd app | |
| echo "π Removing node_modules for fresh install..." | |
| rm -rf node_modules package-lock.json | |
| echo "π§ Installing npm dependencies..." | |
| npm i | |
| cd .. | |
| echo "π§ Configuring mta.yaml..." | |
| sed -i 's|__REPOSITORY_ID__|'${{ steps.set_repository_id.outputs.repository_id }}'|g' ./mta.yaml | |
| echo "π¦ Downloading and setting up MBT..." | |
| wget -P /tmp https://github.com/SAP/cloud-mta-build-tool/releases/download/v1.2.28/cloud-mta-build-tool_1.2.28_Linux_amd64.tar.gz | |
| tar -xvzf /tmp/cloud-mta-build-tool_1.2.28_Linux_amd64.tar.gz | |
| sudo mv mbt /usr/local/bin/ | |
| echo "π Building with MBT..." | |
| mbt build | |
| echo "β Build completed!" | |
| echo "π§ Installing Cloud Foundry CLI..." | |
| wget -q -O - https://packages.cloudfoundry.org/debian/cli.cloudfoundry.org.key | sudo tee /etc/apt/trusted.gpg.d/cloudfoundry.asc | |
| echo "deb https://packages.cloudfoundry.org/debian stable main" | sudo tee /etc/apt/sources.list.d/cloudfoundry-cli.list | |
| sudo apt update | |
| sudo apt install cf-cli | |
| cf install-plugin multiapps -f | |
| echo "π Logging into Cloud Foundry..." | |
| cf login -a ${{ secrets.CF_API }} -u ${{ secrets.CF_USER }} -p ${{ secrets.CF_PASSWORD }} -o ${{ secrets.CF_ORG }} -s ${{ github.event.inputs.cf_space }} | |
| echo "β Logged in successfully!" | |
| echo "π Running cf deploy..." | |
| cf deploy mta_archives/demoappjava_1.0.0.mtar -f | |
| echo "β Deployment complete!" |