tombreit / mkdocs-git-latest-changes-plugin

MkDocs plugin that allows you to display a list of recently modified pages from the Git log
https://tombreit.github.io/mkdocs-git-latest-changes-plugin/
MIT License
1 stars 2 forks source link

TypeError on gitlab instance #15

Open maba2402 opened 3 weeks ago

maba2402 commented 3 weeks ago

The plugin is not working if executed by a gitlab runner. It crashes with the following exception:

ERROR - An exception of type TypeError occurred. Arguments: ("HEAD is a detached symbolic reference as it points to '26a5edb2cdae0a1b02f701cd6b2bc6cf5ef0cbff'",)

The problem can be traced back to the method get_recent_changes.

def get_recent_changes(
    *, repo_url: str, repo_vendor: str, limit_to_docs_dir: str, history_limit: int
) -> str:
    try:
        repo = Repo()
        branch = repo.active_branch
        git = repo.git

The line branch = repo.active_branch raises the exception.

The problem is that in my case gitlab does not checkout a branch but works rather on a defined commit.

$ git branch
(HEAD detached at 26a5edb)

$ git rev-parse --abbrev-ref HEAD
HEAD

This problem has been discussed here #633

tombreit commented 3 weeks ago

Hi @maba2402 ,

could you please post your .gitlab-ci.yml?

tombreit commented 3 weeks ago

Without knowing your configuration, I can only speculate:

Example (pseudocode):

# .gitlab-ci.yml

variables:
  GIT_DEPTH: 0
maba2402 commented 2 weeks ago

I looked a bit more into the details of my .gitlab-ci.yml and tried your proposal. Unfortunately, the situation is still the same. Here are the details.

workflow:
  rules:
    - if: $CI_MERGE_REQUEST_IID
    - if: $CI_COMMIT_TAG
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH

variables:
    GIT_DEPTH: 0

build-mkdocs:
  stage: test
  script:
    - poetry run mkdocs build ${CI_MERGE_REQUEST_IID+--no-directory-urls}
  artifacts:
    expire_in: 3h
    paths:
      - site/
  tags:
    - DOCKER
tombreit commented 2 weeks ago

Perhaps you could force a git pull of your branch?:

# .gitlab-ci.yml

variables:
  GIT_DEPTH: 0

build-mkdocs:
  stage: test
  script:
    - git pull origin <insertyourbranch>
    - git switch <insertyourbranch>
    - git pull
    - poetry run mkdocs build ${CI_MERGE_REQUEST_IID+--no-directory-urls}
maba2402 commented 1 week ago

Thanks a lot. That works.

maba2402 commented 1 week ago

Unfortunately, the proposed solution does not work with a Merge-Request based approach. I need to further investigate this issue.

tombreit commented 1 week ago

It would be nice if you could detail the steps that lead to this error here.