ocibuild_vcs_git (ocibuild v0.10.4)
View SourceGit adapter for OCI annotation support.
This module implements the ocibuild_vcs behaviour for Git repositories.
It extracts source URL and revision information for OCI image annotations.
CI Environment Variables
For reliability in CI environments, this adapter checks environment variables before falling back to git commands:
Source URL (checked in order):
GITHUB_SERVER_URL+GITHUB_REPOSITORY(GitHub Actions)CI_PROJECT_URL(GitLab CI)BUILD_REPOSITORY_URI(Azure DevOps)git remote get-url origin(fallback)
Revision (checked in order):
GITHUB_SHA(GitHub Actions)CI_COMMIT_SHA(GitLab CI)BUILD_SOURCEVERSION(Azure DevOps)git rev-parse HEAD(fallback)
SSH to HTTPS Conversion
SSH URLs are automatically converted to HTTPS for public visibility:
git@github.com:org/repo.git→https://github.com/org/repossh://git@github.com/org/repo.git→https://github.com/org/repo
Configuration
The timeout for git commands can be configured via environment variable:
OCIBUILD_GIT_TIMEOUT- Timeout in milliseconds (default: 5000, max: 300000)
This is particularly useful for network operations like git remote get-url
when working with slow networks or remote repositories. Values above the
maximum are clamped to 300000ms (5 minutes).
Summary
Functions
Detect if Git VCS information is available.
Get the current commit SHA.
Get the source repository URL.
Functions
-spec detect(file:filename()) -> boolean().
Detect if Git VCS information is available.
Returns true if either:
- The path is within a Git repository (
.gitdirectory found), or - CI environment variables are present (GITHUB_*, CI_PROJECT_URL, BUILD_REPOSITORY_URI)
This allows VCS annotations to work in CI environments where the build runs in a different directory than the repository checkout.
-spec get_revision(file:filename()) -> {ok, binary()} | {error, term()}.
Get the current commit SHA.
Tries CI environment variables first, then falls back to git rev-parse HEAD.
-spec get_source_url(file:filename()) -> {ok, binary()} | {error, term()}.
Get the source repository URL.
Tries CI environment variables first, then falls back to git remote get-url origin.
SSH URLs are converted to HTTPS.