Skip to content

Commit db854f5

Browse files
committed
Use managed identity for signing
1 parent 673639d commit db854f5

File tree

8 files changed

+123
-19
lines changed

8 files changed

+123
-19
lines changed

.config/dotnet-tools.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
"isRoot": true,
44
"tools": {
55
"sign": {
6-
"version": "0.9.1-beta.23203.3",
6+
"version": "0.9.1-beta.25330.2",
77
"commands": [
88
"sign"
9-
]
9+
],
10+
"rollForward": false
1011
}
1112
}
12-
}
13+
}

.github/workflows/push-main.yaml renamed to .github/workflows/ci-signed.yaml

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: xUnit.net Analyzers CI Build
1+
name: xUnit.net Analyzers CI Build (signed)
22
on:
33
push:
44
branches:
@@ -7,9 +7,10 @@ on:
77
workflow_dispatch:
88

99
jobs:
10-
build:
10+
deployment:
1111
name: "Build"
1212
runs-on: windows-latest
13+
environment: signing
1314
env:
1415
DOTNET_CLI_WORKLOAD_UPDATE_NOTIFY_DISABLE: true
1516
DOTNET_NOLOGO: true
@@ -30,20 +31,24 @@ jobs:
3031
- name: Get .NET information
3132
run: dotnet --info
3233

34+
- name: Login to Azure CLI
35+
uses: azure/login@v2
36+
with:
37+
client-id: ${{ vars.KEYVAULT_APP_ID }}
38+
tenant-id: ${{ vars.KEYVAULT_TENANT_ID }}
39+
subscription-id: ${{ vars.KEYVAULT_SUBSCRIPTION_ID }}
40+
3341
- name: "Build target: BuildAll"
3442
run: dotnet run --project tools/builder --no-launch-profile -- BuildAll --timing
3543

3644
- name: "Build target: PublishPackages"
3745
env:
38-
PUSH_APIKEY: ${{ secrets.PUSH_APIKEY }}
39-
PUSH_URI: ${{ secrets.PUSH_URI }}
40-
SIGN_APP_ID: ${{ secrets.SIGN_APP_ID }}
41-
SIGN_APP_SECRET: ${{ secrets.SIGN_APP_SECRET }}
42-
SIGN_CERT_NAME: ${{ secrets.SIGN_CERT_NAME }}
43-
SIGN_SUBSCRIPTION: ${{ secrets.SIGN_SUBSCRIPTION }}
44-
SIGN_TENANT: ${{ secrets.SIGN_TENANT }}
45-
SIGN_TIMESTAMP_URI: ${{ secrets.SIGN_TIMESTAMP_URI }}
46-
SIGN_VAULT_URI: ${{ secrets.SIGN_VAULT_URI }}
46+
PUSH_APIKEY: ${{ secrets.FEEDZ_PUSH_KEY }}
47+
PUSH_URI: ${{ vars.FEEDZ_PUSH_URL }}
48+
SIGN_APP_ID: ${{ vars.KEYVAULT_APP_ID }}
49+
SIGN_CERT_NAME: ${{ vars.KEYVAULT_CERT_NAME }}
50+
SIGN_TIMESTAMP_URI: ${{ vars.KEYVAULT_TIMESTAMP_URL }}
51+
SIGN_VAULT_URI: ${{ vars.KEYVAULT_URL }}
4752
run: dotnet run --project tools/builder --no-launch-profile -- PublishPackages --timing
4853

4954
- name: "Upload artifact: test"
@@ -66,6 +71,5 @@ jobs:
6671
uses: ctrf-io/github-test-reporter@v1
6772
with:
6873
report-path: './artifacts/test/*.ctrf'
69-
summary-report: true
7074
github-report: true
7175
if: always()

.github/workflows/ci-unsigned.yaml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: xUnit.net Analyzers CI Build (unsigned)
2+
on:
3+
push:
4+
branches-ignore:
5+
- main
6+
- 'rel/**'
7+
workflow_dispatch:
8+
9+
jobs:
10+
build:
11+
name: "Build"
12+
runs-on: windows-latest
13+
env:
14+
DOTNET_CLI_WORKLOAD_UPDATE_NOTIFY_DISABLE: true
15+
DOTNET_NOLOGO: true
16+
steps:
17+
- name: Clone source
18+
uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 0
21+
submodules: true
22+
23+
- name: Install .NET SDK
24+
uses: actions/setup-dotnet@v4
25+
with:
26+
dotnet-version: |
27+
8.0.x
28+
9.0.x
29+
30+
- name: Get .NET information
31+
run: dotnet --info
32+
33+
- name: "Build target: BuildAll"
34+
run: dotnet run --project tools/builder --no-launch-profile -- BuildAll --timing
35+
36+
- name: "Upload artifact: test"
37+
uses: actions/upload-artifact@v4
38+
with:
39+
name: test
40+
path: artifacts/test
41+
compression-level: 9
42+
if: always()
43+
44+
- name: "Upload artifact: packages"
45+
uses: actions/upload-artifact@v4
46+
with:
47+
name: packages
48+
path: artifacts/packages
49+
compression-level: 0
50+
if: always()
51+
52+
- name: Publish Test Report
53+
uses: ctrf-io/github-test-reporter@v1
54+
with:
55+
report-path: './artifacts/test/*.ctrf'
56+
github-report: true
57+
if: always()

