dotnet / docfx

Static site generator for .NET API documentation.
https://dotnet.github.io/docfx/
MIT License
4.07k stars 865 forks source link

[Bug] DocFx generates incorrect links in "View Source" when building from a tag in Azure DevOps git repo #10161

Open Maarty opened 2 months ago

Maarty commented 2 months ago

Our builds are usually from a git tag in Azure DevOps, and in this case, the "View Source" button in DocFx is not working.

The link would work if we built from a branch, but not from a tag.

Example of generated link: https://dev.azure.com/organizationName/projectname/_git/RepoName?path=Src/path/subpath/file.cs&version=GB7.104.0&line=8

7.104.0 is the name of our git tag.

Correct link would end with GT7.104.0 not GB7.104.0 as GB works only for branches, not tags.

To Reproduce Steps to reproduce the behavior:

  1. Run CLI dotnet docfx on a git tag version of Azure DevOps repo.

Expected behavior The link should end with GT{tag name} instead of GB{tag name} for builds from a git tag.

Context:

VaclavElias commented 2 months ago

This might be similar to my issue. This checkouts from 2 repositories https://github.com/stride3d/stride-docs/blob/staging/.github/workflows/stride-docs-staging-azure.yml

The documentation manual, tutorials.. honor the settings from the docfx.json, so when I click Edit this page, it takes you to the correct repo and branch.

"_gitContribute": {
        "repo": "https://github.com/stride3d/stride-docs",
        "branch": "master"
      }

But when I want to see the source code for the API, for example here https://stride-doc-staging.azurewebsites.net/latest/en/api/Stride.CompilationMode.html

The View Source links takes you to

https://github.com/stride3d/stride/blob/staging/sources/engine/Stride/CompilationMode.cs/#L8 which doesn't exist.

The branch shouldn't be staging but master.

The GitHub Action (link above) has this:

    # Checkout the Stride repository from the default branch
    - name: Checkout Stride (note the LFS)
      uses: actions/checkout@v4
      with:
        repository: stride3d/stride
        token: ${{ secrets.GITHUB_TOKEN }}
        path: stride
        lfs: true
        ref: master

It seems like that the current branch staging is somehow leaking where it shouldn't 🤣.

Tested on version 2.77.0.

filzrev commented 2 months ago

The link should end with GT{tag name} instead of GB{tag name} for builds from a git tag.

Source URLs are generated by following files.

But currently it seems GT{tag name} link is not supported. If there is a way to get current checkouted branch is tag or not. (e.g. Build.SourceBranch environment variable) It can add support for GT type links.


@VaclavElias

But when I want to see the source code for the API, for example here https://stride-doc-staging.azurewebsites.net/latest/en/api/Stride.CompilationMode.html

I though staging branch name seems be taken from GITHUB_REF_NAME environment variable. `https://github.com/dotnet/docfx/blob/main/src/Docfx.Common/Git/GitUtility.cs#L22

It might be resolved by clearing this environment variable. (I thought environment lookup logics are added for perf optimization. It might be able to remove these logics. Because currently external git command call is not exists)

The documentation manual, tutorials.. honor the settings from the docfx.json, so when I click Edit this page, it takes you to the correct repo and branch.

It seems currently _gitContribute settings is not applied to view source link. https://github.com/dotnet/docfx/blob/main/templates/common/common.js#L33-L39

VaclavElias commented 2 months ago

Thanks @filzrev, I will give it a go regarding GITHUB_REF_NAME and report back.