Skip to content

Commit

Permalink
Merge pull request #10 from keiththompson/keith/add_build_all_feature
Browse files Browse the repository at this point in the history
Add build all feature
  • Loading branch information
keiththompson authored May 6, 2021
2 parents 562467b + e712d3d commit 6716b1d
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 28 deletions.
53 changes: 39 additions & 14 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module.exports =

const core = __webpack_require__(127);
const github = __webpack_require__(134);
const readdirSync = __webpack_require__(747)

try {
const context = github.context.payload;
Expand All @@ -26,21 +27,36 @@ try {
if (targetDirectory && depth == 1) {
depth = 2;
}
var labels;
if (github.context.eventName === 'pull_request') {
labels = context['pull_request']['labels'];
} else {
labels = [];
}

octokit.repos.compareCommits({owner, repo, base, head})
.then(data => {
const changedDirectories = data['data']['files']
.map(file => file['filename'])
.filter(file => reduceFile(file, targetDirectory))
.map(file => parseDirectories(file, depth, targetDirectory))
.filter(directory => directory.length > 0);
const result = buildMatrix(changedDirectories)
core.setOutput("is_empty", result['include'].length < 1)
core.setOutput("build_matrix", JSON.stringify(result));
}).catch(error => {
console.log(error);
core.setFailed(error.message);
});
if (shouldBuildAll(labels)) {
const directories = targetDirectory => readdirSync(targetDirectory, { withFileTypes: true })
.filter(dirent => dirent.isDirectory())
.map(dirent => dirent.name)
const result = buildMatrix(directories)
core.setOutput("is_empty", result['include'].length < 1)
core.setOutput("build_matrix", JSON.stringify(result));
} else {
octokit.repos.compareCommits({owner, repo, base, head})
.then(data => {
const changedDirectories = data['data']['files']
.map(file => file['filename'])
.filter(file => reduceFile(file, targetDirectory))
.map(file => parseDirectories(file, depth, targetDirectory))
.filter(directory => directory.length > 0);
const result = buildMatrix(changedDirectories)
core.setOutput("is_empty", result['include'].length < 1)
core.setOutput("build_matrix", JSON.stringify(result));
}).catch(error => {
console.log(error);
core.setFailed(error.message);
});
}

} catch (error) {
console.log(error);
Expand Down Expand Up @@ -79,6 +95,15 @@ function buildMatrix(changedDirectories) {
return {'include': include};
}

function shouldBuildAll(labels) {
for (label of labels) {
if (label['name'] === "build-all") {
return true
}
}
return false
}

/***/ }),

/***/ 604:
Expand Down
53 changes: 39 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const core = require('@actions/core');
const github = require('@actions/github');
const readdirSync = require('fs')

try {
const context = github.context.payload;
Expand All @@ -19,21 +20,36 @@ try {
if (targetDirectory && depth == 1) {
depth = 2;
}
var labels;
if (github.context.eventName === 'pull_request') {
labels = context['pull_request']['labels'];
} else {
labels = [];
}

octokit.repos.compareCommits({owner, repo, base, head})
.then(data => {
const changedDirectories = data['data']['files']
.map(file => file['filename'])
.filter(file => reduceFile(file, targetDirectory))
.map(file => parseDirectories(file, depth, targetDirectory))
.filter(directory => directory.length > 0);
const result = buildMatrix(changedDirectories)
core.setOutput("is_empty", result['include'].length < 1)
core.setOutput("build_matrix", JSON.stringify(result));
}).catch(error => {
console.log(error);
core.setFailed(error.message);
});
if (shouldBuildAll(labels)) {
const directories = targetDirectory => readdirSync(targetDirectory, { withFileTypes: true })
.filter(dirent => dirent.isDirectory())
.map(dirent => dirent.name)
const result = buildMatrix(directories)
core.setOutput("is_empty", result['include'].length < 1)
core.setOutput("build_matrix", JSON.stringify(result));
} else {
octokit.repos.compareCommits({owner, repo, base, head})
.then(data => {
const changedDirectories = data['data']['files']
.map(file => file['filename'])
.filter(file => reduceFile(file, targetDirectory))
.map(file => parseDirectories(file, depth, targetDirectory))
.filter(directory => directory.length > 0);
const result = buildMatrix(changedDirectories)
core.setOutput("is_empty", result['include'].length < 1)
core.setOutput("build_matrix", JSON.stringify(result));
}).catch(error => {
console.log(error);
core.setFailed(error.message);
});
}

} catch (error) {
console.log(error);
Expand Down Expand Up @@ -70,4 +86,13 @@ function buildMatrix(changedDirectories) {
include.push({'directory': directory});
}
return {'include': include};
}

function shouldBuildAll(labels) {
for (label of labels) {
if (label['name'] === "build-all") {
return true
}
}
return false
}

0 comments on commit 6716b1d

Please sign in to comment.