.github/workflows/pull-request.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ jobs:
5959
uses: ctrf-io/github-test-reporter@v1
6060
with:
6161
report-path: './artifacts/test/*.ctrf'
62-
summary-report: true
6362
github-report: true
6463
pull-request: true
6564
update-comment: true

src/Directory.Build.targets

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,19 @@
3232

3333
<Target Name="UpdateNuSpecProperties" BeforeTargets="GenerateNuspec" DependsOnTargets="GetBuildVersion">
3434
<PropertyGroup>
35+
<SignedPath />
36+
<SignedPath Condition=" '$(SIGN_APP_ID)' != '' ">signed\</SignedPath>
3537
<!-- Local builds should have a '-dev' suffix on the build number -->
3638
<PrereleaseSuffix Condition=" '$(GITHUB_ACTIONS)' != 'true' ">-dev</PrereleaseSuffix>
3739
<!-- Never put the Git hash in the package version -->
3840
<PackageVersion>$(BuildVersionSimple)$(PrereleaseVersion)$(PrereleaseSuffix)</PackageVersion>
41+
<PackageReleaseNotes>https://xunit.net/releases/analyzers/$(PackageVersion)</PackageReleaseNotes>
3942
<!-- Pass through values we don't know ahead of time for any hand-crafted .nuspec files -->
4043
<NuspecProperties>
4144
Configuration=$(Configuration);
4245
GitCommitId=$(GitCommitId);
4346
PackageVersion=$(PackageVersion);
47+
SignedPath=$(SignedPath);
4448
</NuspecProperties>
4549
</PropertyGroup>
4650
</Target>

src/xunit.analyzers/xunit.analyzers.nuspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ Installing this package provides code analyzers to help developers find and fix
2323
<file target="_content\" src="..\..\README.md" />
2424
<file target="_content\" src="..\..\tools\media\logo-128-transparent.png" />
2525

26-
<file target="analyzers\dotnet\cs\" src="..\xunit.analyzers.fixes\bin\$Configuration$\netstandard2.0\xunit.analyzers.dll" />
27-
<file target="analyzers\dotnet\cs\" src="..\xunit.analyzers.fixes\bin\$Configuration$\netstandard2.0\xunit.analyzers.fixes.dll" />
26+
<file target="analyzers\dotnet\cs\" src="..\xunit.analyzers\bin\$Configuration$\netstandard2.0\$SignedPath$xunit.analyzers.dll" />
27+
<file target="analyzers\dotnet\cs\" src="..\xunit.analyzers.fixes\bin\$Configuration$\netstandard2.0\$SignedPath$xunit.analyzers.fixes.dll" />
2828

2929
<file target="tools\" src="..\xunit.analyzers.fixes\tools\*.ps1" />
3030
</files>

tools/builder/common

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System;
2+
using System.IO;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Xunit.BuildTools.Models;
6+
7+
namespace Xunit.BuildTools.Targets;
8+
9+
public static partial class SignAssemblies
10+
{
11+
public static Task OnExecute(BuildContext context)
12+
{
13+
// Check early because we don't need to make copies or show the banner for non-signed scenarios
14+
if (!context.CanSign)
15+
return Task.CompletedTask;
16+
17+
context.BuildStep("Signing binaries");
18+
19+
// Note that any changes to .nuspec files means this list needs to be updated, and nuspec files should
20+
// always reference the original signed paths, and not dependency copies (i.e., xunit.v3.common.dll)
21+
var binaries =
22+
new[] {
23+
Path.Combine(context.BaseFolder, "src", "xunit.analyzers", "bin", context.ConfigurationText, "netstandard2.0", "xunit.analyzers.dll"),
24+
Path.Combine(context.BaseFolder, "src", "xunit.analyzers.fixes", "bin", context.ConfigurationText, "netstandard2.0", "xunit.analyzers.fixes.dll"),
25+
}.Select(unsignedPath =>
26+
{
27+
var unsignedFolder = Path.GetDirectoryName(unsignedPath) ?? throw new InvalidOperationException($"Path '{unsignedPath}' did not have a folder");
28+
var signedFolder = Path.Combine(unsignedFolder, "signed");
29+
Directory.CreateDirectory(signedFolder);
30+
31+
var signedPath = Path.Combine(signedFolder, Path.GetFileName(unsignedPath));
32+
File.Copy(unsignedPath, signedPath, overwrite: true);
33+
34+
return signedPath;
35+
}).ToArray();
36+
37+
return context.SignFiles(context.BaseFolder, binaries);
38+
}
39+
}

0 commit comments

Comments
 (0)