trilom / file-changes-action

This action can be added, and you will get outputs of all of the files that have changed in your repository for you to use.
MIT License
167 stars 48 forks source link

Renamed files do not show as modified, added or removed, but do appear in `files` #108

Open justyn opened 4 years ago

justyn commented 4 years ago

Describe the bug files_added and files_removed are not showing in my test setup, only files_modified is working correctly. And files which should show all, just shows modified and new.

Workflow Here are the relevant parts of my workflow (other actions not shown include checkout):

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

jobs:
  build:
    runs-on: ubuntu-latest

    steps:

    - uses: trilom/file-changes-action@v1.2.4
      id: file_changes
      with:
        output: ' '
        pushBefore: ${{ github.base_ref }}
        pushAfter: ${{ github.ref }}

    - name: Run a multi-line script
      run: |
        echo modified: ${{ steps.file_changes.outputs.files_modified }}
        echo added: ${{ steps.file_changes.outputs.files_added }}
        echo removed: ${{ steps.file_changes.outputs.files_removed }}
        echo all: ${{ steps.file_changes.outputs.files }}

Expected behavior

I'm removing three files (four, five and six), adding three files (one, two and three), modifying one file (run_checks.sh), each in their own commit, then pushing these commits to a branch with a Pull Request.

I would expect this:

modified: run_checks.sh
added: one two three
removed: four five six
all: run_checks.sh one three two four five six

Actual output:

modified: run_checks.sh
added:
removed:
all: run_checks.sh one three two

Not quite sure what is going on here!

Particularly strange that the added files are not showing in files_added but they are in files.

justyn commented 4 years ago

Ah, I see what happened - these blank test files show as being renamed, that is why they don't show up as files_added or files_removed, and only the new "names" show up in files.

This does show a bit of an inconsistency though, because it means:

files = files_added + files_removed + files_modified + files_renamed

but there is no individual option to test for files_renamed.

Jolg42 commented 3 years ago

I'm also interested to track renamed/moved files, reading this issue it seems that feature is not yet covered?

Issafalcon commented 3 years ago

We've also run into an issue with not picking up renamed files. GitHub doesn't include the "old" file (one that was renamed) in the list of modified files. The old name is only included as an additional field on the renamed files entry, which the action code doesn't do anything with. Seeing that this issue has been around for a while, we are fixing it ourselves. Ticket is on our backlog at the moment, but I will be issuing a PR once we've established it works.

marc-hb commented 2 years ago

We've also run into an issue with not picking up renamed files. [...] Ticket is on our backlog at the moment

Who is "we" and what backlog is this? Is this involving this action or something else?

GitHub doesn't include the "old" file (one that was renamed) in the list of modified files

If it were just that then it wouldn't be too bad. I mean if at least the new name was listed in added files then it would be OK-ish for most users.

BTW: git diff --no-renames

Issafalcon commented 2 years ago

Apologies, I realise my comment was a bit cryptic. I meant 'we' as in the company I'm working for at the moment, and the backlog being the one we have internally (which is pretty long!)

You're right that the issue isn't something that causes problems for the most part. It is only affecting my current team as we are using terraform in quite a specific way that depends on the file-changes-action to determine which .tf files have changed to then decide which files to run terraform apply on.

Thanks for the tip about --no-renames. It could help our situation.

808sAndBR commented 2 years ago

I dug into the code a bit and while it is not documented like the rest of them, there is a files_renamed object that has the info I needed in it:

${{ steps.get_file_changes.outputs.files_renamed }}

I dont actually know js or typescript (im a python/R dev) but I think it is getting added here: https://github.com/trilom/file-changes-action/blob/a6ca26c14274c33b15e6499323aac178af06ad4b/src/FilesHelper.ts#L24-L30

Annnnnyways if you are having issues with this try accessing the renames directly with that path.