Skip to content

Commit

Permalink
style: fix js lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ttshivers committed Nov 14, 2020
1 parent 2ec7944 commit 00f7976
Showing 1 changed file with 31 additions and 31 deletions.
62 changes: 31 additions & 31 deletions genMatrix.js
Original file line number Diff line number Diff line change
@@ -1,80 +1,80 @@
'use strict';
const path = require('path');
const fs = require('fs');
'use strict'
const path = require('path')
const fs = require('fs')

const testFiles = [
'genMatrix.js',
'.github/workflows/build-test.yml',
];
'.github/workflows/build-test.yml'
]

const nodeDirRegex = /^\d+$/;
const nodeDirRegex = /^\d+$/

const areTestFilesChanged = (changedFiles) => changedFiles
.some((file) => testFiles.includes(file));
.some((file) => testFiles.includes(file))

// Returns a list of the child directories in the given path
const getChildDirectories = (parent) => fs.readdirSync(parent, { withFileTypes: true })
.filter((dirent) => dirent.isDirectory())
.map(({ name }) => path.resolve(parent, name));
.map(({ name }) => path.resolve(parent, name))

const getNodeVerionDirs = (base) => getChildDirectories(base)
.filter((childPath) => nodeDirRegex.test(path.basename(childPath)));
.filter((childPath) => nodeDirRegex.test(path.basename(childPath)))

// Returns the paths of Dockerfiles that are at: base/*/Dockerfile
const getDockerfilesInChildDirs = (base) => getChildDirectories(base)
.map((childDir) => path.resolve(childDir, 'Dockerfile'));
.map((childDir) => path.resolve(childDir, 'Dockerfile'))

const getAllDockerfiles = (base) => getNodeVerionDirs(base).flatMap(getDockerfilesInChildDirs);
const getAllDockerfiles = (base) => getNodeVerionDirs(base).flatMap(getDockerfilesInChildDirs)

const getAffectedDockerfiles = (filesAdded, filesModified, filesRenamed) => {
const files = [
...filesAdded,
...filesModified,
...filesRenamed,
];
...filesRenamed
]

// If the test files were changed, include everything
if (areTestFilesChanged(files)) {
console.log('Test files changed so scheduling all Dockerfiles');
return getAllDockerfiles(__dirname);
console.log('Test files changed so scheduling all Dockerfiles')
return getAllDockerfiles(__dirname)
}

const modifiedDockerfiles = files.filter((file) => file.endsWith('/Dockerfile'));
const modifiedDockerfiles = files.filter((file) => file.endsWith('/Dockerfile'))

// Get Dockerfiles affected by modified docker-entrypoint.sh files
const entrypointAffectedDockerfiles = files
.filter((file) => file.endsWith('/docker-entrypoint.sh'))
.map((file) => path.resolve(path.dirname(file), 'Dockerfile'));
.map((file) => path.resolve(path.dirname(file), 'Dockerfile'))

return [
...modifiedDockerfiles,
...entrypointAffectedDockerfiles,
];
};
...entrypointAffectedDockerfiles
]
}

const getFullNodeVersionFromDockerfile = (file) => fs.readFileSync(file, 'utf8')
.match(/^ENV NODE_VERSION (\d*\.*\d*\.\d*)/m)[1];
.match(/^ENV NODE_VERSION (\d*\.*\d*\.\d*)/m)[1]

const getDockerfileMatrixEntry = (file) => {
const [variant] = path.dirname(file).split(path.sep).slice(-1);
const [variant] = path.dirname(file).split(path.sep).slice(-1)

const version = getFullNodeVersionFromDockerfile(file);
const version = getFullNodeVersionFromDockerfile(file)

return {
version,
variant,
};
};
variant
}
}

const generateBuildMatrix = (filesAdded, filesModified, filesRenamed) => {
const dockerfiles = [...new Set(getAffectedDockerfiles(filesAdded, filesModified, filesRenamed))];
const dockerfiles = [...new Set(getAffectedDockerfiles(filesAdded, filesModified, filesRenamed))]

const entries = dockerfiles.map(getDockerfileMatrixEntry);
const entries = dockerfiles.map(getDockerfileMatrixEntry)

// Return null if there are no entries so we can skip the matrix step
return entries.length
? { include: entries }
: null;
};
: null
}

module.exports = generateBuildMatrix;
module.exports = generateBuildMatrix

0 comments on commit 00f7976

Please sign in to comment.