|
1 |
| -'use strict'; |
2 |
| -const path = require('path'); |
3 |
| -const fs = require('fs'); |
| 1 | +'use strict' |
| 2 | +const path = require('path') |
| 3 | +const fs = require('fs') |
4 | 4 |
|
5 | 5 | const testFiles = [
|
6 | 6 | 'genMatrix.js',
|
7 |
| - '.github/workflows/build-test.yml', |
8 |
| -]; |
| 7 | + '.github/workflows/build-test.yml' |
| 8 | +] |
9 | 9 |
|
10 |
| -const nodeDirRegex = /^\d+$/; |
| 10 | +const nodeDirRegex = /^\d+$/ |
11 | 11 |
|
12 | 12 | const areTestFilesChanged = (changedFiles) => changedFiles
|
13 |
| - .some((file) => testFiles.includes(file)); |
| 13 | + .some((file) => testFiles.includes(file)) |
14 | 14 |
|
15 | 15 | // Returns a list of the child directories in the given path
|
16 | 16 | const getChildDirectories = (parent) => fs.readdirSync(parent, { withFileTypes: true })
|
17 | 17 | .filter((dirent) => dirent.isDirectory())
|
18 |
| - .map(({ name }) => path.resolve(parent, name)); |
| 18 | + .map(({ name }) => path.resolve(parent, name)) |
19 | 19 |
|
20 | 20 | const getNodeVerionDirs = (base) => getChildDirectories(base)
|
21 |
| - .filter((childPath) => nodeDirRegex.test(path.basename(childPath))); |
| 21 | + .filter((childPath) => nodeDirRegex.test(path.basename(childPath))) |
22 | 22 |
|
23 | 23 | // Returns the paths of Dockerfiles that are at: base/*/Dockerfile
|
24 | 24 | const getDockerfilesInChildDirs = (base) => getChildDirectories(base)
|
25 |
| - .map((childDir) => path.resolve(childDir, 'Dockerfile')); |
| 25 | + .map((childDir) => path.resolve(childDir, 'Dockerfile')) |
26 | 26 |
|
27 |
| -const getAllDockerfiles = (base) => getNodeVerionDirs(base).flatMap(getDockerfilesInChildDirs); |
| 27 | +const getAllDockerfiles = (base) => getNodeVerionDirs(base).flatMap(getDockerfilesInChildDirs) |
28 | 28 |
|
29 | 29 | const getAffectedDockerfiles = (filesAdded, filesModified, filesRenamed) => {
|
30 | 30 | const files = [
|
31 | 31 | ...filesAdded,
|
32 | 32 | ...filesModified,
|
33 |
| - ...filesRenamed, |
34 |
| - ]; |
| 33 | + ...filesRenamed |
| 34 | + ] |
35 | 35 |
|
36 | 36 | // If the test files were changed, include everything
|
37 | 37 | if (areTestFilesChanged(files)) {
|
38 |
| - console.log('Test files changed so scheduling all Dockerfiles'); |
39 |
| - return getAllDockerfiles(__dirname); |
| 38 | + console.log('Test files changed so scheduling all Dockerfiles') |
| 39 | + return getAllDockerfiles(__dirname) |
40 | 40 | }
|
41 | 41 |
|
42 |
| - const modifiedDockerfiles = files.filter((file) => file.endsWith('/Dockerfile')); |
| 42 | + const modifiedDockerfiles = files.filter((file) => file.endsWith('/Dockerfile')) |
43 | 43 |
|
44 | 44 | // Get Dockerfiles affected by modified docker-entrypoint.sh files
|
45 | 45 | const entrypointAffectedDockerfiles = files
|
46 | 46 | .filter((file) => file.endsWith('/docker-entrypoint.sh'))
|
47 |
| - .map((file) => path.resolve(path.dirname(file), 'Dockerfile')); |
| 47 | + .map((file) => path.resolve(path.dirname(file), 'Dockerfile')) |
48 | 48 |
|
49 | 49 | return [
|
50 | 50 | ...modifiedDockerfiles,
|
51 |
| - ...entrypointAffectedDockerfiles, |
52 |
| - ]; |
53 |
| -}; |
| 51 | + ...entrypointAffectedDockerfiles |
| 52 | + ] |
| 53 | +} |
54 | 54 |
|
55 | 55 | const getFullNodeVersionFromDockerfile = (file) => fs.readFileSync(file, 'utf8')
|
56 |
| - .match(/^ENV NODE_VERSION (\d*\.*\d*\.\d*)/m)[1]; |
| 56 | + .match(/^ENV NODE_VERSION (\d*\.*\d*\.\d*)/m)[1] |
57 | 57 |
|
58 | 58 | const getDockerfileMatrixEntry = (file) => {
|
59 |
| - const [variant] = path.dirname(file).split(path.sep).slice(-1); |
| 59 | + const [variant] = path.dirname(file).split(path.sep).slice(-1) |
60 | 60 |
|
61 |
| - const version = getFullNodeVersionFromDockerfile(file); |
| 61 | + const version = getFullNodeVersionFromDockerfile(file) |
62 | 62 |
|
63 | 63 | return {
|
64 | 64 | version,
|
65 |
| - variant, |
66 |
| - }; |
67 |
| -}; |
| 65 | + variant |
| 66 | + } |
| 67 | +} |
68 | 68 |
|
69 | 69 | const generateBuildMatrix = (filesAdded, filesModified, filesRenamed) => {
|
70 |
| - const dockerfiles = [...new Set(getAffectedDockerfiles(filesAdded, filesModified, filesRenamed))]; |
| 70 | + const dockerfiles = [...new Set(getAffectedDockerfiles(filesAdded, filesModified, filesRenamed))] |
71 | 71 |
|
72 |
| - const entries = dockerfiles.map(getDockerfileMatrixEntry); |
| 72 | + const entries = dockerfiles.map(getDockerfileMatrixEntry) |
73 | 73 |
|
74 | 74 | // Return null if there are no entries so we can skip the matrix step
|
75 | 75 | return entries.length
|
76 | 76 | ? { include: entries }
|
77 |
| - : null; |
78 |
| -}; |
| 77 | + : null |
| 78 | +} |
79 | 79 |
|
80 |
| -module.exports = generateBuildMatrix; |
| 80 | +module.exports = generateBuildMatrix |
0 commit comments