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

create-pull-request fails with uncommitted changes that aren't in add-paths #1095

Closed
agrare opened this issue Mar 17, 2022 · 6 comments · Fixed by #1099
Closed

create-pull-request fails with uncommitted changes that aren't in add-paths #1095

agrare opened this issue Mar 17, 2022 · 6 comments · Fixed by #1099

Comments

@agrare
Copy link

agrare commented Mar 17, 2022

Subject of the issue

While testing that running the workflow with no changes does not create a pull request I noticed a failure caused by uncommitted changes which were not in the add-paths list.

I have only a single file in the add-paths list (db/fixtures/aws_instance_types.yml)

ruby/setup-ruby will install gems by default into the vendor/bundle directory in the root of the repository.

Create or update the pull request branch
  /usr/bin/git symbolic-ref HEAD --short
  run_aws_extract_instance_types_weekly
  Working base is branch 'run_aws_extract_instance_types_weekly'
  /usr/bin/git checkout --progress -B a7a8b355-0263-43e8-8559-9fdb32371f80 HEAD --
  Switched to a new branch 'a7a8b355-0263-43e8-8559-9fdb32371f80'
  /usr/bin/git status --porcelain -unormal
  ?? vendor/
  Uncommitted changes found. Adding a commit.
  /usr/bin/git add db/fixtures/aws_instance_types.yml
  /usr/bin/git -c author.name=agrare -c [email protected] -c committer.name=GitHub -c [email protected] commit -m Update AWS instance_types
  On branch a7a8b355-0263-43e8-8559-9fdb32371f80
  Untracked files:
    (use "git add <file>..." to include in what will be committed)
  	vendor/
  
  nothing added to commit but untracked files present (use "git add" to track)
  Error: The process '/usr/bin/git' failed with exit code 1

While we should add vendor/bundle to our .gitignore I think this could be a more general issue, I'd expect any files outside of the scope of what is in add-paths to be ignored.

Steps to reproduce

Create a workflow which modifies a file outside of add-paths

Example failure: https://github.com/agrare/manageiq-providers-amazon/runs/5586172800
Example workflow: https://github.com/agrare/manageiq-providers-amazon/blob/run_aws_extract_instance_types_weekly/.github/workflows/instance_types.yaml

@peter-evans
Copy link
Owner

Hi @agrare

Currently there is a minor limitation to using add-paths which is that if there are any changes at all, regardless of path, at least one of add-paths paths must resolve to a file with changes to commit.

I mentioned this in the docs here: https://github.com/peter-evans/create-pull-request#add-specific-paths

Each path must resolve to a least one new or modified file to add

However, I understand that this not what you would expect to happen, and I'm going to see if I can fix it. I think I've identified a way to handle this, so I just need a little time to test it.

In the meantime, using .gitignore would be a good option. Alternatively, you could remove the untracked files in vendor/ with the following step, before executing create-pull-request.

      - run: git clean -f vendor

@peter-evans peter-evans mentioned this issue Mar 22, 2022
Merged
@peter-evans
Copy link
Owner

Hi @agrare

I think I've fixed this issue. If you would be willing to test it, that would be really helpful. I'm releasing it as v4, a new major version, because of a minor breaking change that I made. Currently it's in a feature branch called v4.

      - name: Create Pull Request
        uses: peter-evans/create-pull-request@v4

There are some notes about the v4 release here: https://github.com/peter-evans/create-pull-request/blob/v4/docs/updating.md#updating-from-v3-to-v4

@agrare
Copy link
Author

agrare commented Mar 22, 2022

@peter-evans your change worked perfectly, I removed vendor/bundle from .gitignore and re-ran with no changes and the action succeeds and does not create a pull-request when there are no changes, thank you!


Create or update the pull request branch
  /usr/bin/git symbolic-ref HEAD --short
  run_aws_extract_instance_types_weekly
  Working base is branch 'run_aws_extract_instance_types_weekly'
  /usr/bin/git checkout --progress -B ccf635ce-3ca2-4ed9-857d-15da36fc6d20 HEAD --
  Switched to a new branch 'ccf635ce-3ca2-4ed9-857d-15da36fc6d20'
  /usr/bin/git status --porcelain -unormal -- db/fixtures/aws_instance_types.yml
  /usr/bin/git diff --quiet -- db/fixtures/aws_instance_types.yml
  /usr/bin/git diff --quiet --staged -- db/fixtures/aws_instance_types.yml
  /usr/bin/git reset --hard
  HEAD is now at e3240bd Test not creating a PR
  /usr/bin/git clean -f -d
  Removing vendor/bundle/ruby/2.7.0/bin/
  Removing vendor/bundle/ruby/2.7.0/build_info/
  Resetting working base branch 'run_aws_extract_instance_types_weekly'
  /usr/bin/git checkout --progress run_aws_extract_instance_types_weekly --
  Switched to branch 'run_aws_extract_instance_types_weekly'
  Your branch is up to date with 'origin/run_aws_extract_instance_types_weekly'.
  /usr/bin/git reset --hard origin/run_aws_extract_instance_types_weekly
  HEAD is now at e3240bd Test not creating a PR
  /usr/bin/git -c protocol.version=2 fetch --no-tags --progress --no-recurse-submodules --unshallow origin create-pull-request/patch:refs/remotes/origin/create-pull-request/patch
  fatal: couldn't find remote ref create-pull-request/patch
  Pull request branch 'create-pull-request/patch' does not exist yet.
  /usr/bin/git checkout --progress -B create-pull-request/patch ccf635ce-3ca2-4ed9-857d-15da36fc6d20 --
  Switched to a new branch 'create-pull-request/patch'
  /usr/bin/git rev-list --right-only --count run_aws_extract_instance_types_weekly...create-pull-request/patch
  0
  Branch 'create-pull-request/patch' is not ahead of base 'run_aws_extract_instance_types_weekly' and will not be created

@peter-evans
Copy link
Owner

Great. Thank you for testing it!

@peter-evans
Copy link
Owner

Released as v4.0.0 / v4.

Thank you for raising this issue! It provoked me to look more closely at the logic and make this improvement.

@agrare
Copy link
Author

agrare commented Mar 23, 2022

Thanks for the quick fix @peter-evans !

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

Successfully merging a pull request may close this issue.

2 participants