apiops
apiops copied to clipboard
[BUG] Github actions - publishing with specific commit fails with "ambiguous argument"
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 is the issue still persisting?
Yes, still an issue. I am running on runs-on: ubuntu-latest if it makes a difference.
Agent shouldn't make a difference. Will investigate and get back to you.
@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?
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
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-statusinstead ofgit 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_idcan 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 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.
@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...
@guythetechie any thoughts on this?
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.