-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
199 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,84 +5,82 @@ import { dirname, resolve } from 'node:path' | |
import { ROOT } from './_common.mjs' | ||
|
||
if (!process.env.keys) { | ||
throw new Error(`Keys not set`) | ||
throw new Error(`Keys not set`) | ||
} | ||
const enableNodeModules = process.env.ENABLE_NODE_MODULES === 'true' | ||
const enableMobileNodeModules = | ||
process.env.ENABLE_MOBILE_NODE_MODULES === 'true' | ||
process.env.ENABLE_MOBILE_NODE_MODULES === 'true' | ||
const enableGeneratedFiles = process.env.ENABLE_GENERATED_FILES === 'true' | ||
const enableCypress = process.env.ENABLE_CYPRESS === 'true' | ||
const cypressPath = process.env.CYPRESS_PATH | ||
const keys = JSON.parse(process.env.keys) | ||
console.log(keys) | ||
|
||
const YAML_FILE = process.env['YAML_FILE'] | ||
|
||
const steps = [ | ||
enableNodeModules | ||
? generateCacheAction( | ||
'Cache node_modules', | ||
'node-modules', | ||
'node_modules', | ||
keys['node_modules'], | ||
) | ||
: null, | ||
enableMobileNodeModules | ||
? generateCacheAction( | ||
'Cache Mobile node_modules', | ||
'mobile-node-modules', | ||
'apps/native/app/node_modules', | ||
keys['App node_modules'], | ||
) | ||
: null, | ||
enableGeneratedFiles | ||
? generateCacheAction( | ||
'Cache Generated Files', | ||
'generated-files', | ||
'generated_files.tar.gz', | ||
keys['Generated files'], | ||
) | ||
: null, | ||
enableCypress && cypressPath | ||
? generateCacheAction( | ||
'Cache Cypress', | ||
'cypress-cache', | ||
cypressPath, | ||
keys['Cypress Cache'], | ||
) | ||
: null, | ||
enableNodeModules | ||
? generateCacheAction( | ||
'Cache node_modules', | ||
'node-modules', | ||
'node_modules', | ||
keys['node_modules'], | ||
) | ||
: null, | ||
enableMobileNodeModules | ||
? generateCacheAction( | ||
'Cache Mobile node_modules', | ||
'mobile-node-modules', | ||
'apps/native/app/node_modules', | ||
keys['App node_modules'], | ||
) | ||
: null, | ||
enableGeneratedFiles | ||
? generateCacheAction( | ||
'Cache Generated Files', | ||
'generated-files', | ||
'generated_files.tar.gz', | ||
keys['Generated files'], | ||
) | ||
: null, | ||
enableCypress && cypressPath | ||
? generateCacheAction( | ||
'Cache Cypress', | ||
'cypress-cache', | ||
cypressPath, | ||
keys['Cypress Cache'], | ||
) | ||
: null, | ||
].filter((e) => e != null) | ||
|
||
const workflow = { | ||
...createHeader('Autogenerated cache workflow', 'Autogenerated'), | ||
...createOutputs(steps), | ||
...createRuns(steps), | ||
...createHeader('Autogenerated cache workflow', 'Autogenerated'), | ||
...createOutputs(steps), | ||
...createRuns(steps), | ||
} | ||
|
||
console.log(JSON.stringify(workflow, null, 2)) | ||
|
||
if (YAML_FILE) { | ||
await exportToYaml(workflow, YAML_FILE) | ||
await exportToYaml(workflow, YAML_FILE) | ||
} | ||
|
||
function createHeader(name, description) { | ||
return { | ||
name, | ||
description, | ||
} | ||
return { | ||
name, | ||
description, | ||
} | ||
} | ||
|
||
function createOutputs(steps) { | ||
return { | ||
outputs: steps.reduce((a, value) => { | ||
return { | ||
...a, | ||
[`${value.id}-success`]: { | ||
description: `Success for ${value.name}`, | ||
value: `\${{ steps.${value.id}.outputs.success }}`, | ||
}, | ||
} | ||
}, {}), | ||
} | ||
return { | ||
outputs: steps.reduce((a, value) => { | ||
return { | ||
...a, | ||
[`${value.id}-success`]: { | ||
description: `Success for ${value.name}`, | ||
value: `\${{ steps.${value.id}.outputs.success }}`, | ||
}, | ||
} | ||
}, {}), | ||
} | ||
} | ||
|
||
/** | ||
|
@@ -92,24 +90,24 @@ function createOutputs(steps) { | |
* @returns {Object} - The composite run object. | ||
*/ | ||
function createRuns(steps) { | ||
return { | ||
runs: { | ||
using: 'composite', | ||
steps: steps.map((_value) => { | ||
const { name, id, uses, with: withValue, value } = _value | ||
return { | ||
name, | ||
id, | ||
uses, | ||
...value, | ||
with: { | ||
path: withValue.path, | ||
key: withValue.key, | ||
}, | ||
} | ||
}), | ||
}, | ||
} | ||
return { | ||
runs: { | ||
using: 'composite', | ||
steps: steps.map((_value) => { | ||
const { name, id, uses, with: withValue, value } = _value | ||
return { | ||
name, | ||
id, | ||
uses, | ||
...value, | ||
with: { | ||
path: withValue.path, | ||
key: withValue.key, | ||
}, | ||
} | ||
}), | ||
}, | ||
} | ||
} | ||
|
||
/** | ||
|
@@ -122,16 +120,16 @@ function createRuns(steps) { | |
* @returns {object} - The cache action object. | ||
*/ | ||
function generateCacheAction(name, id, path, key) { | ||
return { | ||
name, | ||
id, | ||
uses: 'island-is/[email protected]', | ||
continue_on_error: true, | ||
with: { | ||
path, | ||
key, | ||
}, | ||
} | ||
return { | ||
name, | ||
id, | ||
uses: 'island-is/[email protected]', | ||
continue_on_error: true, | ||
with: { | ||
path, | ||
key, | ||
}, | ||
} | ||
} | ||
|
||
/** | ||
|
@@ -142,31 +140,31 @@ function generateCacheAction(name, id, path, key) { | |
* @returns {Promise<void>} - A promise that resolves when the export is complete. | ||
*/ | ||
async function exportToYaml( | ||
obj, | ||
_fileName, | ||
fileName = resolve(ROOT, _fileName), | ||
obj, | ||
_fileName, | ||
fileName = resolve(ROOT, _fileName), | ||
) { | ||
const YAML_FILE_ROOT = dirname(fileName) | ||
await mkdir(YAML_FILE_ROOT, { recursive: true }) | ||
return /** @type {Promise<void>} */ ( | ||
new Promise((resolve) => { | ||
const jsonString = JSON.stringify(obj) | ||
const cueProcess = spawn('cue', ['export', '-', '-o', fileName]) | ||
cueProcess.stdin.write(jsonString) | ||
cueProcess.on('message', (msg) => { | ||
console.log(msg) | ||
}) | ||
cueProcess.on('error', (msg) => { | ||
console.log(msg) | ||
}) | ||
cueProcess.on('close', (code) => { | ||
if (code !== 0) { | ||
console.error(`cue export failed with code ${code}`) | ||
process.exit(1) | ||
} | ||
resolve() | ||
}) | ||
cueProcess.stdin.end() | ||
}) | ||
) | ||
const YAML_FILE_ROOT = dirname(fileName) | ||
await mkdir(YAML_FILE_ROOT, { recursive: true }) | ||
return /** @type {Promise<void>} */ ( | ||
new Promise((resolve) => { | ||
const jsonString = JSON.stringify(obj) | ||
const cueProcess = spawn('cue', ['export', '-', '-o', fileName]) | ||
cueProcess.stdin.write(jsonString) | ||
cueProcess.on('message', (msg) => { | ||
console.log(msg) | ||
}) | ||
cueProcess.on('error', (msg) => { | ||
console.log(msg) | ||
}) | ||
cueProcess.on('close', (code) => { | ||
if (code !== 0) { | ||
console.error(`cue export failed with code ${code}`) | ||
process.exit(1) | ||
} | ||
resolve() | ||
}) | ||
cueProcess.stdin.end() | ||
}) | ||
) | ||
} |
Oops, something went wrong.