From 6e738cbd60d55196f190d73dd9b538b7810c005e Mon Sep 17 00:00:00 2001 From: David Driscoll Date: Sat, 11 Nov 2023 20:05:26 -0500 Subject: [PATCH] Attempt to fix gitversion info based on the branch being detached (#1645) --- .build/Build.CI.cs | 25 ++++++++++++++++++++----- .github/workflows/ci.yml | 4 ++++ 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/.build/Build.CI.cs b/.build/Build.CI.cs index aa0b49132..f70e29fae 100644 --- a/.build/Build.CI.cs +++ b/.build/Build.CI.cs @@ -63,11 +63,12 @@ public static RocketSurgeonGitHubActionsConfiguration CiIgnoreMiddleware(RocketS public static RocketSurgeonGitHubActionsConfiguration CiMiddleware(RocketSurgeonGitHubActionsConfiguration configuration) { - configuration - .ExcludeRepositoryConfigurationFiles() - .AddNugetPublish() - .Jobs.OfType() - .First(z => z.Name.Equals("build", StringComparison.OrdinalIgnoreCase)) + var job = configuration + .ExcludeRepositoryConfigurationFiles() + .AddNugetPublish() + .Jobs.OfType() + .First(z => z.Name.Equals("build", StringComparison.OrdinalIgnoreCase)); + job .UseDotNetSdks("6.0", "7.0") .AddNuGetCache() // .ConfigureForGitVersion() @@ -75,6 +76,20 @@ public static RocketSurgeonGitHubActionsConfiguration CiMiddleware(RocketSurgeon .PublishLogs() .FailFast = false; + job.Steps.Insert( + GetCheckStepIndex(job), new RunStep("Create branch for tag (gitversion)") + { + If = "(github.ref_type == 'tag')", + Run = "git checkout -b ci/${{ github.ref }}" + } + ); + return configuration; } + + private static int GetCheckStepIndex(RocketSurgeonsGithubActionsJob job) + { + var checkoutStep = job.Steps.OfType().SingleOrDefault(); + return checkoutStep is null ? 1 : job.Steps.IndexOf(checkoutStep); + } } diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e2764f951..f2c387a1a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -76,6 +76,10 @@ jobs: fail-fast: false runs-on: ubuntu-latest steps: + - name: Create branch for tag (gitversion) + if: (github.ref_type == 'tag') + run: | + git checkout -b ci/${{ github.ref }} - name: Checkout uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 with: