apiops icon indicating copy to clipboard operation
apiops copied to clipboard

[BUG] Github actions - publishing with specific commit fails with "ambiguous argument"

Open audunsolemdal opened this issue 2 years ago • 10 comments

Release version

4.0.3

Describe the bug

Publishing all artifacts works fine, while fetching the latest commit for some reason does not

I also tried debugging with

      - shell: bash
        run: |
          (git -C ${{ GITHUB.WORKSPACE }}/${{ inputs.API_MANAGEMENT_SERVICE_OUTPUT_FOLDER_PATH }} diff-tree --no-commit-id --name-status ${{ inputs.COMMIT_ID }}^ ${{ inputs.COMMIT_ID }})

which gives the same error as below. I find this odd as the logs of the checkout action clearly states the same COMMIT id as the one referenced by ${{ inputs.COMMIT_ID }}.

/usr/bin/git log -1 --format='%H' '925b86b60fa010423ec93708ce2d40ae99b01dad

Expected behavior

Publishing with specific commit works fine

Actual behavior

System.InvalidOperationException: Failed to get files for commit 925b86b60fa010423ec93708ce2d40ae99b01dad in directory /home/runner/work/wl-testteam1/wl-testteam1/apimartifacts. Error message is 'fatal: ambiguous argument '925b86b60fa010423ec93708ce2d40ae99b01dad^': unknown revision or path not in the working tree. Use '--' to separate paths from revisions, like this:

Reproduction Steps

      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0

      - name: Run publisher without Config Yaml but with Commit ID
        if: ( inputs.CONFIGURATION_YAML_PATH == '' &&  inputs.COMMIT_ID != '')
        env:
          COMMIT_ID: ${{ inputs.COMMIT_ID }}
          #censored..
        run: |
          Set-StrictMode -Version Latest
          $ErrorActionPreference = "Stop"
          $VerbosePreference = "Continue"
          $InformationPreference = "Continue"

          Write-Information "Downloading publisher..."
          $publisherFileName = "${{ runner.os }}" -like "*win*" ? "publisher.win-x64.exe" : "publisher.linux-x64.exe"
          $uri = "https://github.com/Azure/apiops/releases/download/${{ env.apiops_release_version }}/$publisherFileName"
          $destinationFilePath = Join-Path "${{ runner.temp }}" "publisher.exe"
          Invoke-WebRequest -Uri "$uri" -OutFile "$destinationFilePath"

          if ("${{ runner.os }}" -like "*linux*")
          {
            Write-Information "Setting file permissions..."
            & chmod +x "$destinationFilePath"
            if ($LASTEXITCODE -ne 0) { throw "Setting file permissions failed."}
          }

          & "$destinationFilePath"              
          if ($LASTEXITCODE -ne 0) { throw "Running publisher failed."}

          Write-Information "Execution complete."
        shell: pwsh

audunsolemdal avatar Feb 17 '23 15:02 audunsolemdal

@audunsolemdal is the issue still persisting?

waelkdouh avatar Mar 17 '23 18:03 waelkdouh

Yes, still an issue. I am running on runs-on: ubuntu-latest if it makes a difference.

audunsolemdal avatar Mar 18 '23 11:03 audunsolemdal

Agent shouldn't make a difference. Will investigate and get back to you.

waelkdouh avatar Mar 18 '23 11:03 waelkdouh

@audunsolemdal - I just ran into this issue on a completely different project. This solution helped me.

Can you try unchecking the Shallow fetch box in your pipeline settings as per these instructions?

guythetechie avatar Mar 30 '23 21:03 guythetechie

Well I am running Github actions and not Azure Pipelines.

      - uses: actions/checkout@v3
        with:
          fetch-depth: 0

But I believe this should be set correct already

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](https://help.github.com/en/articles/events-that-trigger-workflows) to learn which commit $GITHUB_SHA points to for different events

I believe I have tried with fetch-depth: 2 for good measure also with no difference in the result

audunsolemdal avatar Mar 31 '23 07:03 audunsolemdal

You're right, it is already set up correctly for GitHub. I did not pay close enough attention.

I'm not sure why the Git command is failing. Here are a couple of suggestions:

  • Test with a simpler command that achieves the same result. The example below uses git diff --name-status instead of git diff-tree --no-commit-id --name-status.
      - shell: bash
        run: |         
          git -C ${{ GITHUB.WORKSPACE }}/${{ inputs.API_MANAGEMENT_SERVICE_OUTPUT_FOLDER_PATH }} diff --name-status ${{ inputs.COMMIT_ID }}^ ${{ inputs.COMMIT_ID }}
  • Test with explicit values. The value for an_explicit_commit_id can be any valid commit ID in your branch (other than your first commit, I suppose). Doesn't have to be the last one.
      - shell: bash
        run: | 
          cd ${{ GITHUB.WORKSPACE }}
          git diff --name-status an_explicit_commit_id^ an_explicit_commit_id

guythetechie avatar Mar 31 '23 13:03 guythetechie

@guythetechie So I just tested various variants All of the variants you suggested (including the original I posted) work as long as it is not the latest commit. Literally every other commit and all the git commands work just fine.

audunsolemdal avatar Apr 05 '23 10:04 audunsolemdal

@waelkdouh Hi, we are experiencing this same issue. We are running the publisher tool in a Jenkins pipeline and it fails with:
Error message is 'fatal: ambiguous argument '<COMMIT_ID>^': unknown revision or path not in the working tree. In our specific use case, the Commit ID must always be the latest (HEAD) in the repo and we are correctly injecting that commit ID to the publisher via env var...

R3DRUN3 avatar Apr 29 '24 13:04 R3DRUN3

@guythetechie any thoughts on this?

waelkdouh avatar Apr 29 '24 14:04 waelkdouh

As discussed above, can you add a bash step in your Jenkins pipeline to do git diff --name-status your_commit_id^ your_commitId? I'm not familiar with Jenkins, but it should be pretty straightforward.

guythetechie avatar Apr 30 '24 02:04 guythetechie