Skip to content

Commit

Permalink
Fix issue with processing exiting before output is finished being pri…
Browse files Browse the repository at this point in the history
…nted. Also exclude merge commits since we only want the files changed by the current PR or push event. Bump version.
  • Loading branch information
lots0logs committed Jun 6, 2020
1 parent f1fbe31 commit 56647e5
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 25 deletions.
28 changes: 16 additions & 12 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,15 +376,15 @@ async function outputResults() {
core.setOutput('removed', toJSON(Array.from(FILES_REMOVED.values()), 0));
core.setOutput('renamed', toJSON(Array.from(FILES_RENAMED.values()), 0));

fs.writeFileSync(`${process.env.HOME}/files.json`, toJSON(Array.from(FILES.values()), 0), 'utf-8');
fs.writeFileSync(`${process.env.HOME}/files_added.json`, toJSON(Array.from(FILES_ADDED.values()), 0), 'utf-8');
fs.writeFileSync(`${process.env.HOME}/files_modified.json`, toJSON(Array.from(FILES_MODIFIED.values()), 0), 'utf-8');
fs.writeFileSync(`${process.env.HOME}/files_removed.json`, toJSON(Array.from(FILES_REMOVED.values()), 0), 'utf-8');
fs.writeFileSync(`${process.env.HOME}/files_renamed.json`, toJSON(Array.from(FILES_RENAMED.values()), 0), 'utf-8');
fs.writeFileSync(`${process.env.HOME}/files.json`, toJSON(Array.from(FILES.values())), 'utf-8');
fs.writeFileSync(`${process.env.HOME}/files_added.json`, toJSON(Array.from(FILES_ADDED.values())), 'utf-8');
fs.writeFileSync(`${process.env.HOME}/files_modified.json`, toJSON(Array.from(FILES_MODIFIED.values())), 'utf-8');
fs.writeFileSync(`${process.env.HOME}/files_removed.json`, toJSON(Array.from(FILES_REMOVED.values())), 'utf-8');
fs.writeFileSync(`${process.env.HOME}/files_renamed.json`, toJSON(Array.from(FILES_RENAMED.values())), 'utf-8');

// Backwards Compatability
core.setOutput('deleted', toJSON(Array.from(FILES_REMOVED.values()), 0));
fs.writeFileSync(`${process.env.HOME}/files_deleted.json`, toJSON(Array.from(FILES_REMOVED.values()), 0), 'utf-8');
fs.writeFileSync(`${process.env.HOME}/files_deleted.json`, toJSON(Array.from(FILES_REMOVED.values())), 'utf-8');
}

async function processCommitData(result) {
Expand All @@ -405,7 +405,10 @@ async function processCommitData(result) {
}

if (isRemoved(file)) {
FILES_REMOVED.add(file.filename);
if (! FILES_ADDED.has(file.filename)) {
FILES_REMOVED.add(file.filename);
}

FILES_ADDED.delete(file.filename);
FILES_MODIFIED.delete(file.filename);

Expand Down Expand Up @@ -435,19 +438,20 @@ debug('context', context);
debug('args', args);

getCommits().then(commits => {
debug('All Commits', commits);
// Exclude merge commits
commits = commits.filter(c => 1 === c.parents.length);

if ('push' === context.eventName) {
commits = commits.filter(c => c.distinct);

debug('All Distinct Commits', commits);
}

debug('All Commits', commits);

Promise.all(commits.map(fetchCommitData))
.then(data => Promise.all(data.map(processCommitData)))
.then(outputResults)
.then(() => process.exit(0))
.catch(err => core.error(err) && process.exit(1));
.then(() => process.exitCode = 0)
.catch(err => core.error(err) && (process.exitCode = 1));
});


Expand Down
28 changes: 16 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ async function outputResults() {
core.setOutput('removed', toJSON(Array.from(FILES_REMOVED.values()), 0));
core.setOutput('renamed', toJSON(Array.from(FILES_RENAMED.values()), 0));

fs.writeFileSync(`${process.env.HOME}/files.json`, toJSON(Array.from(FILES.values()), 0), 'utf-8');
fs.writeFileSync(`${process.env.HOME}/files_added.json`, toJSON(Array.from(FILES_ADDED.values()), 0), 'utf-8');
fs.writeFileSync(`${process.env.HOME}/files_modified.json`, toJSON(Array.from(FILES_MODIFIED.values()), 0), 'utf-8');
fs.writeFileSync(`${process.env.HOME}/files_removed.json`, toJSON(Array.from(FILES_REMOVED.values()), 0), 'utf-8');
fs.writeFileSync(`${process.env.HOME}/files_renamed.json`, toJSON(Array.from(FILES_RENAMED.values()), 0), 'utf-8');
fs.writeFileSync(`${process.env.HOME}/files.json`, toJSON(Array.from(FILES.values())), 'utf-8');
fs.writeFileSync(`${process.env.HOME}/files_added.json`, toJSON(Array.from(FILES_ADDED.values())), 'utf-8');
fs.writeFileSync(`${process.env.HOME}/files_modified.json`, toJSON(Array.from(FILES_MODIFIED.values())), 'utf-8');
fs.writeFileSync(`${process.env.HOME}/files_removed.json`, toJSON(Array.from(FILES_REMOVED.values())), 'utf-8');
fs.writeFileSync(`${process.env.HOME}/files_renamed.json`, toJSON(Array.from(FILES_RENAMED.values())), 'utf-8');

// Backwards Compatability
core.setOutput('deleted', toJSON(Array.from(FILES_REMOVED.values()), 0));
fs.writeFileSync(`${process.env.HOME}/files_deleted.json`, toJSON(Array.from(FILES_REMOVED.values()), 0), 'utf-8');
fs.writeFileSync(`${process.env.HOME}/files_deleted.json`, toJSON(Array.from(FILES_REMOVED.values())), 'utf-8');
}

async function processCommitData(result) {
Expand All @@ -117,7 +117,10 @@ async function processCommitData(result) {
}

if (isRemoved(file)) {
FILES_REMOVED.add(file.filename);
if (! FILES_ADDED.has(file.filename)) {
FILES_REMOVED.add(file.filename);
}

FILES_ADDED.delete(file.filename);
FILES_MODIFIED.delete(file.filename);

Expand Down Expand Up @@ -147,18 +150,19 @@ debug('context', context);
debug('args', args);

getCommits().then(commits => {
debug('All Commits', commits);
// Exclude merge commits
commits = commits.filter(c => 1 === c.parents.length);

if ('push' === context.eventName) {
commits = commits.filter(c => c.distinct);

debug('All Distinct Commits', commits);
}

debug('All Commits', commits);

Promise.all(commits.map(fetchCommitData))
.then(data => Promise.all(data.map(processCommitData)))
.then(outputResults)
.then(() => process.exit(0))
.catch(err => core.error(err) && process.exit(1));
.then(() => process.exitCode = 0)
.catch(err => core.error(err) && (process.exitCode = 1));
});

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gh-action-get-changed-files",
"version": "2.1.1rc4",
"version": "2.1.1",
"private": true,
"main": "dist/index.js",
"scripts":{
Expand Down

0 comments on commit 56647e5

Please sign in to comment.