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

When PR branch is unfortunately named, it can cause ambiguities in the git commands in GHA actions #713

Closed
jiridanek opened this issue Sep 26, 2024 · 1 comment · Fixed by #714
Assignees
Labels
kind/bug Something isn't working

Comments

@jiridanek
Copy link
Member

https://github.com/red-hat-data-services/notebooks/actions/runs/11052380337/job/30704337780?pr=361

It seems that when PR branch is unfortunately named, it can cause ambiguities in the git commands.

+ git fetch --no-tags origin pull/361/head:amd
From https://github.com/red-hat-data-services/notebooks
 * [new ref]         refs/pull/361/head -> amd
+ git fetch --no-tags origin +refs/heads/main:refs/remotes/origin/main
From https://github.com/red-hat-data-services/notebooks
 * [new branch]      main       -> origin/main
+ python3 ci/cached-builds/gen_gha_matrix_jobs.py --from-ref origin/main --to-ref amd
INFO:root:Skipping targets not modified in the PR
DEBUG:root:Getting list of changed files from git diff
fatal: ambiguous argument 'amd': both revision and filename
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
Traceback (most recent call last):
  File "/home/runner/work/notebooks/notebooks/ci/cached-builds/gen_gha_matrix_jobs.py", line 188, in <module>
    main()
  File "/home/runner/work/notebooks/notebooks/ci/cached-builds/gen_gha_matrix_jobs.py", line 172, in main
    changed_files = gha_pr_changed_files.list_changed_files(args.from_ref, args.to_ref)
  File "/home/runner/work/notebooks/notebooks/ci/cached-builds/gha_pr_changed_files.py", line 19, in list_changed_files
    files = subprocess.check_output(["git", "diff", "--name-only", from_ref, to_ref],
  File "/usr/lib/python3.10/subprocess.py", line 421, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
  File "/usr/lib/python3.10/subprocess.py", line 526, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['git', 'diff', '--name-only', 'origin/main', 'amd']' returned non-zero exit status [12](https://github.com/red-hat-data-services/notebooks/actions/runs/11052380337/job/30704337780?pr=361#step:3:13)8.
@jiridanek
Copy link
Member Author

Managed to reproduce for myself

$ mkdir amd
$ git diff --name-only origin/main amd
fatal: ambiguous argument 'amd': both revision and filename
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

The fix is, as the error says, to do

$ git diff --name-only origin/main amd --

openshift-merge-bot bot added a commit that referenced this issue Sep 26, 2024
Issue #713: fix(gha): don't crash when branch name matches file name in the repo
@github-project-automation github-project-automation bot moved this from 📋 Backlog to ✅Done in ODH IDE Planning Sep 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant