Skip to content

Commit e539c7d

Browse files
authored
chore: template public API snapshot versions (#238)
* chore: template public API snapshot versions * chore: support package-specific API version templates * chore: add version API snapshots for all packages * Revert "chore: add version API snapshots for all packages" This reverts commit cea0f18. * Revert "chore: support package-specific API version templates" This reverts commit 6f24c7a. * fix: make public API template rendering portable
1 parent 620bc67 commit e539c7d

3 files changed

Lines changed: 58 additions & 1 deletion

File tree

Directory.Build.targets

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<Project>
2+
<UsingTask TaskName="RenderPublicApiSnapshot"
3+
TaskFactory="RoslynCodeTaskFactory"
4+
AssemblyFile="$(MSBuildToolsPath)/Microsoft.Build.Tasks.Core.dll">
5+
<ParameterGroup>
6+
<SourceFile ParameterType="System.String" Required="true" />
7+
<OutputFile ParameterType="System.String" Required="true" />
8+
<Version ParameterType="System.String" Required="true" />
9+
</ParameterGroup>
10+
<Task>
11+
<Using Namespace="System.IO" />
12+
<Code Type="Fragment" Language="cs"><![CDATA[
13+
var directory = Path.GetDirectoryName(OutputFile);
14+
if (!string.IsNullOrEmpty(directory))
15+
{
16+
Directory.CreateDirectory(directory);
17+
}
18+
19+
var text = File.ReadAllText(SourceFile).Replace("<version>", Version);
20+
File.WriteAllText(OutputFile, text);
21+
]]></Code>
22+
</Task>
23+
</UsingTask>
24+
25+
<!-- Render PublicAPI snapshots through a template step so version constants can use <version>. -->
26+
<Target Name="PreparePublicApiSnapshots"
27+
BeforeTargets="CoreCompile"
28+
Condition="Exists('$(MSBuildProjectDirectory)/PublicAPI.Shipped.txt') Or Exists('$(MSBuildProjectDirectory)/PublicAPI.Unshipped.txt')">
29+
<PropertyGroup>
30+
<_PublicApiSnapshotOutputDir>$(IntermediateOutputPath)PublicApiSnapshots/</_PublicApiSnapshotOutputDir>
31+
</PropertyGroup>
32+
33+
<RenderPublicApiSnapshot SourceFile="$(MSBuildProjectDirectory)/PublicAPI.Shipped.txt"
34+
OutputFile="$(_PublicApiSnapshotOutputDir)PublicAPI.Shipped.txt"
35+
Version="$(Version)"
36+
Condition="Exists('$(MSBuildProjectDirectory)/PublicAPI.Shipped.txt')" />
37+
<RenderPublicApiSnapshot SourceFile="$(MSBuildProjectDirectory)/PublicAPI.Unshipped.txt"
38+
OutputFile="$(_PublicApiSnapshotOutputDir)PublicAPI.Unshipped.txt"
39+
Version="$(Version)"
40+
Condition="Exists('$(MSBuildProjectDirectory)/PublicAPI.Unshipped.txt')" />
41+
42+
<ItemGroup>
43+
<AdditionalFiles Remove="PublicAPI.Shipped.txt" />
44+
<AdditionalFiles Remove="$(MSBuildProjectDirectory)/PublicAPI.Shipped.txt" />
45+
<AdditionalFiles Remove="PublicAPI.Unshipped.txt" />
46+
<AdditionalFiles Remove="$(MSBuildProjectDirectory)/PublicAPI.Unshipped.txt" />
47+
48+
<AdditionalFiles Include="$(_PublicApiSnapshotOutputDir)PublicAPI.Shipped.txt"
49+
Link="PublicAPI.Shipped.txt"
50+
Condition="Exists('$(MSBuildProjectDirectory)/PublicAPI.Shipped.txt')" />
51+
<AdditionalFiles Include="$(_PublicApiSnapshotOutputDir)PublicAPI.Unshipped.txt"
52+
Link="PublicAPI.Unshipped.txt"
53+
Condition="Exists('$(MSBuildProjectDirectory)/PublicAPI.Unshipped.txt')" />
54+
</ItemGroup>
55+
</Target>
56+
</Project>

sdk_compliance_adapter/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ WORKDIR /app
33

44
# Copy the solution and project files
55
COPY Directory.Build.props ./
6+
COPY Directory.Build.targets ./
67
COPY Directory.Packages.props ./
78
COPY src/PostHog/PostHog.csproj src/PostHog/
89
COPY src/PostHog/packages.lock.json src/PostHog/

src/PostHog/PublicAPI.Shipped.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ const PostHog.Api.PostHogProperties.RequestPath = "$request_path" -> string!
335335
const PostHog.Api.PostHogProperties.ResponseStatusCode = "$response_status_code" -> string!
336336
const PostHog.Api.PostHogProperties.SessionId = "$session_id" -> string!
337337
const PostHog.Api.PostHogProperties.UserAgent = "$user_agent" -> string!
338-
const PostHog.Versioning.VersionConstants.Version = "2.7.1" -> string!
338+
const PostHog.Versioning.VersionConstants.Version = "<version>" -> string!
339339
override PostHog.Api.ApiErrorResult.Equals(object? obj) -> bool
340340
override PostHog.Api.ApiErrorResult.GetHashCode() -> int
341341
override PostHog.Api.ApiErrorResult.ToString() -> string!

0 commit comments

Comments
 (0)