Skip to content

Commit 088d543

Browse files
committed
Test Deploy
1 parent 489d976 commit 088d543

File tree

7 files changed

+151
-9
lines changed

7 files changed

+151
-9
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: "cf-setup"
2+
3+
description: "Installs CF CLI."
4+
5+
inputs:
6+
cf-version:
7+
description: "Full CF CLI version, e.g. 8"
8+
required: false
9+
default: "8"
10+
11+
api:
12+
description: "CF api"
13+
required: false
14+
default: https://api.cf.eu12.hana.ondemand.com
15+
16+
org:
17+
description: "CF org"
18+
required: true
19+
20+
space:
21+
description: "CF space"
22+
required: true
23+
24+
runs:
25+
using: node20
26+
main: ./setup.js

.github/actions/cf-setup/setup.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
"use strict";
2+
3+
const core = require("@actions/core");
4+
const exec = require("@actions/exec");
5+
const tc = require("@actions/tool-cache");
6+
7+
/*
8+
remember to run 'npm run package:cf' after changing this file to recreate the packed version 'index.js'
9+
*/
10+
const SUPPORTED_VERSIONS = ["7", "8"];
11+
12+
async function main() {
13+
try {
14+
// get input
15+
const api = core.getInput("api");
16+
const org = core.getInput("org", { required: true });
17+
const space = core.getInput("space", { required: true });
18+
const version = core.getInput("cf-version");
19+
20+
if (!SUPPORTED_VERSIONS.includes(version)) {
21+
throw new Error(`CF CLI version ${version} not supported. Use one of ${SUPPORTED_VERSIONS}`);
22+
}
23+
24+
let cachedPath = tc.find("cf-cli", version);
25+
if (cachedPath) {
26+
core.info(`Found CF CLI version ${version} in tool cache`);
27+
} else {
28+
core.startGroup("Downloading CF CLI package...");
29+
30+
const downloadUrl = `https://packages.cloudfoundry.org/stable?release=linux64-binary&version=v${version}&source=github`;
31+
core.info(`Getting ${version} from ${downloadUrl}`);
32+
const downloadPath = await tc.downloadTool(downloadUrl);
33+
core.info(`CF CLI version ${version} was downloaded`);
34+
35+
core.info("Extracting CF CLI package...");
36+
const cfToolExtractedPath = await tc.extractTar(downloadPath);
37+
38+
core.info("Adding to cache...");
39+
cachedPath = await tc.cacheDir(cfToolExtractedPath, "cf-cli", version);
40+
41+
core.endGroup();
42+
}
43+
44+
core.info(`Installing CF CLI in ${cachedPath}`);
45+
core.addPath(cachedPath);
46+
47+
await exec.exec("cf", ["install-plugin", "multiapps", "-f"]);
48+
await exec.exec("cf", ["-v"]);
49+
await exec.exec("cf", ["api", api]);
50+
await exec.exec("cf", ["auth"]);
51+
await exec.exec("cf", ["target", "-o", org, "-s", space]);
52+
53+
core.info(`Done`);
54+
} catch (error) {
55+
core.setFailed(error.message);
56+
}
57+
}
58+
59+
(async () => await main())();

