Skip to content

Commit

Permalink
Merge pull request #62 from cap-js/test-pipeline-setup
Browse files Browse the repository at this point in the history
Test pipeline setup
  • Loading branch information
DanSchlachter authored Jul 4, 2024
2 parents 0454dd6 + db36d84 commit e863e5b
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 5 deletions.
83 changes: 83 additions & 0 deletions .github/workflows/checkout
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/usr/bin/env node
/* eslint-disable no-console */

const [,,$1] = process.argv
const { exec } = require('child_process')
const path = require('path')
const { readFile, writeFile } = require("fs").promises;
const { join } = require("path");

async function remoteService () {
const TARGET_DIR = "xmpls/remote-service"
const levelUP = "../../"
const INCLUDES = ["srv", "test"]
const paths = INCLUDES.map(pattern => join(__dirname, levelUP, TARGET_DIR, pattern))
const cmd = `cp -r ${paths.join(' ')} ${levelUP}`
await run(cmd);

const packageJson = JSON.parse(await readFile(join(__dirname, levelUP ,"package.json"), "utf-8"));
const delta = JSON.parse(await readFile(join(__dirname, levelUP, TARGET_DIR, "package.json"), "utf-8"));
packageJson.cds.requires["API_BUSINESS_PARTNER"] = delta.cds.requires["API_BUSINESS_PARTNER"]
await writeFile(join(__dirname, levelUP, "package.json"), JSON.stringify(packageJson, null, 2), "utf-8");

// dependencies
const deps = [
"@sap-cloud-sdk/connectivity",
"@sap-cloud-sdk/http-client",
"@sap-cloud-sdk/resilience",
"@sap-cloud-sdk/util"
]
console.info("Preparing Incidents-app with Remote Service")
return await run(`npm add ${deps.join(" ")}`)
}

async function messaging () {
const TARGET_DIR = "xmpls/messaging"
const levelUP = "../../"
const INCLUDES = ["app", "srv", "test"]
const paths = INCLUDES.map(pattern => join(__dirname, levelUP, TARGET_DIR, pattern))
const cmd = `cp -r ${paths.join(' ')} ${levelUP}`
await run(cmd);

const packageJson = JSON.parse(await readFile(join(__dirname, levelUP, "package.json"), "utf-8"));
const delta = JSON.parse(await readFile(join(__dirname, levelUP, TARGET_DIR, "package.json"), "utf-8"));
packageJson.cds.requires["API_BUSINESS_PARTNER"] = delta.cds.requires["API_BUSINESS_PARTNER"]
packageJson.cds.requires["messaging"] = delta.cds.requires["messaging"]
await writeFile(join(__dirname, levelUP, "package.json"), JSON.stringify(packageJson, null, 2), "utf-8");

// dependencies
const deps = [
"@sap-cloud-sdk/connectivity",
"@sap-cloud-sdk/http-client",
"@sap-cloud-sdk/resilience",
"@sap-cloud-sdk/util",
"@sap/xb-msg-amqp-v100"
]
console.info("Preparing Incidents-app with Messaging")
return await run(`npm add ${deps.join(" ")}`)
}

function run (cmd, silent) {
if (cmd.raw) return run (String.raw(...arguments))
if (cmd.endsWith('--silent')) silent = cmd = cmd.slice(0,-9)
if (typeof cmd === 'string') cmd = new Promise ((done,failed) => {
const cp = exec (cmd, (e,stdout) => e ? failed(e) : done(stdout))
if (!silent) {
cp.stdout.on ('data', d => process.stdout.write(d))
cp.stderr.on ('data', d => process.stderr.write(d))
}
})
return cmd
}

switch ($1) {

case 'remote-service':
remoteService();
break;
case 'messaging':
messaging();
break;
default:
console.log('Usage: ./checkout <command>');
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
"add-attachments": "npm add @cap-js/attachments && cp -r xmpls/attachments.cds ./db",
"add-notifications": "npm add @cap-js/notifications && cp xmpls/alert-notifications.js ./srv && cp xmpls/notification-types.json ./srv",
"add-audit-log": "npm add @cap-js/audit-logging && cp xmpls/data-privacy.cds ./srv && cp xmpls/audit-log.test.js ./test",
"add-remote-service": "cp -r xmpls/remote-service/* .",
"add-messaging": "cp -r xmpls/messaging/* .",
"add-remote-service": "./.github/workflows/checkout remote-service",
"add-messaging": "./.github/workflows/checkout messaging",
"add-all-xmpls": "npm run add-remote-service && npm run add-messaging && npm run add-change-tracking && npm run add-audit-log",
"reset": "read -p 'This will irreversibly reset your working directory including ALL files in this git repo. Continue?' -n 1 -r && echo && if [[ $REPLY =~ ^[Yy]$ ]]; then git clean -fd && git reset --hard && npm i; fi"
},
Expand Down
1 change: 1 addition & 0 deletions xmpls/messaging/app/fields.cds
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
using from './incidents/field';
3 changes: 0 additions & 3 deletions xmpls/messaging/app/services.cds

This file was deleted.

0 comments on commit e863e5b

Please sign in to comment.