Skip to content

Choose and Deploy 🚀 #496

Choose and Deploy 🚀

Choose and Deploy 🚀 #496

Workflow file for this run

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:
contents: read
pull-requests: read
packages: read # Added permission to read packages
jobs:
Deploy:
environment: dev
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 21 ☕
uses: actions/setup-java@v3
with:
java-version: 21
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: 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/app/single-tenant/personal-space/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 cf8-cli
cf install-plugin multiapps -f
echo "🔑 Logging into Cloud Foundry..."
set +x
echo "::add-mask::$CF_API"
echo "::add-mask::$CF_USER"
echo "::add-mask::$CF_PASSWORD"
echo "::add-mask::$CF_ORG"
cf login -a "$CF_API" -u "$CF_USER" -p "$CF_PASSWORD" -o "$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!"
env:
CF_API: ${{ secrets.CF_API }}
CF_USER: ${{ secrets.CF_USER }}
CF_PASSWORD: ${{ secrets.CF_PASSWORD }}
CF_ORG: ${{ secrets.CF_ORG }}
SnapshotDeploy:
environment: dev
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 21 ☕
uses: actions/setup-java@v3
with:
java-version: 21
distribution: 'temurin'
- 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>" app/single-tenant/central-space/demoapp | 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/app/single-tenant/central-space/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 cf8-cli
cf install-plugin multiapps -f
echo "🔑 Logging into Cloud Foundry..."
set +x
echo "::add-mask::$CF_API"
echo "::add-mask::$CF_USER"
echo "::add-mask::$CF_PASSWORD"
echo "::add-mask::$CF_ORG"
cf login -a "$CF_API" -u "$CF_USER" -p "$CF_PASSWORD" -o "$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!"
env:
CF_API: ${{ secrets.CF_API }}
CF_USER: ${{ secrets.CF_USER }}
CF_PASSWORD: ${{ secrets.CF_PASSWORD }}
CF_ORG: ${{ secrets.CF_ORG }}