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 verification step to create_draft_release to check SSI one-pipeline succeeded #5865

Merged
merged 2 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions .github/workflows/create_draft_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ on:
forced_commit_id:
description: 'Force using artifacts from specific commit? If provided, this will try and use the artifacts from the given commit, regardless of build status'
required: false
ignore_gitlab_failures:
description: "DANGER Force ignoring any issues with the GitLab artifacts or SSI. Don't use this unless you _really_ know what you're doing"
required: false

jobs:
create_draft_release:
Expand Down Expand Up @@ -40,6 +43,12 @@ jobs:
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor }}@users.noreply.github.com"

- name: "Check GitLab status"
if: ${{ !github.event.inputs.ignore_gitlab_failures }}
run: ./tracer/build.sh VerifyReleaseReadiness
env:
CommitSha: "${{ steps.set_sha.outputs.sha }}"

- name: "Get current version"
id: versions
run: ./tracer/build.sh OutputCurrentVersionToGitHub
Expand Down
2 changes: 2 additions & 0 deletions .nuke/build.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@
"UpdateVendoredCode",
"UpdateVersion",
"VerifyChangedFilesFromVersionBump",
"VerifyReleaseReadiness",
"ZipMonitoringHome",
"ZipMonitoringHomeLinux",
"ZipMonitoringHomeOsx",
Expand Down Expand Up @@ -691,6 +692,7 @@
"UpdateVendoredCode",
"UpdateVersion",
"VerifyChangedFilesFromVersionBump",
"VerifyReleaseReadiness",
"ZipMonitoringHome",
"ZipMonitoringHomeLinux",
"ZipMonitoringHomeOsx",
Expand Down
73 changes: 73 additions & 0 deletions tracer/build/_build/Build.GitHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using Nuke.Common;
using Nuke.Common.IO;
using Nuke.Common.Tooling;
using Nuke.Common.Tools.Docker;
using Nuke.Common.Tools.Git;
using Octokit;
using Octokit.GraphQL;
Expand Down Expand Up @@ -1103,6 +1104,78 @@ await client.Issue.Milestone.Update(
}
});

Target VerifyReleaseReadiness => _ => _
.Unlisted()
.Requires(() => GitHubToken)
.Requires(() => CommitSha)
.Executes(async () =>
{
Logger.Information("Verifying SSI artifact build succeeded for commit {Commit}...", CommitSha);
var client = GetGitHubClient();
var statuses = await client.Repository.Status.GetAll(
owner: GitHubRepositoryOwner,
name: GitHubRepositoryName,
reference: CommitSha);

// find all the gitlab-related SSI statuses, they _all_ need to have passed
// (apart from the serverless one, we'll ignore that for now)
// This includes the _full_ list, so we just want to check that we have a success for each unique job
var ssiStatuses = statuses
.Where(x => x.Context.StartsWith("dd-gitlab/") && x.Context != "dd-gitlab/benchmark-serverless")
.ToLookup(x => x.Context, x => x);

// System.Diagnostics.Debugger.Launch();
if (ssiStatuses.Count == 0)
{
throw new Exception("No GitLab builds for SSI artifacts found. Please check the commit and try again");
}

var failedSsi = ssiStatuses
.Where(x => !x.Any(status => status.State == CommitState.Success))
.ToList();

if (failedSsi.Any())
{
Logger.Warning("The following gitlab jobs did not complete successfully. Please check the builds for details about why");
foreach (var failed in failedSsi)
{
var build = failed.OrderBy(c => c.State.Value).First();
Logger.Warning("- {Job} ({Status}) {Link}", failed.Key, build.State, build.TargetUrl);
}

throw new Exception("Some gitlab jobs did not build/test successfully. Please check the builds for details about why.");
}

var stages = string.Join(", ", ssiStatuses.Select(x => x.Key));
Logger.Information("All gitlab build stages ({Stages}) completed successfully", stages);

// assert that the docker image for the commit is present
var image = $"ghcr.io/datadog/dd-trace-dotnet/dd-lib-dotnet-init:{CommitSha}";
VerifyDockerImageExists(image);

if(new Version(Version).Major < 3)
{
image = $"ghcr.io/datadog/dd-trace-dotnet/dd-lib-dotnet:{CommitSha}-musl";
VerifyDockerImageExists(image);
}

static void VerifyDockerImageExists(string image)
{
try
{
Logger.Information("Checking for presence of SSI image '{Image}'", image);
DockerTasks.DockerManifest(
s => s.SetCommand($"inspect")
.SetProcessArgumentConfigurator(c => c.Add(image)));
Logger.Information("SSI image '{Image}' exists", image);
}
catch (Exception ex)
{
throw new Exception($"Error verifying SSI artifacts: '{image}' could not be found. Ensure GitLab has successfully built and pushed the image", ex);
}
}
});

async Task ReplaceCommentInPullRequest(int prNumber, string title, string markdown)
{
try
Expand Down
Loading