Skip to content

Commit 8b611d9

Browse files
andrewlockKevin Gosse
andauthored
Add verification step to create_draft_release to check SSI one-pipeline succeeded (#5865 -> v2) (#5879)
## Summary of changes Adds a stage to `create_draft_release` that verifies the gitlab stages all passed before starting the release ## Reason for change Before we merged #5818 we were testing the lib injection images prior to publishing, but that PR removed the checks (we're building/testing everything in the one pipeline instead) This PR, _explicitly_ checks that everything passed in GitLab before starting the release. ## Implementation details Pulls all the statuses for the commit, and makes sure the GitLab ones all have a passing status. Pros: - If/when the one-pipeline expands, we automatically check for success. - One pipeline can change (add/remove checks) and we automatically make sure they all passed before doing a release. Cons: - The one pipeline could break at some point without being a _real_ issue, which would block our releases. So added an override we can use in case of emergency. It should only be used when the reporting is "false" though, because the one pipeline creates and publishes the SSI artifacts. - We don't explicitly require any of the checks. This gives us flexibility (they can add or remove checks) but we won't know if we're actually checking them all (for example) - If the GitHub/GitLab link isn't working (due to issues either side), we might not be notified about failures ## Test coverage Tested locally to confirm the `VerifyReleaseReadiness` works as expected. e.g. run ```powershell .\tracer\build.ps1 VerifyReleaseReadiness -CommitSha 89bf7b3 -GITHUB_TOKEN <your token> ``` and it passes, but `ec735117ceaa963d5033f83ed80daaa88f970867` fails (for example) ## Other details Backport of #5865 --------- Co-authored-by: Kevin Gosse <[email protected]>
1 parent 2b17318 commit 8b611d9

File tree

3 files changed

+83
-0
lines changed

3 files changed

+83
-0
lines changed

.github/workflows/create_draft_release.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ on:
66
forced_commit_id:
77
description: 'Force using artifacts from specific commit? If provided, this will try and use the artifacts from the given commit, regardless of build status'
88
required: false
9+
ignore_gitlab_failures:
10+
description: "DANGER Force ignoring any issues with the GitLab artifacts or SSI. Don't use this unless you _really_ know what you're doing"
11+
required: false
912

1013
jobs:
1114
create_draft_release:
@@ -40,6 +43,12 @@ jobs:
4043
git config user.name "${{ github.actor }}"
4144
git config user.email "${{ github.actor }}@users.noreply.github.com"
4245
46+
- name: "Check GitLab status"
47+
if: ${{ !github.event.inputs.ignore_gitlab_failures }}
48+
run: ./tracer/build.sh VerifyReleaseReadiness
49+
env:
50+
CommitSha: "${{ steps.set_sha.outputs.sha }}"
51+
4352
- name: "Get current version"
4453
id: versions
4554
run: ./tracer/build.sh OutputCurrentVersionToGitHub

.nuke/build.schema.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,7 @@
464464
"UpdateVendoredCode",
465465
"UpdateVersion",
466466
"VerifyChangedFilesFromVersionBump",
467+
"VerifyReleaseReadiness",
467468
"ZipMonitoringHome",
468469
"ZipMonitoringHomeLinux",
469470
"ZipMonitoringHomeOsx",
@@ -677,6 +678,7 @@
677678
"UpdateVendoredCode",
678679
"UpdateVersion",
679680
"VerifyChangedFilesFromVersionBump",
681+
"VerifyReleaseReadiness",
680682
"ZipMonitoringHome",
681683
"ZipMonitoringHomeLinux",
682684
"ZipMonitoringHomeOsx",

tracer/build/_build/Build.GitHub.cs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using Nuke.Common;
1818
using Nuke.Common.IO;
1919
using Nuke.Common.Tooling;
20+
using Nuke.Common.Tools.Docker;
2021
using Nuke.Common.Tools.Git;
2122
using Octokit;
2223
using Octokit.GraphQL;
@@ -1103,6 +1104,77 @@ await client.Issue.Milestone.Update(
11031104
}
11041105
});
11051106

1107+
Target VerifyReleaseReadiness => _ => _
1108+
.Unlisted()
1109+
.Requires(() => GitHubToken)
1110+
.Requires(() => CommitSha)
1111+
.Executes(async () =>
1112+
{
1113+
Logger.Information("Verifying SSI artifact build succeeded for commit {Commit}...", CommitSha);
1114+
var client = GetGitHubClient();
1115+
var statuses = await client.Repository.Status.GetAll(
1116+
owner: GitHubRepositoryOwner,
1117+
name: GitHubRepositoryName,
1118+
reference: CommitSha);
1119+
1120+
// find all the gitlab-related SSI statuses, they _all_ need to have passed
1121+
// (apart from the serverless one, we'll ignore that for now)
1122+
// This includes the _full_ list, so we just want to check that we have a success for each unique job
1123+
var ssiStatuses = statuses
1124+
.Where(x => x.Context.StartsWith("dd-gitlab/") && x.Context != "dd-gitlab/benchmark-serverless")
1125+
.ToLookup(x => x.Context, x => x);
1126+
1127+
if (ssiStatuses.Count == 0)
1128+
{
1129+
throw new Exception("No GitLab builds for SSI artifacts found. Please check the commit and try again");
1130+
}
1131+
1132+
var failedSsi = ssiStatuses
1133+
.Where(x => !x.Any(status => status.State == CommitState.Success))
1134+
.ToList();
1135+
1136+
if (failedSsi.Any())
1137+
{
1138+
Logger.Warning("The following gitlab jobs did not complete successfully. Please check the builds for details about why");
1139+
foreach (var failed in failedSsi)
1140+
{
1141+
var build = failed.OrderBy(c => c.State.Value).First();
1142+
Logger.Warning("- {Job} ({Status}) {Link}", failed.Key, build.State, build.TargetUrl);
1143+
}
1144+
1145+
throw new Exception("Some gitlab jobs did not build/test successfully. Please check the builds for details about why.");
1146+
}
1147+
1148+
var stages = string.Join(", ", ssiStatuses.Select(x => x.Key));
1149+
Logger.Information("All gitlab build stages ({Stages}) completed successfully", stages);
1150+
1151+
// assert that the docker image for the commit is present
1152+
var image = $"ghcr.io/datadog/dd-trace-dotnet/dd-lib-dotnet-init:{CommitSha}";
1153+
VerifyDockerImageExists(image);
1154+
1155+
if(new Version(Version).Major < 3)
1156+
{
1157+
image = $"ghcr.io/datadog/dd-trace-dotnet/dd-lib-dotnet:{CommitSha}-musl";
1158+
VerifyDockerImageExists(image);
1159+
}
1160+
1161+
static void VerifyDockerImageExists(string image)
1162+
{
1163+
try
1164+
{
1165+
Logger.Information("Checking for presence of SSI image '{Image}'", image);
1166+
DockerTasks.DockerManifest(
1167+
s => s.SetCommand($"inspect")
1168+
.SetProcessArgumentConfigurator(c => c.Add(image)));
1169+
Logger.Information("SSI image '{Image}' exists", image);
1170+
}
1171+
catch (Exception ex)
1172+
{
1173+
throw new Exception($"Error verifying SSI artifacts: '{image}' could not be found. Ensure GitLab has successfully built and pushed the image", ex);
1174+
}
1175+
}
1176+
});
1177+
11061178
async Task ReplaceCommentInPullRequest(int prNumber, string title, string markdown)
11071179
{
11081180
try

0 commit comments

Comments
 (0)