Skip to content

[dev] add old name #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Oct 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ jobs:
echo "Removed? ${{ steps.diff.outputs.removed }}"
echo "Renamed? ${{ steps.diff.outputs.renamed }}"
echo "Name: ${{ steps.diff.outputs.name }}"
echo "Previous: ${{ steps.diff.outputs.previous }}"
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Very simple, you provide the action with a `path` to a _file_ or _folder_, and i
## Usage
```yaml
- name: Simple Diff
uses: mudlabs/simple-diff@v1.0.1
uses: mudlabs/simple-diff@v1.0.2
with:
path: path/to/file
```
Expand All @@ -38,6 +38,7 @@ Very simple, you provide the action with a `path` to a _file_ or _folder_, and i
| `removed` | boolean | Specifies the file or folder was removed. |
| `renamed` | boolean | Specifies the file or folder was renamed. |
| `name` | string | Specifies the name of the file or folder. |
| `previous` | string | Specifies the previous file name, or its name. |

## Example Case
You have a workflow that only runs on a push event to a file path. But you don't want it to run if the file was `removed` _(deleted)_.
Expand All @@ -57,11 +58,11 @@ jobs:
- uses: actions/checkout@v2
- name: Simple Diff
id: diff
uses: mudlabs/simple-diff@v1.0.1
uses: mudlabs/simple-diff@v1.0.2
with:
path: path/to/my/file.ext
- run: exit 1
if: steps.diff.outputs.removed
if: steps.diff.outputs.removed == true

# Other jobs will run only if file.ext was NOT removed.
```
Expand Down
7 changes: 4 additions & 3 deletions action.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ const toBoolean = value => value.toLowerCase() == "true";
if (response.data.status !== "ahead") throw `The head commit for this ${github.context.eventName} event is not ahead of the base commit.`;

const target = normalise(path);
const files = response.data.files;
const files = response.data.files;
const file = files.find(file => decodeURIComponent(file.contents_url).indexOf(`contents/${target}`) !== -1);

core.setOutput("name", file ? file.filename : target);
core.setOutput("added", file ? file.status === "added" : false);
core.setOutput("modified", file ? file.status === "modified" : false);
core.setOutput("removed", file ? file.status === "removed" : false);
core.setOutput("renamed", file ? file.status === "renamed" : false);
core.setOutput("name", file ? file.filename : target);
core.setOutput("modified", file ? file.status === "modified" : false);
core.setOutput("previous", file ? file.previous_filename || file.filename : target);

if (file) return;
if (strict) throw `None of the files in this commits diff tree match the provided file (${path}).`;
Expand Down
2 changes: 2 additions & 0 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ outputs:
description: Specifies the item was renamed.
name:
description: Specifies the item name.
previous:
description: The files previous name, or its name.