tj-actions / changed-files

:octocat: Github action to retrieve all (added, copied, modified, deleted, renamed, type changed, unmerged, unknown) files and directories.
MIT License
1.82k stars 193 forks source link

[BUG] Files not found when not last commit on new branch #952

Closed thearchitector closed 1 year ago

thearchitector commented 1 year ago

Is there an existing issue for this?

Does this issue exist in the latest version?

Describe the bug?

If I push several commits to a new branch (as in, create a branch locally and commit several times, then git push -u), no changed files are detected if the last commit in the batch isn't an edit on any of those files (filtered by grep).

If the flow of commits is this:

main (A last commit)
PR (no last remote, doesn't exist) -- PR (B-C-D pushed local commits, creates remote branch)

I should see A compared to D, but I actually see C compared to D. If none of the files matched by the grep were changed between C and D, nothing is picked up.

To Reproduce

- id: changed-files
  uses: tj-actions/changed-files@v35
  with:
    since_last_remote_commit: "true"
    files: |
      */banana
- if: steps.changed-files.outputs.any_changed == 'true'
  run: |
    set -ex
    for file in ${{ steps.changed-files.outputs.all_changed_files }}; do
      echo $file
    done
  1. git checkout -b example
  2. Create a new directory with some files in it:
    • ./example/banana
    • ./example/pie
  3. Edit a file outside that directory that doesn't match the grep pattern:
    • ./README
  4. git add example && git commit -m "match"
  5. git add README && git commit -m "no match"
  6. git push -u origin example

What OS are you seeing the problem on?

ubuntu-latest or ubuntu-20.04

Expected behavior?

Changes should be triggered for all the files matching the grep since the branch is new and since_last_remote_commit = "true".

If the flow of commits is this:

main (A last commit)
PR (no last remote, doesn't exist) -- PR (B-C-D pushed local commits, creates remote branch)

I should see A compared to D, and all matching files picked up by the action.

Relevant log output

2023-01-18T19:00:31.2118864Z ##[group]Run actions/checkout@v3
2023-01-18T19:00:31.2119187Z with:
2023-01-18T19:00:31.2119432Z   fetch-depth: 0
2023-01-18T19:00:31.2119745Z   repository: metabronx/docker-images
2023-01-18T19:00:31.2120275Z   token: ***
2023-01-18T19:00:31.2120516Z   ssh-strict: true
2023-01-18T19:00:31.2120790Z   persist-credentials: true
2023-01-18T19:00:31.2121041Z   clean: true
2023-01-18T19:00:31.2121267Z   lfs: false
2023-01-18T19:00:31.2121498Z   submodules: false
2023-01-18T19:00:31.2121750Z   set-safe-directory: true
2023-01-18T19:00:31.2122021Z ##[endgroup]
2023-01-18T19:00:31.2273528Z ##[command]/usr/bin/docker exec  e535e233fd2f352c1b546ae3aaa28e8c86aa75269ce750e08b31c26a4c197d1c sh -c "cat /etc/*release | grep ^ID"
2023-01-18T19:00:31.7636707Z Syncing repository: metabronx/docker-images
2023-01-18T19:00:31.7638684Z ##[group]Getting Git version info
2023-01-18T19:00:31.7639257Z Working directory is '/__w/docker-images/docker-images'
2023-01-18T19:00:31.7640296Z [command]/usr/bin/git version
2023-01-18T19:00:31.7659672Z git version 2.30.2
2023-01-18T19:00:31.7699755Z ##[endgroup]
2023-01-18T19:00:31.7741320Z Temporarily overriding HOME='/__w/_temp/ad61d1b3-ec72-4463-8d39-384670e966e5' before making global git config changes
2023-01-18T19:00:31.7742183Z Adding repository directory to the temporary git global config as a safe directory
2023-01-18T19:00:31.7751459Z [command]/usr/bin/git config --global --add safe.directory /__w/docker-images/docker-images
2023-01-18T19:00:31.7812830Z Deleting the contents of '/__w/docker-images/docker-images'
2023-01-18T19:00:31.7819279Z ##[group]Initializing the repository
2023-01-18T19:00:31.7825230Z [command]/usr/bin/git init /__w/docker-images/docker-images
2023-01-18T19:00:31.7900875Z hint: Using 'master' as the name for the initial branch. This default branch name
2023-01-18T19:00:31.7901519Z hint: is subject to change. To configure the initial branch name to use in all
2023-01-18T19:00:31.7902086Z hint: of your new repositories, which will suppress this warning, call:
2023-01-18T19:00:31.7902486Z hint: 
2023-01-18T19:00:31.7903445Z hint:  git config --global init.defaultBranch <name>
2023-01-18T19:00:31.7903848Z hint: 
2023-01-18T19:00:31.7904784Z hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
2023-01-18T19:00:31.7908331Z hint: 'development'. The just-created branch can be renamed via this command:
2023-01-18T19:00:31.7908949Z hint: 
2023-01-18T19:00:31.7909849Z hint:  git branch -m <name>
2023-01-18T19:00:31.7919345Z Initialized empty Git repository in /__w/docker-images/docker-images/.git/
2023-01-18T19:00:31.7935390Z [command]/usr/bin/git remote add origin https://github.com/metabronx/docker-images
2023-01-18T19:00:31.8017987Z ##[endgroup]
2023-01-18T19:00:31.8018657Z ##[group]Disabling automatic garbage collection
2023-01-18T19:00:31.8025729Z [command]/usr/bin/git config --local gc.auto 0
2023-01-18T19:00:31.8070747Z ##[endgroup]
2023-01-18T19:00:31.8071321Z ##[group]Setting up auth
2023-01-18T19:00:31.8082499Z [command]/usr/bin/git config --local --name-only --get-regexp core\.sshCommand
2023-01-18T19:00:31.8129751Z [command]/usr/bin/git submodule foreach --recursive sh -c "git config --local --name-only --get-regexp 'core\.sshCommand' && git config --local --unset-all 'core.sshCommand' || :"
2023-01-18T19:00:31.8411784Z [command]/usr/bin/git config --local --name-only --get-regexp http\.https\:\/\/github\.com\/\.extraheader
2023-01-18T19:00:31.8457139Z [command]/usr/bin/git submodule foreach --recursive sh -c "git config --local --name-only --get-regexp 'http\.https\:\/\/github\.com\/\.extraheader' && git config --local --unset-all 'http.https://github.com/.extraheader' || :"
2023-01-18T19:00:31.8743090Z [command]/usr/bin/git config --local http.https://github.com/.extraheader AUTHORIZATION: basic ***
2023-01-18T19:00:31.8851387Z ##[endgroup]
2023-01-18T19:00:31.8852026Z ##[group]Fetching the repository
2023-01-18T19:00:31.8878902Z [command]/usr/bin/git -c protocol.version=2 fetch --prune --progress --no-recurse-submodules origin +refs/heads/*:refs/remotes/origin/* +refs/tags/*:refs/tags/*
2023-01-18T19:00:32.5450178Z remote: Enumerating objects: 81, done.        
2023-01-18T19:00:32.5450690Z remote: Counting objects:   7% (1/14)        
2023-01-18T19:00:32.5451230Z remote: Counting objects:  14% (2/14)        
2023-01-18T19:00:32.5451662Z remote: Counting objects:  21% (3/14)        
2023-01-18T19:00:32.5452086Z remote: Counting objects:  28% (4/14)        
2023-01-18T19:00:32.5452490Z remote: Counting objects:  35% (5/14)        
2023-01-18T19:00:32.5452920Z remote: Counting objects:  42% (6/14)        
2023-01-18T19:00:32.5453341Z remote: Counting objects:  50% (7/14)        
2023-01-18T19:00:32.5453739Z remote: Counting objects:  57% (8/14)        
2023-01-18T19:00:32.5454355Z remote: Counting objects:  64% (9/14)        
2023-01-18T19:00:32.5454785Z remote: Counting objects:  71% (10/14)        
2023-01-18T19:00:32.5455209Z remote: Counting objects:  78% (11/14)        
2023-01-18T19:00:32.5455634Z remote: Counting objects:  85% (12/14)        
2023-01-18T19:00:32.5456052Z remote: Counting objects:  92% (13/14)        
2023-01-18T19:00:32.5457455Z remote: Counting objects: 100% (14/14)        
2023-01-18T19:00:32.5457828Z remote: Counting objects: 100% (14/14), done.        
2023-01-18T19:00:32.5458519Z remote: Compressing objects:  10% (1/10)        
2023-01-18T19:00:32.5458854Z remote: Compressing objects:  20% (2/10)        
2023-01-18T19:00:32.5459163Z remote: Compressing objects:  30% (3/10)        
2023-01-18T19:00:32.5459485Z remote: Compressing objects:  40% (4/10)        
2023-01-18T19:00:32.5459813Z remote: Compressing objects:  50% (5/10)        
2023-01-18T19:00:32.5460116Z remote: Compressing objects:  60% (6/10)        
2023-01-18T19:00:32.5460456Z remote: Compressing objects:  70% (7/10)        
2023-01-18T19:00:32.5460765Z remote: Compressing objects:  80% (8/10)        
2023-01-18T19:00:32.5461081Z remote: Compressing objects:  90% (9/10)        
2023-01-18T19:00:32.5461402Z remote: Compressing objects: 100% (10/10)        
2023-01-18T19:00:32.5461752Z remote: Compressing objects: 100% (10/10), done.        
2023-01-18T19:00:32.5850953Z remote: Total 81 (delta 4), reused 10 (delta 2), pack-reused 67        
2023-01-18T19:00:32.6072662Z From https://github.com/metabronx/docker-images
2023-01-18T19:00:32.6073109Z  * [new branch]      main       -> origin/main
2023-01-18T19:00:32.6079191Z  * [new branch]      nginx      -> origin/nginx
2023-01-18T19:00:32.6130511Z [command]/usr/bin/git branch --list --remote origin/nginx
2023-01-18T19:00:32.6152473Z   origin/nginx
2023-01-18T19:00:32.6164201Z [command]/usr/bin/git rev-parse refs/remotes/origin/nginx
2023-01-18T19:00:32.6195175Z 6ae881deb8a5773601a1367c5cc4da1864a3693a
2023-01-18T19:00:32.6205558Z ##[endgroup]
2023-01-18T19:00:32.6206025Z ##[group]Determining the checkout info
2023-01-18T19:00:32.6206486Z ##[endgroup]
2023-01-18T19:00:32.6206905Z ##[group]Checking out the ref
2023-01-18T19:00:32.6210224Z [command]/usr/bin/git checkout --progress --force -B nginx refs/remotes/origin/nginx
2023-01-18T19:00:32.6279709Z Switched to a new branch 'nginx'
2023-01-18T19:00:32.6280604Z Branch 'nginx' set up to track remote branch 'nginx' from 'origin'.
2023-01-18T19:00:32.6289715Z ##[endgroup]
2023-01-18T19:00:32.6340397Z [command]/usr/bin/git log -1 --format='%H'
2023-01-18T19:00:32.6373450Z '6ae881deb8a5773601a1367c5cc4da1864a3693a'
2023-01-18T19:00:32.6769925Z ##[group]Run tj-actions/changed-files@v35
2023-01-18T19:00:32.6770210Z with:
2023-01-18T19:00:32.6770453Z   since_last_remote_commit: true
2023-01-18T19:00:32.6770722Z   files: */Dockerfile

2023-01-18T19:00:32.6770956Z   separator:  
2023-01-18T19:00:32.6771224Z   include_all_old_new_renamed_files: false
2023-01-18T19:00:32.6771653Z   old_new_separator: ,
2023-01-18T19:00:32.6771910Z   old_new_files_separator:  
2023-01-18T19:00:32.6772160Z   files_separator: 

2023-01-18T19:00:32.6772420Z   files_ignore_separator: 

2023-01-18T19:00:32.6772669Z   path: .
2023-01-18T19:00:32.6772878Z   quotepath: true
2023-01-18T19:00:32.6773118Z   dir_names: false
2023-01-18T19:00:32.6773345Z   json: false
2023-01-18T19:00:32.6773566Z   json_raw_format: false
2023-01-18T19:00:32.6773811Z   fetch_depth: 50
2023-01-18T19:00:32.6774060Z   write_output_files: false
2023-01-18T19:00:32.6774506Z   output_dir: .github/outputs
2023-01-18T19:00:32.6774776Z   match_directories: true
2023-01-18T19:00:32.6775069Z ##[endgroup]
2023-01-18T19:00:32.7047634Z ##[group]Run # "Calculating the previous and current SHA..."
2023-01-18T19:00:32.7048066Z # "Calculating the previous and current SHA..."
2023-01-18T19:00:32.7048419Z bash $GITHUB_ACTION_PATH/diff-sha.sh
2023-01-18T19:00:32.7050809Z shell: bash --noprofile --norc -e -o pipefail {0}
2023-01-18T19:00:32.7051131Z env:
2023-01-18T19:00:32.7051415Z   GITHUB_SERVER_URL: https://github.com
2023-01-18T19:00:32.7051742Z   GITHUB_REPOSITORY: metabronx/docker-images
2023-01-18T19:00:32.7052053Z   GITHUB_REF: refs/heads/nginx
2023-01-18T19:00:32.7052373Z   GITHUB_SHA: 6ae881deb8a5773601a1367c5cc4da1864a3693a
2023-01-18T19:00:32.7052760Z   GITHUB_WORKSPACE: /home/runner/work/docker-images/docker-images
2023-01-18T19:00:32.7053094Z   GITHUB_EVENT_HEAD_REPO_FORK: 
2023-01-18T19:00:32.7053386Z   GITHUB_EVENT_PULL_REQUEST_NUMBER: 
2023-01-18T19:00:32.7053692Z   GITHUB_EVENT_PULL_REQUEST_BASE_REF: 
2023-01-18T19:00:32.7053982Z   GITHUB_EVENT_PULL_REQUEST_HEAD_REF: 
2023-01-18T19:00:32.7054541Z   GITHUB_EVENT_PULL_REQUEST_BASE_SHA: 
2023-01-18T19:00:32.7054842Z   GITHUB_EVENT_PULL_REQUEST_HEAD_SHA: 
2023-01-18T19:00:32.7055128Z   GITHUB_EVENT_PULL_REQUEST_COMMITS: 
2023-01-18T19:00:32.7055444Z   GITHUB_EVENT_BEFORE: 0000000000000000000000000000000000000000
2023-01-18T19:00:32.7055741Z   GITHUB_EVENT_FORCED: false
2023-01-18T19:00:32.7055999Z   GITHUB_REFNAME: nginx
2023-01-18T19:00:32.7056243Z   INPUT_SHA: 
2023-01-18T19:00:32.7056476Z   INPUT_BASE_SHA: 
2023-01-18T19:00:32.7056694Z   INPUT_SINCE: 
2023-01-18T19:00:32.7056923Z   INPUT_UNTIL: 
2023-01-18T19:00:32.7057148Z   INPUT_PATH: .
2023-01-18T19:00:32.7057374Z   INPUT_FETCH_DEPTH: 50
2023-01-18T19:00:32.7057660Z   INPUT_SINCE_LAST_REMOTE_COMMIT: true
2023-01-18T19:00:32.7057999Z ##[endgroup]
2023-01-18T19:00:32.8029419Z ##[group]changed-files-diff-sha
2023-01-18T19:00:32.8030855Z Verifying git version...
2023-01-18T19:00:32.8091633Z Valid git version found: (2.30.2)
2023-01-18T19:00:32.8097976Z Running on a push event...
2023-01-18T19:00:32.8287964Z ##[endgroup]
2023-01-18T19:00:32.8418667Z ##[group]Run tj-actions/glob@v16
2023-01-18T19:00:32.8418917Z with:
2023-01-18T19:00:32.8419148Z   files: */Dockerfile

2023-01-18T19:00:32.8419411Z   files-separator: 

2023-01-18T19:00:32.8419680Z   excluded-files-separator: 

2023-01-18T19:00:32.8419969Z   escape-paths: true
2023-01-18T19:00:32.8420242Z   working-directory: .
2023-01-18T19:00:32.8420531Z   base-sha: 5125d4ac8184a852129813c3ba7e538871f004b4
2023-01-18T19:00:32.8420863Z   sha: 6ae881deb8a5773601a1367c5cc4da1864a3693a
2023-01-18T19:00:32.8421135Z   diff: ..
2023-01-18T19:00:32.8421365Z   match-directories: true
2023-01-18T19:00:32.8421652Z   include-deleted-files: true
2023-01-18T19:00:32.8421920Z   separator: |
2023-01-18T19:00:32.8422209Z   files-from-source-file-separator: 

2023-01-18T19:00:32.8422587Z   excluded-files-from-source-file-separator: 

2023-01-18T19:00:32.8422944Z   follow-symbolic-links: true
2023-01-18T19:00:32.8423398Z   match-gitignore-files: false
2023-01-18T19:00:32.8423685Z   strip-top-level-dir: true
2023-01-18T19:00:32.8423960Z ##[endgroup]
2023-01-18T19:00:32.8429220Z ##[command]/usr/bin/docker exec  e535e233fd2f352c1b546ae3aaa28e8c86aa75269ce750e08b31c26a4c197d1c sh -c "cat /etc/*release | grep ^ID"
2023-01-18T19:00:33.1243420Z [command]/usr/bin/git rev-parse --show-toplevel
2023-01-18T19:00:33.1293895Z /__w/docker-images/docker-images
2023-01-18T19:00:33.1330567Z [command]/usr/bin/git diff --diff-filter=D --name-only 5125d4ac8184a852129813c3ba7e538871f004b4..6ae881deb8a5773601a1367c5cc4da1864a3693a
2023-01-18T19:00:33.1407804Z Successfully created paths-output-file: /tmp/c19ad6a8-aff3-4747-8b56-6386493e1e25.txt
2023-01-18T19:00:33.1556785Z ##[group]Run bash $GITHUB_ACTION_PATH/get-changed-paths.sh
2023-01-18T19:00:33.1557202Z bash $GITHUB_ACTION_PATH/get-changed-paths.sh
2023-01-18T19:00:33.1557640Z shell: bash --noprofile --norc -e -o pipefail {0}
2023-01-18T19:00:33.1557920Z env:
2023-01-18T19:00:33.1558248Z   GITHUB_WORKSPACE: /home/runner/work/docker-images/docker-images
2023-01-18T19:00:33.1558608Z   GITHUB_EVENT_PULL_REQUEST_BASE_REF: 
2023-01-18T19:00:33.1558911Z   GITHUB_EVENT_PULL_REQUEST_HEAD_REPO_FORK: 
2023-01-18T19:00:33.1559290Z   INPUT_FILES_PATTERN_FILE: /tmp/c19ad6a8-aff3-4747-8b56-6386493e1e25.txt
2023-01-18T19:00:33.1559624Z   INPUT_SEPARATOR:  
2023-01-18T19:00:33.1559859Z   INPUT_PATH: .
2023-01-18T19:00:33.1560162Z   INPUT_PREVIOUS_SHA: 5125d4ac8184a852129813c3ba7e538871f004b4
2023-01-18T19:00:33.1560532Z   INPUT_CURRENT_SHA: 6ae881deb8a5773601a1367c5cc4da1864a3693a
2023-01-18T19:00:33.1560838Z   INPUT_TARGET_BRANCH: nginx
2023-01-18T19:00:33.1561108Z   INPUT_CURRENT_BRANCH: nginx
2023-01-18T19:00:33.1561367Z   INPUT_DIFF: ..
2023-01-18T19:00:33.1561600Z   INPUT_QUOTEPATH: true
2023-01-18T19:00:33.1561895Z   INPUT_INCLUDE_ALL_OLD_NEW_RENAMED_FILES: false
2023-01-18T19:00:33.1562193Z   INPUT_OLD_NEW_SEPARATOR: ,
2023-01-18T19:00:33.1562476Z   INPUT_OLD_NEW_FILES_SEPARATOR:  
2023-01-18T19:00:33.1562740Z   INPUT_DIFF_RELATIVE: 
2023-01-18T19:00:33.1563002Z   INPUT_DIR_NAMES: false
2023-01-18T19:00:33.1563266Z   INPUT_DIR_NAMES_MAX_DEPTH: 
2023-01-18T19:00:33.1563508Z   INPUT_JSON: false
2023-01-18T19:00:33.1563770Z   INPUT_HAS_CUSTOM_PATTERNS: true
2023-01-18T19:00:33.1564050Z   INPUT_JSON_RAW_FORMAT: false
2023-01-18T19:00:33.1564295Z ##[endgroup]
2023-01-18T19:00:33.2655221Z ##[group]changed-files
2023-01-18T19:00:33.2656093Z Resolving repository path: /__w/docker-images/docker-images/.
2023-01-18T19:00:33.2657859Z Retrieving changes between 5125d4ac8184a852129813c3ba7e538871f004b4 (nginx) → 6ae881deb8a5773601a1367c5cc4da1864a3693a (nginx)
2023-01-18T19:00:33.7476324Z ##[endgroup]

Anything else?

No response

Code of Conduct

jackton1 commented 1 year ago

@thearchitector I believe that's by design If you'll like the changes to be detected based on a prior commit that has been pushed you can exclude since_last_remote_commit: "true"

thearchitector commented 1 year ago

When you say by design, which do you mean is the correct behavior?

It is interesting because if you change the action to be this instead:

- id: changed-files
  uses: tj-actions/changed-files@v35
  with:
    since_last_remote_commit: "true"
    dir_names: "true"
    files_ignore: |
      .github/**/*

it does seem to find the files.

jackton1 commented 1 year ago

The term "if there is no last remote commit, there are no changes" might be a little confusing.

The design of since_last_remote_commit: "true"

Initial comparison

main (A last commit) -- PR (B Initial commit)

Diff A and B (i.e all changed files between A and B)

New commits pushed to the PR branch

PR (B last remote) -- PR (C-D-E-F pushed local commits)

Diff B and F (i.e all changed files between B and F)

NOTE: Any patterns you specify are matched if the pattern specified in the files list has been changed between B and F

You second comment

- id: changed-files
  uses: tj-actions/changed-files@v35
  with:
    since_last_remote_commit: "true"
    dir_names: "true"
    files_ignore: |
      .github/**/*

Uses the files_ignore input which in this case means detecting changes to other files

thearchitector commented 1 year ago

That is what I thought, but I also assumed that this would also be the case:

main (A last commit)
PR (no last remote, doesn't exist) -- PR (B-C-D pushed local commits, creates remote branch)

Diff would be A and D

jackton1 commented 1 year ago

That is what I thought, but I also assumed that this would also be the case:

main (A last commit)
PR (no last remote, doesn't exist) -- PR (B-C-D pushed local commits, creates remote branch)

Diff would be A and D

So do you mean you are seeing A compared to B as opposed to D ?

thearchitector commented 1 year ago

I am seeing C compared to D.

I've tested this thrice, but I will do it again because now I am doubting myself 😅

@jackton1 Tested again, and yes I am seeing C compared to D.

jackton1 commented 1 year ago

@thearchitector This should be resolved in the latest release.