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]: workflowのgit logコマンド部分でエラーになる #3

Closed
ee090186 opened this issue Mar 19, 2023 · 0 comments
Closed
Assignees
Labels
bug Something isn't working

Comments

@ee090186
Copy link
Owner

ee090186 commented Mar 19, 2023

What happened?

ローカル環境では成功する以下のgit logコマンドが、Github Actions内で実行するとエラーになる

git log --all --pretty=oneline --abbrev-commit --boundary --left-right main...test >> pstest.txt


Relevant log output

Run git log --all --pretty=oneline --abbrev-commit --boundary --left-right main...test >> pstest.txt
  git log --all --pretty=oneline --abbrev-commit --boundary --left-right main...test >> pstest.txt
  shell: C:\Program Files\PowerShell\7\pwsh.EXE -command ". '{0}'"
##[debug]C:\Program Files\PowerShell\7\pwsh.EXE -command ". 'D:\a\_temp\d7231df4-e480-472a-9f67-420c04c007d6.ps1'"
fatal: ambiguous argument 'main...test': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
Error: Process completed with exit code 1.

git log -5コマンドにすると、コマンドは実行できるが、このGitHubActionsTestリポジトリには存在しない?shaが表示された

Run # git log --all --pretty=oneline --abbrev-commit --boundary --left-right main...test -- >> pstest.txt
  # git log --all --pretty=oneline --abbrev-commit --boundary --left-right main...test -- >> pstest.txt
  git log -5
  shell: C:\Program Files\PowerShell\7\pwsh.EXE -command ". '{0}'"
commit c0e6be34e53513fcc008[2](https://github.com/ee090186/GitHubActionsTest/actions/runs/4460151170/jobs/7833106614#step:4:2)f9d5d501d844fa60ea5
Author: ee090186 <7070400[3](https://github.com/ee090186/GitHubActionsTest/actions/runs/4460151170/jobs/7833106614#step:4:3)[email protected]>
Date:   Sun Mar 19 10:11:12 2023 +0000

    Merge 7b3d1d99[4](https://github.com/ee090186/GitHubActionsTest/actions/runs/4460151170/jobs/7833106614#step:4:4)082[5](https://github.com/ee090186/GitHubActionsTest/actions/runs/4460151170/jobs/7833106614#step:4:6)9055fa8bf8f41c44224e98a9435 into 7817[6](https://github.com/ee090186/GitHubActionsTest/actions/runs/4460151170/jobs/7833106614#step:4:7)81bae6262b6ce6f44aeed302ceba[7](https://github.com/ee090186/GitHubActionsTest/actions/runs/4460151170/jobs/7833106614#step:4:8)[9](https://github.com/ee090186/GitHubActionsTest/actions/runs/4460151170/jobs/7833106614#step:4:10)3d90e

git log testのコマンド実行時
→このコマンドもエラーのため、git logコマンド自体よりもその前のgit設定などの部分に問題あるかも

Run # git log --all --pretty=oneline --abbrev-commit --boundary --left-right main...test -- >> pstest.txt
  # git log --all --pretty=oneline --abbrev-commit --boundary --left-right main...test -- >> pstest.txt
  git log test
  shell: C:\Program Files\PowerShell\[7](https://github.com/ee090186/GitHubActionsTest/actions/runs/4460168081/jobs/7833133731?pr=2#step:4:8)\pwsh.EXE -command ". '{0}'"
  
fatal: ambiguous argument 'test': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

以下のgit configステップをコメントアウトしてみてもエラー変わらず
-> この設定ステップには問題なし

- name: git setting
  run: |
    git config --global user.name ${GITHUB_ACTOR}
    git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com" 
Run # git log --all --pretty=oneline --abbrev-commit --boundary --left-right main...test -- >> pstest.txt
  # git log --all --pretty=oneline --abbrev-commit --boundary --left-right main...test -- >> pstest.txt
  git log test
  shell: C:\Program Files\PowerShell\[7](https://github.com/ee090186/GitHubActionsTest/actions/runs/4460240668/jobs/7833246793#step:3:8)\pwsh.EXE -command ". '{0}'"
  
fatal: ambiguous argument 'test': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'


Cause

  1. fetch-depth: 0を指定していなかったため
    デフォルトだと一つのコミットしか参照できないよう

actions/checkout@v3

Only a single commit is fetched by default, for the ref/SHA that triggered the workflow.
Set fetch-depth: 0 to fetch all history for all branches and tags.
Refer here to learn which commit $GITHUB_SHA points to for different events.


  1. actions/checkoutでは、ランナーはGithubからリポジトリをクローンしてきている状態のため、リモート追跡ブランチ(origin/{ブランチ名})しかないから?


Solution

  1. 以下のように、fetch-depth: 0を指定する
    steps:
      - name: checkout
        uses: actions/checkout@main
        with:
          fetch-depth: 0
  1. ブランチ名指定部分の頭にorigin/を記載し、リモート追跡ブランチを指定する
git log --pretty=oneline --abbrev-commit --boundary --left-right origin/${{ env.BASE_BRANCH_NAME }}...origin/${{ env.HEAD_BRANCH_NAME }}

実行結果

Run #$git_log = 
  #$git_log = 
  git log --pretty=oneline --abbrev-commit --boundary --left-right origin/main...origin/test
  #"GIT_LOG=$git_log" >> $env:GITHUB_OUTPUT
  shell: C:\Program Files\PowerShell\7\pwsh.EXE -command ". '{0}'"
  env:
    HEAD_BRANCH_NAME: test
    BASE_BRANCH_NAME: main
< f8a8939 up: git logコマンドのデバッグ用
< 7096a[2](https://github.com/ee090186/GitHubActionsTest/actions/runs/4479435026/jobs/7873378927#step:5:2)c up: git logコマンドのデバッグ用
< c00adef up: git logコマンド結果の変数格納部分コメントアウト解除
< 11a[3](https://github.com/ee090186/GitHubActionsTest/actions/runs/4479435026/jobs/7873378927#step:5:3)7f8 up: git logコマンドのデバッグ用
< c7d7323 up: git logコマンドのデバッグ用
< 6260d[5](https://github.com/ee090186/GitHubActionsTest/actions/runs/4479435026/jobs/7873378927#step:5:5)3 up: git logコマンドのデバッグ用

...


Refelence

以下のIssue・プルリクエストでは、同様なエラーが起き、v1を使用する必要があると書いてあるように見えたが。。。acthons/checkout@mainでも動作した

@ee090186 ee090186 added the bug Something isn't working label Mar 19, 2023
@ee090186 ee090186 self-assigned this Mar 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant