Skip to content

Commit 57900b2

Browse files
authored
Feature: add the ability to specify file names (#21)
1 parent dafeb2f commit 57900b2

File tree

6 files changed

+123
-59
lines changed

6 files changed

+123
-59
lines changed

.github/workflows/ci-build.yml

Lines changed: 4 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
name: Build and Release
1+
name: Build
22

33
on:
44
push:
55
branches: [ main ]
66
pull_request:
7-
types: [opened, synchronize, reopened, closed]
87
branches: [ main ]
98

109
env:
@@ -13,7 +12,7 @@ env:
1312

1413
jobs:
1514
build:
16-
runs-on: windows-latest
15+
runs-on: windows-2022
1716
outputs:
1817
nbgv: ${{ steps.nbgv.outputs.SemVer2 }}
1918
steps:
@@ -24,12 +23,12 @@ jobs:
2423
lfs: true
2524

2625
- name: Install .NET Core
27-
uses: actions/[email protected].0
26+
uses: actions/[email protected].2
2827
with:
2928
dotnet-version: 3.1.x
3029

3130
- name: Install .NET 5
32-
uses: actions/[email protected].0
31+
uses: actions/[email protected].2
3332
with:
3433
dotnet-version: 5.0.x
3534

@@ -79,52 +78,3 @@ jobs:
7978
with:
8079
name: nuget
8180
path: '**/*.nupkg'
82-
83-
release:
84-
runs-on: windows-latest
85-
needs: build
86-
if: contains(github.event.pull_request.labels.*.name, 'release') && github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.merged == true
87-
steps:
88-
- name: Checkout
89-
uses: actions/[email protected]
90-
with:
91-
fetch-depth: 0
92-
93-
- name: Download NuGet Packages
94-
uses: actions/[email protected]
95-
with:
96-
name: nuget
97-
98-
- uses: nuget/setup-nuget@v1
99-
name: Setup NuGet
100-
101-
# Decode the base 64 encoded pfx and save the Signing_Certificate
102-
- name: Sign NuGet packages
103-
shell: pwsh
104-
run: |
105-
$pfx_cert_byte = [System.Convert]::FromBase64String("${{ secrets.SIGNING_CERTIFICATE }}")
106-
[IO.File]::WriteAllBytes("GitHubActionsWorkflow.pfx", $pfx_cert_byte)
107-
$secure_password = ConvertTo-SecureString ${{ secrets.SIGN_CERTIFICATE_PASSWORD }} –asplaintext –force
108-
Import-PfxCertificate -FilePath GitHubActionsWorkflow.pfx -Password $secure_password -CertStoreLocation Cert:\CurrentUser\My
109-
nuget sign -Timestamper http://timestamp.digicert.com -CertificateFingerprint ${{ secrets.SIGN_CERTIFICATE_HASH }} **/*.nupkg
110-
111-
- name: Changelog
112-
uses: glennawatson/ChangeLog@v1
113-
id: changelog
114-
115-
- name: Create Release
116-
uses: actions/[email protected]
117-
env:
118-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
119-
with:
120-
tag_name: ${{ needs.build.outputs.nbgv }}
121-
release_name: ${{ needs.build.outputs.nbgv }}
122-
body: |
123-
${{ steps.changelog.outputs.commitLog }}
124-
125-
- name: NuGet Push
126-
env:
127-
NUGET_AUTH_TOKEN: ${{ secrets.NUGET_API_KEY }}
128-
SOURCE_URL: https://api.nuget.org/v3/index.json
129-
run: |
130-
dotnet nuget push -s ${{ env.SOURCE_URL }} -k ${{ env.NUGET_AUTH_TOKEN }} **/*.nupkg

.github/workflows/release.yml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
name: Build and Release
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
7+
env:
8+
configuration: Release
9+
productNamespacePrefix: "ReactiveMarbles"
10+
11+
jobs:
12+
build:
13+
runs-on: windows-2022
14+
environment:
15+
name: release
16+
outputs:
17+
nbgv: ${{ steps.nbgv.outputs.SemVer2 }}
18+
steps:
19+
- name: Checkout
20+
uses: actions/[email protected]
21+
with:
22+
fetch-depth: 0
23+
lfs: true
24+
25+
- name: Install .NET Core
26+
uses: actions/[email protected]
27+
with:
28+
dotnet-version: 3.1.x
29+
30+
- name: Install .NET 5
31+
uses: actions/[email protected]
32+
with:
33+
dotnet-version: 5.0.x
34+
35+
- name: NBGV
36+
id: nbgv
37+
uses: dotnet/nbgv@master
38+
with:
39+
setAllVars: true
40+
41+
- name: NuGet Restore
42+
run: dotnet restore
43+
working-directory: src
44+
45+
- name: Build
46+
run: dotnet build --configuration=${{ env.configuration }} --verbosity=minimal --no-restore
47+
working-directory: src
48+
49+
- name: Pack
50+
run: dotnet pack --configuration=${{ env.configuration }} --verbosity=minimal --no-restore
51+
working-directory: src
52+
53+
- uses: nuget/setup-nuget@v1
54+
name: Setup NuGet
55+
56+
# Decode the base 64 encoded pfx and save the Signing_Certificate
57+
- name: Sign NuGet packages
58+
shell: pwsh
59+
run: |
60+
$pfx_cert_byte = [System.Convert]::FromBase64String("${{ secrets.SIGNING_CERTIFICATE }}")
61+
[IO.File]::WriteAllBytes("GitHubActionsWorkflow.pfx", $pfx_cert_byte)
62+
$secure_password = ConvertTo-SecureString ${{ secrets.SIGN_CERTIFICATE_PASSWORD }} –asplaintext –force
63+
Import-PfxCertificate -FilePath GitHubActionsWorkflow.pfx -Password $secure_password -CertStoreLocation Cert:\CurrentUser\My
64+
nuget sign -Timestamper http://timestamp.digicert.com -CertificateFingerprint ${{ secrets.SIGN_CERTIFICATE_HASH }} **/*.nupkg
65+
66+
- name: Changelog
67+
uses: glennawatson/[email protected]
68+
id: changelog
69+
70+
- name: Create Release
71+
uses: actions/[email protected]
72+
env:
73+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
74+
with:
75+
tag_name: ${{ steps.nbgv.outputs.SemVer2 }}
76+
release_name: ${{ steps.nbgv.outputs.SemVer2 }}
77+
body: |
78+
${{ steps.changelog.outputs.commitLog }}
79+
80+
- name: NuGet Push
81+
env:
82+
NUGET_AUTH_TOKEN: ${{ secrets.NUGET_API_KEY }}
83+
SOURCE_URL: https://api.nuget.org/v3/index.json
84+
run: |
85+
dotnet nuget push -s ${{ env.SOURCE_URL }} -k ${{ env.NUGET_AUTH_TOKEN }} **/*.nupkg

src/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
</ItemGroup>
3939

4040
<ItemGroup>
41-
<PackageReference Include="Nerdbank.GitVersioning" Version="3.4.231" PrivateAssets="all" />
41+
<PackageReference Include="Nerdbank.GitVersioning" Version="3.4.240" PrivateAssets="all" />
4242
</ItemGroup>
4343

4444
<ItemGroup>

src/ReactiveMarbles.SourceGenerator.TestNuGetHelper/Compilation/SourceGeneratorUtility.cs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,19 @@ static SourceGeneratorUtility()
6767
public T RunGenerator<T>(EventBuilderCompiler compiler, out ImmutableArray<Diagnostic> compilationDiagnostics, out ImmutableArray<Diagnostic> generatorDiagnostics, out GeneratorDriver generatorDriver, params string[] sources)
6868
where T : ISourceGenerator, new() => RunGenerator<T>(compiler, out compilationDiagnostics, out generatorDiagnostics, out generatorDriver, out _, out _, sources);
6969

70+
/// <summary>
71+
/// Runs the generator.
72+
/// </summary>
73+
/// <typeparam name="T">The type of generator.</typeparam>
74+
/// <param name="compiler">The compiler.</param>
75+
/// <param name="compilationDiagnostics">The diagnostics which are produced from the compiler.</param>
76+
/// <param name="generatorDiagnostics">The diagnostics which are produced from the generator.</param>
77+
/// <param name="generatorDriver">Output value for the driver.</param>
78+
/// <param name="sources">The source code files.</param>
79+
/// <returns>The source generator instance.</returns>
80+
public T RunGenerator<T>(EventBuilderCompiler compiler, out ImmutableArray<Diagnostic> compilationDiagnostics, out ImmutableArray<Diagnostic> generatorDiagnostics, out GeneratorDriver generatorDriver, params (string FileName, string Source)[] sources)
81+
where T : ISourceGenerator, new() => RunGenerator<T>(compiler, out compilationDiagnostics, out generatorDiagnostics, out generatorDriver, out _, out _, sources);
82+
7083
/// <summary>
7184
/// Runs the generator.
7285
/// </summary>
@@ -80,6 +93,22 @@ public T RunGenerator<T>(EventBuilderCompiler compiler, out ImmutableArray<Diagn
8093
/// <param name="sources">The source code files.</param>
8194
/// <returns>The source generator instance.</returns>
8295
public T RunGenerator<T>(EventBuilderCompiler compiler, out ImmutableArray<Diagnostic> compilationDiagnostics, out ImmutableArray<Diagnostic> generatorDiagnostics, out GeneratorDriver generatorDriver, out Microsoft.CodeAnalysis.Compilation beforeCompilation, out Microsoft.CodeAnalysis.Compilation afterGeneratorCompilation, params string[] sources)
96+
where T : ISourceGenerator, new() =>
97+
RunGenerator<T>(compiler, out compilationDiagnostics, out generatorDiagnostics, out generatorDriver, out beforeCompilation, out afterGeneratorCompilation, sources.Select(x => (FileName: "Unknown File", Source: x)).ToArray());
98+
99+
/// <summary>
100+
/// Runs the generator.
101+
/// </summary>
102+
/// <typeparam name="T">The type of generator.</typeparam>
103+
/// <param name="compiler">The compiler.</param>
104+
/// <param name="compilationDiagnostics">The diagnostics which are produced from the compiler.</param>
105+
/// <param name="generatorDiagnostics">The diagnostics which are produced from the generator.</param>
106+
/// <param name="generatorDriver">Output value for the driver.</param>
107+
/// <param name="beforeCompilation">The compilation before the generator has run.</param>
108+
/// <param name="afterGeneratorCompilation">The compilation after the generator has run.</param>
109+
/// <param name="sources">The source code files.</param>
110+
/// <returns>The source generator instance.</returns>
111+
public T RunGenerator<T>(EventBuilderCompiler compiler, out ImmutableArray<Diagnostic> compilationDiagnostics, out ImmutableArray<Diagnostic> generatorDiagnostics, out GeneratorDriver generatorDriver, out Microsoft.CodeAnalysis.Compilation beforeCompilation, out Microsoft.CodeAnalysis.Compilation afterGeneratorCompilation, params (string FileName, string Source)[] sources)
83112
where T : ISourceGenerator, new()
84113
{
85114
beforeCompilation = CreateCompilation(compiler, sources);
@@ -109,7 +138,7 @@ private static void ShouldHaveNoCompilerDiagnosticsWarningOrAbove(Action<string>
109138
}
110139
}
111140

112-
private static Microsoft.CodeAnalysis.Compilation CreateCompilation(EventBuilderCompiler compiler, params string[] sources)
141+
private static Microsoft.CodeAnalysis.Compilation CreateCompilation(EventBuilderCompiler compiler, params (string FileName, string Source)[] sources)
113142
{
114143
var assemblyPath = Path.GetDirectoryName(typeof(object).Assembly.Location);
115144

@@ -126,7 +155,7 @@ private static Microsoft.CodeAnalysis.Compilation CreateCompilation(EventBuilder
126155

127156
return CSharpCompilation.Create(
128157
"compilation" + Guid.NewGuid(),
129-
sources.Select(x => CSharpSyntaxTree.ParseText(x, new CSharpParseOptions(LanguageVersion.Latest))),
158+
sources.Select(x => CSharpSyntaxTree.ParseText(x.Source, new CSharpParseOptions(LanguageVersion.Latest), x.FileName)),
130159
assemblies,
131160
new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, deterministic: true));
132161
}

src/ReactiveMarbles.SourceGenerator.TestNuGetHelper/ReactiveMarbles.SourceGenerator.TestNuGetHelper.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="ReactiveMarbles.NuGet.Helpers" Version="1.0.6" />
10+
<PackageReference Include="ReactiveMarbles.NuGet.Helpers" Version="1.0.11" />
1111
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="3.11.0" />
1212
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.2" />
1313
<PackageReference Include="ICSharpCode.Decompiler" Version="7.1.0.6543" />

version.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "1.1",
2+
"version": "1.2",
33
"publicReleaseRefSpec": [
44
"^refs/heads/master$",
55
"^refs/heads/main$"

0 commit comments

Comments
 (0)