Skip to content

Commit

Permalink
(cake-buildGH-4331/cake-buildGH-4349) Migrate GHA Artifact to V4 API
Browse files Browse the repository at this point in the history
  • Loading branch information
devlead committed Sep 30, 2024
1 parent 29611bd commit 88493f4
Show file tree
Hide file tree
Showing 20 changed files with 532 additions and 583 deletions.
247 changes: 88 additions & 159 deletions src/Cake.Common.Tests/Fixtures/Build/GitHubActionsCommandsFixture.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using Cake.Common.Build.GitHubActions.Data;
using Cake.Core;
using NSubstitute;
Expand All @@ -10,8 +11,11 @@ namespace Cake.Common.Tests.Fixtures.Build
{
internal sealed class GitHubActionsInfoFixture
{
public const string ActionRuntimeToken = "zht1j5NeW2T5ZsOxncX4CUEiWYhD4ZRwoDghkARk";
public const string ActionRuntimeToken = "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6Ikh5cTROQVRBanNucUM3bWRydEFoaHJDUjJfUSJ9.eyJuYW1laWQiOiJkZGRkZGRkZC1kZGRkLWRkZGQtZGRkZC1kZGRkZGRkZGRkZGQiLCJzY3AiOiJBY3Rpb25zLkdlbmVyaWNSZWFkOjAwMDAwMDAwLTAwMDAtMDAwMC0wMDAwLTAwMDAwMDAwMDAwMCBBY3Rpb25zLlJlc3VsdHM6YjllMjgxNTMtY2EyMC00Yjg2LTkxZGQtMDllOGY2NDRlZmRmOjFkODQ5YTQ1LTJmMzAtNWZiYi0zMjI2LWI3MzBhMTdhOTNhZiBBY3Rpb25zLlVwbG9hZEFydGlmYWN0czowMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAwMDAvMTpCdWlsZC9CdWlsZC8xNiBMb2NhdGlvblNlcnZpY2UuQ29ubmVjdCBSZWFkQW5kVXBkYXRlQnVpbGRCeVVyaTowMDAwMDAwMC0wMDAwLTAwMDAtMDAw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la9MOklVq2ehx6DC12qbUNpTELJGeWz_JvKHWexyfN1qJgUw3y4ritZDJF3HLTpb5IJS7sQmFZVB7F2P6DF-1iaCBX5hgA9KfiwWXw6oTkKd6aOEyJpcBe0b87V_-fVTivOUS-ABE5XN6TCLZSmt7X6qwTPeSoLKgQGx1h_tHwubGDjtQ";
public const string ActionRuntimeUrl = "https://pipelines.actions.githubusercontent.com/ip0FyYnZXxdEOcOwPHkRsZJd2x6G5XoT486UsAb0/";
public const string ActionResultsUrl = "https://results-receiver.actions.githubusercontent.com/";
private readonly Version CakeTestVersion = new Version(1, 2, 3, 4);

public ICakeEnvironment Environment { get; }

public GitHubActionsInfoFixture()
Expand Down Expand Up @@ -55,11 +59,15 @@ public GitHubActionsInfoFixture()

Environment.GetEnvironmentVariable("ACTIONS_RUNTIME_TOKEN").Returns(ActionRuntimeToken);
Environment.GetEnvironmentVariable("ACTIONS_RUNTIME_URL").Returns(ActionRuntimeUrl);
Environment.GetEnvironmentVariable("ACTIONS_RESULTS_URL").Returns(ActionResultsUrl);
Environment.GetEnvironmentVariable("GITHUB_ENV").Returns("/opt/github.env");
Environment.GetEnvironmentVariable("GITHUB_OUTPUT").Returns("/opt/github.output");
Environment.GetEnvironmentVariable("GITHUB_STEP_SUMMARY").Returns("/opt/github.stepsummary");
Environment.GetEnvironmentVariable("GITHUB_PATH").Returns("/opt/github.path");
Environment.WorkingDirectory.Returns("/home/runner/work/cake/cake");

Environment.GetSpecialPath(Core.IO.SpecialPath.LocalTemp).Returns("/tmp");
Environment.Runtime.CakeVersion.Returns(CakeTestVersion);
}

public GitHubActionsRunnerInfo CreateRunnerInfo(string architecture = null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ public void Should_Return_Correct_Value()
var result = info.Token;

// Then
Assert.Equal("zht1j5NeW2T5ZsOxncX4CUEiWYhD4ZRwoDghkARk", result);
Assert.Equal(
"eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI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IlBlcm1pc3Npb25cIjozfV0iLCJhY3NsIjoiMTAiLCJvcmNoaWQiOiJiOWUyODE1My1jYTIwLTRiODYtOTFkZC0wOWU4ZjY0NGVmZGYuYnVpbGQudWJ1bnR1LWxhdGVzdCIsImlzcyI6InZzdG9rZW4uYWN0aW9ucy5naXRodWJ1c2VyY29udGVudC5jb20iLCJhdWQiOiJ2c3Rva2VuLmFjdGlvbnMuZ2l0aHVidXNlcmNvbnRlbnQuY29tfHZzbzo0M2YwNTdkMC0wODAzLTRkOTEtOTRhMS1mOGViMTAzZGYxMWYiLCJuYmYiOjE3Mjc1NDQzOTIsImV4cCI6MTcyNzU2NzE5Mn0.sUTvwxD-NlbAhQJB7cIInovd9qDkFHWcwOiiQAlHCsjpRBCEUWb3tWfOmCEpn8It4FWkaSszjMd8oecBEMlyEUtk6Cm6l1AqCUnIT13B48c_2sjhjWz-UDNMt94nzYH2ulC8mBcV_kSEIHJUvOnFKrFMKEdg6axAjLCx4la9MOklVq2ehx6DC12qbUNpTELJGeWz_JvKHWexyfN1qJgUw3y4ritZDJF3HLTpb5IJS7sQmFZVB7F2P6DF-1iaCBX5hgA9KfiwWXw6oTkKd6aOEyJpcBe0b87V_-fVTivOUS-ABE5XN6TCLZSmt7X6qwTPeSoLKgQGx1h_tHwubGDjtQ",
result);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Text.Json.Serialization;

namespace Cake.Common.Build.GitHubActions.Commands.Artifact
{
#pragma warning disable SA1313 // Parameter names should begin with lower-case letter
internal record CreateArtifactRequest(
[property: JsonPropertyName("version")]
int Version,
[property: JsonPropertyName("name")]
string Name,
[property: JsonPropertyName("workflow_run_backend_id")]
string WorkflowRunBackendId,
[property: JsonPropertyName("workflow_job_run_backend_id")]
string WorkflowJobRunBackendId);
#pragma warning restore SA1313 // Parameter names should begin with lower-case letter
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Text.Json.Serialization;

namespace Cake.Common.Build.GitHubActions.Commands.Artifact
{
#pragma warning disable SA1313 // Parameter names should begin with lower-case letter
internal record CreateArtifactResponse(
[property: JsonPropertyName("ok")]
bool Ok,
[property: JsonPropertyName("signed_upload_url")]
string SignedUploadUrl);
#pragma warning restore SA1313 // Parameter names should begin with lower-case letter
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Text.Json.Serialization;

namespace Cake.Common.Build.GitHubActions.Commands.Artifact
{
#pragma warning disable SA1313 // Parameter names should begin with lower-case letter
internal record FinalizeArtifactRequest(
[property: JsonPropertyName("name")]
string Name,
[property: JsonPropertyName("hash")]
string Hash,
[property: JsonPropertyName("size")]
long Size,
[property: JsonPropertyName("workflow_run_backend_id")]
string WorkflowRunBackendId,
[property: JsonPropertyName("workflow_job_run_backend_id")]
string WorkflowJobRunBackendId);
#pragma warning restore SA1313 // Parameter names should begin with lower-case letter
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Text.Json.Serialization;

namespace Cake.Common.Build.GitHubActions.Commands.Artifact
{
#pragma warning disable SA1313 // Parameter names should begin with lower-case letter
internal record FinalizeArtifactResponse(
[property: JsonPropertyName("ok")]
bool Ok,
[property: JsonPropertyName("artifact_id")]
string ArtifactId);
#pragma warning restore SA1313 // Parameter names should begin with lower-case letter
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Text.Json.Serialization;

namespace Cake.Common.Build.GitHubActions.Commands.Artifact
{
#pragma warning disable SA1313 // Parameter names should begin with lower-case letter
internal record GetSignedArtifactURLRequest(
[property: JsonPropertyName("workflow_run_backend_id")]
string WorkflowRunBackendId,
[property: JsonPropertyName("workflow_job_run_backend_id")]
string WorkflowJobRunBackendId,
[property: JsonPropertyName("name")]
string Name);
#pragma warning restore SA1313 // Parameter names should begin with lower-case letter
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Text.Json.Serialization;
namespace Cake.Common.Build.GitHubActions.Commands.Artifact
{
#pragma warning disable SA1313 // Parameter names should begin with lower-case letter
internal record GetSignedArtifactURLResponse(
[property: JsonPropertyName("name")]
string Name,
[property: JsonPropertyName("signed_url")]
string SignedUrl);
#pragma warning restore SA1313 // Parameter names should begin with lower-case letter
}
Loading

0 comments on commit 88493f4

Please sign in to comment.