From b17fbb00bdc0c0f63fcf166580804b4d2cdc2a42 Mon Sep 17 00:00:00 2001 From: Sean Krail Date: Wed, 8 Apr 2020 12:33:22 -0700 Subject: [PATCH] refactor: rename output deleted to removed 'removed' is the official name used by GitHub's API. 'deleted' will still be supported for backwards-compatibility, but not mentioned in the docs. --- .github/workflows/test.yml | 2 +- README.md | 14 +++++++------- action.yml | 8 ++++++-- dist/index.js | 20 +++++++++++--------- src/main.ts | 21 ++++++++++++--------- 5 files changed, 37 insertions(+), 28 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b007239..954272c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -91,6 +91,6 @@ jobs: echo 'steps.files.outputs.all=${{ steps.files.outputs.all }}' echo 'steps.files.outputs.added=${{ steps.files.outputs.added }}' echo 'steps.files.outputs.modified=${{ steps.files.outputs.modified }}' - echo 'steps.files.outputs.deleted=${{ steps.files.outputs.deleted }}' + echo 'steps.files.outputs.removed=${{ steps.files.outputs.removed }}' echo 'steps.files.outputs.renamed=${{ steps.files.outputs.renamed }}' echo 'steps.files.outputs.added_modified=${{ steps.files.outputs.added_modified }}' diff --git a/README.md b/README.md index d13d7c5..3f4401b 100644 --- a/README.md +++ b/README.md @@ -5,9 +5,9 @@ # Get All Changed Files Get all of the files changed/modified in a pull request or push's commits. -You can choose to get all changed files, only added files, only modified files, only deleted files, or all added and modified files. +You can choose to get all changed files, only added files, only modified files, only removed files, only renamed files, or all added and modified files. These outputs are available via the `steps` output context. -The `steps` output context exposes the output names `all`, `added`, `modified`, `deleted`, `renamed`, and `added_modified`. +The `steps` output context exposes the output names `all`, `added`, `modified`, `removed`, `renamed`, and `added_modified`. # Usage @@ -26,7 +26,7 @@ See [action.yml](action.yml) - [Get all changed files as space-delimited](#get-all-changed-files-as-space-delimited) - [Get all added and modified files as CSV](#get-all-added-and-modified-files-as-csv) -- [Get all deleted files as JSON](#get-all-deleted-files-as-json) +- [Get all removed files as JSON](#get-all-removed-files-as-json) ## Get all changed files as space-delimited @@ -56,7 +56,7 @@ Consider using one of the other formats if that's the case. done ``` -## Get all deleted files as JSON +## Get all removed files as JSON ```yaml - id: files @@ -64,9 +64,9 @@ Consider using one of the other formats if that's the case. with: format: 'json' - run: | - readarray -t deleted_files <<<"$(jq -r '.[]' <<<'${{ steps.files.outputs.deleted }}')" - for deleted_file in ${deleted_files[@]}; do - echo "Do something with this ${deleted_file}." + readarray -t removed_files <<<"$(jq -r '.[]' <<<'${{ steps.files.outputs.removed }}')" + for removed_file in ${removed_files[@]}; do + echo "Do something with this ${removed_file}." done ``` diff --git a/action.yml b/action.yml index 68b354d..2536c03 100644 --- a/action.yml +++ b/action.yml @@ -30,12 +30,16 @@ outputs: modified: description: > Array of modified files. - deleted: + removed: description: > - Array of deleted files. + Array of removed files. renamed: description: > Array of renamed files. added_modified: description: > Array of all added and modified files. + # For backwards-compatibility + deleted: + description: > + Array of deleted files. diff --git a/dist/index.js b/dist/index.js index 732bc20..72c1662 100644 --- a/dist/index.js +++ b/dist/index.js @@ -3572,7 +3572,7 @@ function run() { } // Get the changed files from the response payload. const files = response.data.files; - const all = [], added = [], modified = [], deleted = [], renamed = [], addedModified = []; + const all = [], added = [], modified = [], removed = [], renamed = [], addedModified = []; for (const file of files) { const filename = file.filename; // If we're using the 'space-delimited' format and any of the filenames have a space in them, @@ -3592,17 +3592,17 @@ function run() { addedModified.push(filename); break; case 'removed': - deleted.push(filename); + removed.push(filename); break; case 'renamed': renamed.push(filename); break; default: - core.setFailed(`One of your files includes an unsupported file status '${file.status}', expected 'added', 'modified', or 'removed'.`); + core.setFailed(`One of your files includes an unsupported file status '${file.status}', expected 'added', 'modified', 'removed', or 'renamed'.`); } } // Format the arrays of changed files. - let allFormatted, addedFormatted, modifiedFormatted, deletedFormatted, renamedFormatted, addedModifiedFormatted; + let allFormatted, addedFormatted, modifiedFormatted, removedFormatted, renamedFormatted, addedModifiedFormatted; switch (format) { case 'space-delimited': // If any of the filenames have a space in them, then fail the step. @@ -3613,7 +3613,7 @@ function run() { allFormatted = all.join(' '); addedFormatted = added.join(' '); modifiedFormatted = modified.join(' '); - deletedFormatted = deleted.join(' '); + removedFormatted = removed.join(' '); renamedFormatted = renamed.join(' '); addedModifiedFormatted = addedModified.join(' '); break; @@ -3621,7 +3621,7 @@ function run() { allFormatted = all.join(','); addedFormatted = added.join(','); modifiedFormatted = modified.join(','); - deletedFormatted = deleted.join(','); + removedFormatted = removed.join(','); renamedFormatted = renamed.join(','); addedModifiedFormatted = addedModified.join(','); break; @@ -3629,7 +3629,7 @@ function run() { allFormatted = JSON.stringify(all); addedFormatted = JSON.stringify(added); modifiedFormatted = JSON.stringify(modified); - deletedFormatted = JSON.stringify(deleted); + removedFormatted = JSON.stringify(removed); renamedFormatted = JSON.stringify(renamed); addedModifiedFormatted = JSON.stringify(addedModified); break; @@ -3638,16 +3638,18 @@ function run() { core.info(`All: ${allFormatted}`); core.info(`Added: ${addedFormatted}`); core.info(`Modified: ${modifiedFormatted}`); - core.info(`Deleted: ${deletedFormatted}`); + core.info(`Removed: ${removedFormatted}`); core.info(`Renamed: ${renamedFormatted}`); core.info(`Added or modified: ${addedModifiedFormatted}`); // Set step output context. core.setOutput('all', allFormatted); core.setOutput('added', addedFormatted); core.setOutput('modified', modifiedFormatted); - core.setOutput('deleted', deletedFormatted); + core.setOutput('removed', removedFormatted); core.setOutput('renamed', renamedFormatted); core.setOutput('added_modified', addedModifiedFormatted); + // For backwards-compatibility + core.setOutput('deleted', removedFormatted); } catch (error) { core.setFailed(error.message); diff --git a/src/main.ts b/src/main.ts index 680242b..0f0fdd6 100644 --- a/src/main.ts +++ b/src/main.ts @@ -87,7 +87,7 @@ async function run(): Promise { const all = [] as string[], added = [] as string[], modified = [] as string[], - deleted = [] as string[], + removed = [] as string[], renamed = [] as string[], addedModified = [] as string[] for (const file of files) { @@ -111,14 +111,14 @@ async function run(): Promise { addedModified.push(filename) break case 'removed': - deleted.push(filename) + removed.push(filename) break case 'renamed': renamed.push(filename) break default: core.setFailed( - `One of your files includes an unsupported file status '${file.status}', expected 'added', 'modified', or 'removed'.` + `One of your files includes an unsupported file status '${file.status}', expected 'added', 'modified', 'removed', or 'renamed'.` ) } } @@ -127,7 +127,7 @@ async function run(): Promise { let allFormatted: string, addedFormatted: string, modifiedFormatted: string, - deletedFormatted: string, + removedFormatted: string, renamedFormatted: string, addedModifiedFormatted: string switch (format) { @@ -142,7 +142,7 @@ async function run(): Promise { allFormatted = all.join(' ') addedFormatted = added.join(' ') modifiedFormatted = modified.join(' ') - deletedFormatted = deleted.join(' ') + removedFormatted = removed.join(' ') renamedFormatted = renamed.join(' ') addedModifiedFormatted = addedModified.join(' ') break @@ -150,7 +150,7 @@ async function run(): Promise { allFormatted = all.join(',') addedFormatted = added.join(',') modifiedFormatted = modified.join(',') - deletedFormatted = deleted.join(',') + removedFormatted = removed.join(',') renamedFormatted = renamed.join(',') addedModifiedFormatted = addedModified.join(',') break @@ -158,7 +158,7 @@ async function run(): Promise { allFormatted = JSON.stringify(all) addedFormatted = JSON.stringify(added) modifiedFormatted = JSON.stringify(modified) - deletedFormatted = JSON.stringify(deleted) + removedFormatted = JSON.stringify(removed) renamedFormatted = JSON.stringify(renamed) addedModifiedFormatted = JSON.stringify(addedModified) break @@ -168,7 +168,7 @@ async function run(): Promise { core.info(`All: ${allFormatted}`) core.info(`Added: ${addedFormatted}`) core.info(`Modified: ${modifiedFormatted}`) - core.info(`Deleted: ${deletedFormatted}`) + core.info(`Removed: ${removedFormatted}`) core.info(`Renamed: ${renamedFormatted}`) core.info(`Added or modified: ${addedModifiedFormatted}`) @@ -176,9 +176,12 @@ async function run(): Promise { core.setOutput('all', allFormatted) core.setOutput('added', addedFormatted) core.setOutput('modified', modifiedFormatted) - core.setOutput('deleted', deletedFormatted) + core.setOutput('removed', removedFormatted) core.setOutput('renamed', renamedFormatted) core.setOutput('added_modified', addedModifiedFormatted) + + // For backwards-compatibility + core.setOutput('deleted', removedFormatted) } catch (error) { core.setFailed(error.message) }