Skip to content

Commit

Permalink
fix: test
Browse files Browse the repository at this point in the history
  • Loading branch information
lodmfjord committed May 31, 2024
1 parent 75dab03 commit 9fd0833
Show file tree
Hide file tree
Showing 4 changed files with 199 additions and 203 deletions.
6 changes: 3 additions & 3 deletions .github/actions/get-cache/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ description: 'Action to get cache'
inputs:
enable-node-modules:
description: 'Get node modules cache'
default: 'true'
default: 'false'
enable-mobile-node-modules:
description: 'Get mobile node modules'
default: 'false'
enable-generated-files:
description: 'Get generated files'
default: 'true'
default: 'false'
enable-cypress:
description: 'Get cypress'
default: 'true'
default: 'false'
keys:
description: 'Keys'
default: 'false'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Test test
- name: Get cache
uses: ./.github/actions/get-cache
218 changes: 108 additions & 110 deletions scripts/ci/generate-cache-steps.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}`,
},
}
}, {}),
}
}

/**
Expand All @@ -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,
},
}
}),
},
}
}

/**
Expand All @@ -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,
},
}
}

/**
Expand All @@ -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()
})
)
}
Loading

0 comments on commit 9fd0833

Please sign in to comment.