Skip to content
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
18 changes: 3 additions & 15 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ jobs:
os: [windows-latest, ubuntu-latest, macos-latest]
env:
TRUSTED_INGEST: ${{ (github.event_name == 'push' || github.event_name == 'workflow_dispatch') && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop') }}
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
steps:
- name: Get the sources
uses: actions/checkout@v7
Expand All @@ -48,14 +45,6 @@ jobs:
with:
user: ${{ secrets.NUGET_USER }}

- name: Azure login
if: ${{ env.TRUSTED_INGEST == 'true' && env.AZURE_CLIENT_ID != '' && env.AZURE_TENANT_ID != '' && env.AZURE_SUBSCRIPTION_ID != '' }}
uses: azure/login@v3
with:
client-id: ${{ env.AZURE_CLIENT_ID }}
tenant-id: ${{ env.AZURE_TENANT_ID }}
subscription-id: ${{ env.AZURE_SUBSCRIPTION_ID }}

- name: Run Cake script
uses: cake-build/cake-action@v3
env:
Expand All @@ -65,11 +54,10 @@ jobs:
NUGET_SOURCE: ${{ secrets.NUGET_SOURCE }}
NUGET_APIKEY: ${{ steps.login.outputs.NUGET_API_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
AZURE_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}
AZURE_TENANT_ID: ${{ env.TRUSTED_INGEST == 'true' && secrets.AZURE_TENANT_ID || '' }}
AZURE_CLIENT_ID: ${{ env.TRUSTED_INGEST == 'true' && secrets.AZURE_CLIENT_ID || '' }}
AZURE_AUTHORITY_HOST: "https://login.microsoftonline.com"
AZURE_STORAGE_ACCOUNT: ${{ secrets.AZURE_STORAGE_ACCOUNT }}
AZURE_STORAGE_ACCOUNT: ${{ env.TRUSTED_INGEST == 'true' && secrets.AZURE_STORAGE_ACCOUNT || '' }}
AZURE_STORAGE_ACCOUNT_CONTAINER: ${{ secrets.AZURE_STORAGE_ACCOUNT_CONTAINER }}${{ matrix.os }}
with:
file-path: cake.cs
Expand Down
8 changes: 8 additions & 0 deletions build/records.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,14 @@ public bool ShouldReportDPI() =>

public string? AzureStorageAccountContainer { get; } = System.Environment.GetEnvironmentVariable("AZURE_STORAGE_ACCOUNT_CONTAINER");

public bool ShouldPrepareAzureWorkloadIdentity() => GitHubActions.IsRunningOnGitHubActions &&
AzureCredentials.WorkloadIdentitySpecified;

public bool ShouldRunIntegrationTests() => !string.IsNullOrWhiteSpace(AzureStorageAccount) &&
!string.IsNullOrWhiteSpace(AzureStorageAccountContainer) &&
(
AzureCredentials.AzureCredentialsSpecified ||
ShouldPrepareAzureWorkloadIdentity() ||
IsLocalBuild
);
}
Expand All @@ -80,6 +84,10 @@ public record AzureCredentials(
!string.IsNullOrWhiteSpace(ClientId) &&
!string.IsNullOrWhiteSpace(ClientSecret) &&
!string.IsNullOrWhiteSpace(AuthorityHost);

public bool WorkloadIdentitySpecified { get; } = !string.IsNullOrWhiteSpace(TenantId) &&
!string.IsNullOrWhiteSpace(ClientId) &&
string.IsNullOrWhiteSpace(ClientSecret);
}
internal record ExtensionHelper(Func<string, CakeTaskBuilder> TaskCreate, Func<CakeReport> Run);

23 changes: 19 additions & 4 deletions cake.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,23 @@
)
.Then("DPI")
.Does<BuildData>(
static (context, data) => Command(
["dpi", "dpi.exe"],
static async (context, data) => {
var workload = data.ShouldReportDPI() && data.ShouldPrepareAzureWorkloadIdentity()
? await GitHubActions.Commands.AzurePrepareWorkloadIdentity(data.AzureCredentials.TenantId!, data.AzureCredentials.ClientId!)
: null;

Command(
new CommandSettings {
ToolName = "dpi",
ToolExecutableNames = ["dpi", "dpi.exe"],
EnvironmentVariables = workload is null
? new Dictionary<string, string>()
: new Dictionary<string, string> {
["AZURE_TENANT_ID"] = workload.TenantId,
["AZURE_CLIENT_ID"] = workload.ClientId,
["AZURE_FEDERATED_TOKEN_FILE"] = workload.FederatedTokenFile.FullPath
}
},
new ProcessArgumentBuilder()
.Append("nuget")
.Append("--silent")
Expand All @@ -97,8 +112,8 @@
: "analyze"
)
.AppendSwitchQuoted("--buildversion", data.Version)
)
);
}
)
.Then("Build")
.Does<BuildData>(
Expand Down
Loading