Skip to content

Allow GIT info to be passed as (env?) variables #4

@skaravos

Description

@skaravos

When projects are compiled inside containerized CI/CD environments, the (docker) container that actually runs the configuration & compilation may not have access to git, or the project's .git repository information may not be present.
In these cases, even though the build container can't access the git info, the CI/CD runner should have access to all the git repository information before the job is dispatched to the build container.
So it would be nice to be able to forward this knowledge along to the submodule in the form of environment variables.

I'd need to test the idea more thoroughly, but I'm thinking something along the lines of:

# example gitlab-ci.yml build
build:
  stage: build
  image: SOME_DOCKER_IMAGE_WITHOUT_GIT
  tags:
    - docker
  script:
    # gitlab's CI_COMMIT_AUTHOR var is in the form "Name <email>"
    - commit_author_info=${CI_COMMIT_AUTHOR}
    - commit_user_name=${commit_author_info% <*}
    - commit_email=${commit_author_info#*<}; commit_email=${commit_email%*>}
    # export git info vars for use by the cmake version info target submodule
    - export GIT_UNCOMMITTED_CHANGES=0
    - export GIT_COMMIT_HASH=${CI_COMMIT_SHA}
    - export GIT_COMMIT_DATE=${CI_COMMIT_TIMESTAMP}
    - export GIT_AUTHOR_NAME=${commit_user_name}
    - export GIT_AUTHOR_EMAIL=${commit_email}
    # run configuration & build...
    # the VersionInfo submodule should use the env var values as a fallback
    - cmake -S . -B _build -DCMAKE_INSTALL_PREFIX=_install
    - cmake --build _build --target install

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions