Skip to content
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

[BUG] Unexpected result #412

Closed
Xat59 opened this issue Mar 2, 2022 · 2 comments
Closed

[BUG] Unexpected result #412

Xat59 opened this issue Mar 2, 2022 · 2 comments

Comments

@Xat59
Copy link

Xat59 commented Mar 2, 2022

Hello guys,

I would like to list all files that have changed (by changed I mean removed, edited, added) from my PR.

When using this workflow, I get unexpected result :

---
name: Get all changed files from this PR

on:
  push:
    branches: 'bau/*'
  pull_request:
    branches: 'bau/*'

jobs:
  changed-files:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        with:
          fetch-depth: 0
      - name: changed-files
        id: changed-files
        uses: tj-actions/changed-files@v17.2

This returns only 1 file while I have 3 modified files in my PR... :

  Resolving repository path...
  Retrieving changes between 95635589e714fa8c58d7e0206a966ff8fd311216 (bau/chg0001) → 2c0046c6f49aceda59bc9cff304140445da4bb72 (bau/chg0001)
  Getting diff...
  Added files: 
  Copied files: 
  Deleted files: 
  Modified files: .github/workflows/terragrunt.yml
  Renamed files: 
  Type Changed files: 
  Unmerged files: 
  Unknown files: 
  All changed and modified files: .github/workflows/terragrunt.yml
  All changed files: .github/workflows/terragrunt.yml
  All modified files: .github/workflows/terragrunt.yml

Note 95635589e714fa8c58d7e0206a966ff8fd311216 is the second to last SHA in the PR, and 2c0046c6f49aceda59bc9cff304140445da4bb72 is the last SHA in the PR.

So yeah of course between these 2 commits there are only 1 file, but that is not at all what I need.

I need to retrieve all files from the PR.

@jackton1
Copy link
Member

jackton1 commented Mar 2, 2022

@Xat59 That's because your action was triggered by a push event

on:
  push:                           # <- Based on this line
    branches: 'bau/*'     # <- Based on this line
  pull_request:
    branches: 'bau/*'    # <- This should point to your default branch (main, master) and not the pull request branch
Retrieving changes between 95635589e714fa8c58d7e0206a966ff8fd311216 (bau/chg0001) → 2c0046c6f49aceda59bc9cff304140445da4bb72 (bau/chg0001)

This line above says you pushed a change to your Pull Request and the push event triggered the action on your branch which wouldn't show you changes that have been made in your PR but only changes since the previous commit.

Solution

Change the trigger above to

on:
  pull_request:
    branches: 'main'

Remove the push entirely if you only want to list pull request files that have changed.

@jackton1 jackton1 closed this as completed Mar 2, 2022
@Xat59
Copy link
Author

Xat59 commented Mar 2, 2022

@jackton1 I've other jobs that must be ran after retrieving the list of changed files.

I've did what you said :

---
name: Get all changed files from this PR

on:
  pull_request:
    branches: ['main',’master']

jobs:
  changed-files:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        with:
          fetch-depth: 0
      - name: changed-files
        id: changed-files
        uses: tj-actions/changed-files@v17.2

It works fine now, thanks a lot.
Regards,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants