@sap/cds-dk
Version:
Command line client and development toolkit for the SAP Cloud Application Programming Model
79 lines (69 loc) • 2.58 kB
JavaScript
const path = require('node:path')
const { execSync } = require('node:child_process')
const { readProject } = require('../../projectReader')
const { renderAndCopy } = require('../../template')
const cds = require('../../../cds')
const { exists, copy } = cds.utils
module.exports = class GitHubActionTemplate extends require('../../plugin') {
static hasInProduction() {
return exists('.github/workflows/test.yaml')
}
options() {
return {
'sap': {
type: 'boolean'
}
}
}
static help() {
return 'CI/CD pipeline via GitHub Actions'
}
async run() {
const { hasMta, hasKyma, isJava } = readProject()
const test = `.github/workflows/test.yaml`
const { force, sap } = cds.cli.options
if (!exists(test) || force) {
await renderAndCopy(path.join(__dirname, 'files/workflows/test.yaml.hbs'), test, { sap, isJava })
} else {
console.log('> skipping ' + test)
}
const release = `.github/workflows/release.yaml`
if (!exists(release) || cds.cli.options.force) {
let githubSlug
try {
githubSlug = execSync('git remote get-url origin', { stdio: 'pipe' }).toString().split('/').slice(-2).join('/').trim().replace(/\.git$/, '')
} catch {
githubSlug = '<org/repo>'
// console.log(`\ncould not determine GitHub URL for the project – replace '<org/repo>' in ${release}`, DEBUG ? error : '')
}
await renderAndCopy(path.join(__dirname, 'files/workflows/release.yaml.hbs'), release, { isJava, sap: cds.cli.options.sap, githubSlug, hasMta, hasKyma })
} else {
console.log('> skipping ' + release)
}
}
async combine() {
const project = readProject()
const { addMta, addKyma } = project, { force } = cds.cli.options
project.sap = cds.cli.options.sap
if (addMta) {
const cf = '.github/workflows/cf.yaml'
if (force || !exists(cf)) {
await renderAndCopy(path.join(__dirname, 'files/workflows/cf.yaml.hbs'), cf, project)
}
}
if (addKyma) {
const kyma = '.github/workflows/kyma.yaml'
if (force || !exists(kyma)) {
await renderAndCopy(path.join(__dirname, 'files/workflows/kyma.yaml.hbs'), kyma, project)
}
const kymaSetup = '.github/actions/kyma-setup'
if (force || !exists(kymaSetup)) {
await copy(path.join(__dirname, 'files/kyma-setup'), kymaSetup)
}
const kymaInfo = '.github/actions/kyma-info'
if (force || !exists(kymaInfo)) {
await copy(path.join(__dirname, 'files/kyma-info'), kymaInfo)
}
}
}
}