Skip to content

Commit

Permalink
Extract out base folder as a param
Browse files Browse the repository at this point in the history
  • Loading branch information
pflooky committed Jun 24, 2024
1 parent 16a16ed commit 3049f73
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 35 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ jobs:
id: test-action
uses: ./
with:
configuration-file: example/file.yaml
configuration_file: example/file.yaml
base_folder: ./data-caterer

- name: Print Output
id: output
Expand Down
12 changes: 8 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ author: 'Data Catering'

# Define your inputs here.
inputs:
configuration-file:
configuration_file:
description: 'File path to Data Caterer configuration file'
default: 'data-caterer.yaml'
insta-infra-folder:
insta_infra_folder:
description: 'Folder to insta-infra'
default: 'data-caterer-integration-test/insta-infra'
base_folder:
description: 'Folder to use for execution files'
default: '/tmp/data-caterer'

# Define your outputs here.
outputs:
Expand All @@ -32,5 +35,6 @@ runs:
const { script } = require("${{github.action_path}}/dist/index.js")
script()
env:
CONFIGURATION_FILE: ${{ inputs.configuration-file }}
INSTA_INFRA_FOLDER: ${{ inputs.insta-infra-folder }}
CONFIGURATION_FILE: ${{ inputs.configuration_file }}
INSTA_INFRA_FOLDER: ${{ inputs.insta_infra_folder }}
BASE_FOLDER: ${{ github.action_path }}
2 changes: 1 addition & 1 deletion badges/coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 36 additions & 14 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

40 changes: 29 additions & 11 deletions src/data-caterer.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ const {
createDataCatererDockerRunCommand
} = require('./config')

const baseFolder = '/tmp/data-caterer'
const configurationFolder = `${baseFolder}/conf`
const sharedFolder = `${baseFolder}/shared`
const dataCatererVersion = '0.11.1'

/**
Expand Down Expand Up @@ -240,7 +237,12 @@ function extractDataValidations(testConfig, appIndex, currValidations) {
}
}

function runDataCaterer(testConfig, appIndex) {
function runDataCaterer(
testConfig,
appIndex,
configurationFolder,
sharedFolder
) {
// Use template plan and task YAML files
// Also, template application.conf
const currentPlan = basePlan()
Expand Down Expand Up @@ -276,7 +278,7 @@ function runDataCaterer(testConfig, appIndex) {
execSync(dockerRunCommand)
}

function cleanAppDoneFiles(parsedConfig) {
function cleanAppDoneFiles(parsedConfig, sharedFolder) {
// Clean up 'app-*-done' files in shared directory
for (const [i] of parsedConfig.run.entries()) {
try {
Expand All @@ -287,8 +289,13 @@ function cleanAppDoneFiles(parsedConfig) {
}
}

function runTests(parsedConfig, configFileDirectory) {
function runTests(parsedConfig, configFileDirectory, baseFolder) {
let testResult = ''
const configurationFolder = `${baseFolder}/conf`
const sharedFolder = `${baseFolder}/shared`
fs.mkdirSync(configurationFolder, { recursive: true })
fs.mkdirSync(sharedFolder, { recursive: true })

if (parsedConfig.run) {
for (const [i, runConf] of parsedConfig.run.entries()) {
// Need to know whether to run application first or data generation
Expand All @@ -312,7 +319,12 @@ function runTests(parsedConfig, configFileDirectory) {
!runConf.generateFirst
) {
core.info('Running data caterer')
testResult = runDataCaterer(runConf.test, i)
testResult = runDataCaterer(
runConf.test,
i,
configurationFolder,
sharedFolder
)
core.info('Running application/job')
execSync(runConf.command, { cwd: configFileDirectory })
writeToFile(sharedFolder, `app-${i}-done`, 'done', true)
Expand All @@ -321,10 +333,15 @@ function runTests(parsedConfig, configFileDirectory) {
execSync(runConf.command, { cwd: configFileDirectory })
writeToFile(sharedFolder, `app-${i}-done`, 'done', true)
core.info('Running data caterer')
testResult = runDataCaterer(runConf.test, i)
testResult = runDataCaterer(
runConf.test,
i,
configurationFolder,
sharedFolder
)
}
}
cleanAppDoneFiles(parsedConfig)
cleanAppDoneFiles(parsedConfig, sharedFolder)
}
}

Expand All @@ -338,9 +355,10 @@ function runTests(parsedConfig, configFileDirectory) {
* - Return back summarised results
* @param configFile Base configuration file defining requirements for integration tests
* @param instaInfraFolder Folder where insta-infra is checked out
* @param baseFolder Folder where execution files get saved
* @returns {string} Results of data-caterer
*/
function runIntegrationTests(configFile, instaInfraFolder) {
function runIntegrationTests(configFile, instaInfraFolder, baseFolder) {
if (instaInfraFolder.includes(' ')) {
throw new Error(`Invalid insta-infra folder pathway=${instaInfraFolder}`)
}
Expand All @@ -364,7 +382,7 @@ function runIntegrationTests(configFile, instaInfraFolder) {
})
}

const testResults = runTests(parsedConfig, configFileDirectory)
const testResults = runTests(parsedConfig, configFileDirectory, baseFolder)
core.info('Finished tests!')
return testResults
}
Expand Down
10 changes: 7 additions & 3 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,19 @@ async function run() {
try {
const configFile = process.env.CONFIGURATION_FILE
? process.env.CONFIGURATION_FILE
: core.getInput('configuration-file', {})
: core.getInput('configuration_file', {})
const instaInfraFolder = process.env.INSTA_INFRA_FOLDER
? process.env.INSTA_INFRA_FOLDER
: core.getInput('insta-infra-folder', {})
: core.getInput('insta_infra_folder', {})
const baseFolder = process.env.BASE_FOLDER
? process.env.BASE_FOLDER
: core.getInput('base_folder', {})

// Debug logs are only output if the `ACTIONS_STEP_DEBUG` secret is true
core.debug(`Using config file: ${configFile}`)
core.debug(`Using insta-infra folder: ${instaInfraFolder}`)
const result = runIntegrationTests(configFile, instaInfraFolder)
core.debug(`Using base folder: ${baseFolder}`)
const result = runIntegrationTests(configFile, instaInfraFolder, baseFolder)

// Set outputs for other workflow steps to use
core.setOutput('results', result)
Expand Down

0 comments on commit 3049f73

Please sign in to comment.