Skip to content
48 changes: 48 additions & 0 deletions .github/actions/cf-github-deploy/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: GitHub Deployment for Cloud Foundry
description: "Creates a GitHub deployment for your Cloud Foundry app"

inputs:
app-name:
description: "Base name of the deployed CAP app"
required: true

runs:
using: "composite"
steps:
- name: Get deployed server URL
id: get-url
shell: bash
run: |
raw=$(cf app "${{ inputs.app-name }}" | awk '/routes:/ {print $2}')
raw=$(echo "$raw" | sed -E 's#^https?://##')
echo "url=https://$raw" >> "$GITHUB_OUTPUT"

- name: Create GitHub Deployment
uses: actions/github-script@v7
env:
URL: ${{ steps.get-url.outputs.url }}
with:
script: |
const { owner, repo } = context.repo
const ref = context.ref
const url = process.env.URL

const deployment = await github.rest.repos.createDeployment({
owner,
repo,
ref,
required_contexts: [],
environment: 'Staging',
auto_merge: false,
description: 'Deployed to Cloud Foundry',
})

await github.rest.repos.createDeploymentStatus({
owner,
repo,
deployment_id: deployment.data.id,
state: 'success',
environment_url: url,
log_url: `https://github.com/${owner}/${repo}/actions/runs/${context.runId}`,
description: 'CAP app is live',
})
53 changes: 53 additions & 0 deletions .github/actions/cf-setup/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Cloud Foundry Setup
description: "Installs dependencies for Cloud Foundry deployment"

inputs:
cf-version:
description: "The version of the Cloud Foundry CLI to install"
required: false
default: "8.8.3"
cf-api:
description: "The Cloud Foundry API endpoint to connect to"
required: true
cf-org:
description: "The Cloud Foundry organization to target"
required: true
cf-space:
description: "The Cloud Foundry space to target"
required: true
cf-username:
description: "The Cloud Foundry username to authenticate with"
required: true
cf-password:
description: "The Cloud Foundry password to authenticate with"
required: true

runs:
using: composite
steps:
- shell: bash
run: |
set -e
echo "Using CF_VERSION=${{ inputs.cf-version }}"
echo "Using CF_API=${{ inputs.cf-api }}"
curl -L "https://packages.cloudfoundry.org/stable?release=linux64-binary&version=${{ inputs.cf-version }}&source=github" -o cf-cli.tgz
mkdir cf-cli && tar -xzf cf-cli.tgz -C cf-cli
chmod +x cf-cli/cf
echo "${PWD}/cf-cli" >> $GITHUB_PATH

- shell: bash
run: |
echo "Installing MBT..."
npm install -g mbt

- shell: bash
run: |
echo "Installing CF CLI multiapps plugin..."
cf install-plugin multiapps -f

- shell: bash
run: |
echo "Authenticating to Cloud Foundry..."
cf api "${{ inputs.cf-api }}"
cf auth "${{ inputs.cf-username }}" "${{ inputs.cf-password }}"
cf target -o "${{ inputs.cf-org }}" -s "${{ inputs.cf-space }}"
46 changes: 46 additions & 0 deletions .github/workflows/cf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Cloud Foundry

on:
workflow_call:
workflow_dispatch:
merge_group:
push:
branches:
- main

concurrency:
group: cf-${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

env:
APP_NAME: samples
FORCE_COLOR: true
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
- uses: actions/setup-node@v4
with:
node-version: 22
- uses: ./.github/actions/cf-setup
with:
cf-api: ${{ vars.CF_API }}
cf-org: ${{ vars.CF_ORG }}
cf-space: ${{ vars.CF_SPACE }}
cf-username: ${{ vars.CF_USERNAME }}
cf-password: ${{ secrets.CF_PASSWORD }}
- run: npm clean-install
- run: npx cds up

- uses: ./.github/actions/cf-github-deploy
with:
app-name: ${{ env.APP_NAME }}

- run: cf logs ${{ env.APP_NAME }} --recent
- run: cf logs orders-srv --recent
- run: cf logs reviews-srv --recent
- run: cf logs bookstore-srv --recent
- run: cf logs ${{ env.APP_NAME }}-db-deployer --recent
Loading