.github/workflows/deploy.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# This workflow will set up a test project based on SDK and deploy to Cloud Foundry
2+
name: Test Deploy
3+
on: workflow_dispatch
4+
env:
5+
NODE_OPTIONS: --use-openssl-ca
6+
jobs:
7+
default:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v4
11+
- uses: actions/setup-node@v4
12+
with:
13+
node-version: 22
14+
cache: npm
15+
- run: npm ci
16+
- name: Setup CDS project
17+
run: cds init afcsdk && cd afcsdk && npm i
18+
- name: Install SDK
19+
run: npm i github:cap-js-community/sap-afc-sdk
20+
- name: Boostrap SDK
21+
run: afc init cf
22+
- name: Add SDK features
23+
run: afc add broker,sample,http
24+
env:
25+
BROKER_PASSWORD_HASH: ${{ secrets.BROKER_PASSWORD_HASH }}
26+
BROKER_SERVICE_ID: ${{ secrets.BROKER_SERVICE_ID }}
27+
BROKER_SERVICE_PLAN_ID: ${{ secrets.BROKER_SERVICE_PLAN_ID }}
28+
- name: Install CF actions
29+
run: npm i @actions/core && npm i @actions/exec && npm i @actions/tool-cache
30+
- name: CF setup
31+
uses: ./.github/actions/cf-setup
32+
env:
33+
CF_USERNAME: ${{ secrets.CF_USERNAME }}
34+
CF_PASSWORD: ${{ secrets.CF_PASSWORD }}
35+
with:
36+
api: ${{ secrets.CF_API }}
37+
org: ${{ secrets.CF_ORG }}
38+
space: ${{ secrets.CF_SPACE }}
39+
- name: Install MBT
40+
run: npm i mbt
41+
- name: Build MTA
42+
run: mbt build
43+
- name: CF deploy
44+
run: cf deploy ./afcsdk/mta_archives/afcsdk_1.0.0.mtar

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@ CAP application.
207207
- Terminal: `cds init <name>`
208208
- Switch to project folder:
209209
- Terminal: `cd <name>`
210+
- Install
211+
- Terminal: `npm install`
210212

211213
### Features
212214

@@ -219,7 +221,6 @@ CAP application.
219221
- Terminal: `afc init kyma`
220222
- Add AFC SDK features
221223
- Terminal: `afc add broker,sample,http`
222-
- Install: `npm install`
223224
- Test
224225
- Terminal: `npm start`
225226
- Browser: `http://localhost:4004`

bin/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"sqlite",
99
"hana",
1010
"xsuaa",
11-
"application-logs",
11+
"application-logging",
1212
"approuter",
1313
"connectivity",
1414
"destination",

bin/features/broker.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,26 @@ function generateHashBrokerPassword() {
8888
}
8989

9090
module.exports = () => {
91-
let brokerPassword = {};
92-
if (!fileExists(CATALOG_PATH)) {
93-
brokerPassword = generateHashBrokerPassword();
94-
BROKER.SBF_BROKER_CREDENTIALS_HASH["broker-user"] = brokerPassword.hash;
91+
// catalog
92+
if (process.env.BROKER_SERVICE_ID) {
93+
CATALOG.services[0].id = process.env.BROKER_SERVICE_ID;
94+
}
95+
if (process.env.BROKER_SERVICE_PLAN_ID) {
96+
CATALOG.services[0].plans[0].id = process.env.BROKER_SERVICE_PLAN_ID;
9597
}
96-
const brokerWritten = writeFile(BROKER_PATH, BROKER);
9798
writeFile(CATALOG_PATH, CATALOG);
98-
if (brokerWritten) {
99+
100+
// broker
101+
let brokerPassword = {};
102+
if (!fileExists(BROKER_PATH)) {
103+
if (process.env.BROKER_PASSWORD_HASH) {
104+
BROKER.SBF_BROKER_CREDENTIALS_HASH["broker-user"] = process.env.BROKER_PASSWORD_HASH;
105+
} else {
106+
brokerPassword = generateHashBrokerPassword();
107+
BROKER.SBF_BROKER_CREDENTIALS_HASH["broker-user"] = brokerPassword.hash;
108+
}
109+
}
110+
if (writeFile(BROKER_PATH, BROKER) && brokerPassword.clear) {
99111
console.log("Broker Password (keep it safe to create broker):", brokerPassword.clear);
100112
console.log(`\nAfter deployment fetch API key: afc api key -p '${brokerPassword.clear}`);
101113
}

eslint.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const configPrettier = require("eslint-config-prettier");
1111
// https://eslint.org/docs/rules/
1212
module.exports = [
1313
{
14-
ignores: ["**/node_modules/", "**/temp/", "**/reports/"],
14+
ignores: [".github", "**/node_modules/", "**/temp/", "**/reports/"],
1515
},
1616
js.configs.recommended,
1717
nodePlugin.configs["flat/recommended-script"],

0 commit comments

Comments
 (0)