Skip to content

Choose and Deploy πŸš€ #448

Choose and Deploy πŸš€

Choose and Deploy πŸš€ #448

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:
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!"