Skip to content

Commit

Permalink
Merge pull request #11 from keiththompson/keith/add_build_all_feature
Browse files Browse the repository at this point in the history
Fix
  • Loading branch information
keiththompson authored May 7, 2021
2 parents 6716b1d + 8cffc04 commit 496a6a1
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 42 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ jobs:
uses: ./
id: generate_build_matrix
with:
build-all: true
target-directory: .github
repo-token: ${{ secrets.MY_GITHUB_TOKEN }}
- name: Print the output
run: |
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ inputs:
target-directory:
description: 'An optional target directory to listen to changes in'
required: false
build-all:
description: 'Set to true to build all sub directories in the target directory'
required: false
default: false
outputs:
build_matrix:
description: 'The files changed between the default branch and the sha being built'
Expand Down
32 changes: 11 additions & 21 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports =

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

try {
const context = github.context.payload;
Expand All @@ -23,24 +23,17 @@ try {
const token = core.getInput('repo-token');
const octokit = github.getOctokit(token);
const depth = core.getInput('depth');
const buildAll = core.getInput('build-all');
const targetDirectory = core.getInput('target-directory')
if (targetDirectory && depth == 1) {
depth = 2;
}
var labels;
if (github.context.eventName === 'pull_request') {
labels = context['pull_request']['labels'];
} else {
labels = [];
}

if (shouldBuildAll(labels)) {
const directories = targetDirectory => readdirSync(targetDirectory, { withFileTypes: true })
.filter(dirent => dirent.isDirectory())
.map(dirent => dirent.name)
if (buildAll) {
const directories = getDirectories(targetDirectory)
const result = buildMatrix(directories)
core.setOutput("is_empty", result['include'].length < 1)
core.setOutput("build_matrix", JSON.stringify(result));
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 => {
Expand Down Expand Up @@ -95,14 +88,11 @@ function buildMatrix(changedDirectories) {
return {'include': include};
}

function shouldBuildAll(labels) {
for (label of labels) {
if (label['name'] === "build-all") {
return true
}
}
return false
}
function getDirectories(path) {
const isDirectory = fs.lstatSync(path).isDirectory()
return fs.readdirSync(path, { withFileTypes: true})
.filter(directory => fs.lstatSync(path + "/" + directory.name).isDirectory())
}

/***/ }),

Expand Down
32 changes: 11 additions & 21 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const core = require('@actions/core');
const github = require('@actions/github');
const readdirSync = require('fs')
const fs = require('fs')

try {
const context = github.context.payload;
Expand All @@ -16,24 +16,17 @@ try {
const token = core.getInput('repo-token');
const octokit = github.getOctokit(token);
const depth = core.getInput('depth');
const buildAll = core.getInput('build-all');
const targetDirectory = core.getInput('target-directory')
if (targetDirectory && depth == 1) {
depth = 2;
}
var labels;
if (github.context.eventName === 'pull_request') {
labels = context['pull_request']['labels'];
} else {
labels = [];
}

if (shouldBuildAll(labels)) {
const directories = targetDirectory => readdirSync(targetDirectory, { withFileTypes: true })
.filter(dirent => dirent.isDirectory())
.map(dirent => dirent.name)
if (buildAll) {
const directories = getDirectories(targetDirectory)
const result = buildMatrix(directories)
core.setOutput("is_empty", result['include'].length < 1)
core.setOutput("build_matrix", JSON.stringify(result));
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 => {
Expand Down Expand Up @@ -88,11 +81,8 @@ function buildMatrix(changedDirectories) {
return {'include': include};
}

function shouldBuildAll(labels) {
for (label of labels) {
if (label['name'] === "build-all") {
return true
}
}
return false
}
function getDirectories(path) {
const isDirectory = fs.lstatSync(path).isDirectory()
return fs.readdirSync(path, { withFileTypes: true})
.filter(directory => fs.lstatSync(path + "/" + directory.name).isDirectory())
}

0 comments on commit 496a6a1

Please sign in to comment.