Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for disregarding the GitHub Actions env variables #795

Merged
merged 1 commit into from
Sep 9, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/NerdBank.GitVersioning/CloudBuildServices/GitHubActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,18 @@ internal class GitHubActions : ICloudBuild
public string BuildingTag => (BuildingRef?.StartsWith("refs/tags/") ?? false) ? BuildingRef : null;

/// <inheritdoc/>
public string GitCommitId => Environment.GetEnvironmentVariable("GITHUB_SHA");

private static string BuildingRef => Environment.GetEnvironmentVariable("GITHUB_REF");
public string GitCommitId => IgnoreGitHubRef ? null : Environment.GetEnvironmentVariable("GITHUB_SHA");

private static string BuildingRef => IgnoreGitHubRef ? null : Environment.GetEnvironmentVariable("GITHUB_REF");

/// <summary>
/// Gets a value indicating whether to ignore GitHub Actions environment variables that indicate where HEAD is.
/// </summary>
/// <remarks>
/// This is useful in a GitHub workflow where HEAD was moved by some prior Action, such that the environment variables are stale.
/// GitHub Actions does not allow these env vars to be changed mid-workflow, so in such cases NB.GV should just use HEAD.
/// </remarks>
private static bool IgnoreGitHubRef => string.Equals(Environment.GetEnvironmentVariable("IGNORE_GITHUB_REF"), "true", StringComparison.OrdinalIgnoreCase);

private static string EnvironmentFile => Environment.GetEnvironmentVariable("GITHUB_ENV");

Expand Down