Skip to content

Commit

Permalink
Merge pull request #3810 from arturcic/feature/yaml-cache
Browse files Browse the repository at this point in the history
Switch cache format from JSON back to YAML
  • Loading branch information
arturcic committed Nov 30, 2023
2 parents a58abfd + 1c87a40 commit 030694e
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 117 deletions.
4 changes: 2 additions & 2 deletions .github/actions/docker-manifests/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ runs:
-
name: '[Docker Publish Manifests] DockerHub'
shell: pwsh
run: dotnet run/docker.dll --target=DockerManifest --arch=amd64 --docker_dotnetversion=${{ inputs.targetFramework }} --docker_distro=${{ inputs.distro }} --docker_registry dockerhub
run: dotnet run/docker.dll --target=DockerManifest --arch=amd64 --arch=arm64 --docker_dotnetversion=${{ inputs.targetFramework }} --docker_distro=${{ inputs.distro }} --docker_registry dockerhub
-
name: Login to GitHub
uses: docker/login-action@v2
Expand All @@ -43,4 +43,4 @@ runs:
-
name: '[Docker Publish Manifests] GitHub'
shell: pwsh
run: dotnet run/docker.dll --target=DockerManifest --arch=amd64 --docker_dotnetversion=${{ inputs.targetFramework }} --docker_distro=${{ inputs.distro }} --docker_registry github
run: dotnet run/docker.dll --target=DockerManifest --arch=amd64 --arch=arm64 --docker_dotnetversion=${{ inputs.targetFramework }} --docker_distro=${{ inputs.distro }} --docker_registry github
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
strategy:
fail-fast: false
matrix:
arch: [ amd64 ]
arch: [ amd64, amd64 ]

uses: ./.github/workflows/_artifacts_linux.yml
with:
Expand All @@ -76,7 +76,7 @@ jobs:
strategy:
fail-fast: false
matrix:
arch: [ amd64 ]
arch: [ amd64, amd64 ]

uses: ./.github/workflows/_docker.yml
with:
Expand Down
206 changes: 99 additions & 107 deletions src/GitVersion.Core.Tests/Core/GitVersionExecutorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,33 +92,31 @@ public void CacheKeyForWorktree()
public void CacheFileExistsOnDisk()
{
const string versionCacheFileContent = """
{
"Major": 4,
"Minor": 10,
"Patch": 3,
"PreReleaseTag": "test.19",
"PreReleaseTagWithDash": "-test.19",
"PreReleaseLabel": "test",
"PreReleaseLabelWithDash": "-test",
"PreReleaseNumber": 19,
"WeightedPreReleaseNumber": 19,
"BuildMetaData": null,
"FullBuildMetaData": "Branch.feature/test.Sha.dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f",
"MajorMinorPatch": "4.10.3",
"SemVer": "4.10.3-test.19",
"AssemblySemVer": "4.10.3.0",
"AssemblySemFileVer": "4.10.3.0",
"FullSemVer": "4.10.3-test.19",
"InformationalVersion": "4.10.3-test.19+Branch.feature/test.Sha.dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f",
"BranchName": "feature/test",
"EscapedBranchName": "feature-test",
"Sha": "dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f",
"ShortSha": "dd2a29af",
"VersionSourceSha": "4.10.2",
"CommitsSinceVersionSource": 19,
"CommitDate": "2015-11-10T00:00:00.000Z",
"UncommittedChanges": 0
}
Major: 4
Minor: 10
Patch: 3
PreReleaseTag: test.19
PreReleaseTagWithDash: -test.19
PreReleaseLabel: test
PreReleaseLabelWithDash: -test
PreReleaseNumber: 19
WeightedPreReleaseNumber: 19
BuildMetaData:
FullBuildMetaData: Branch.feature/test.Sha.dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f
MajorMinorPatch: 4.10.3
SemVer: 4.10.3-test.19
AssemblySemVer: 4.10.3.0
AssemblySemFileVer: 4.10.3.0
FullSemVer: 4.10.3-test.19
InformationalVersion: 4.10.3-test.19+Branch.feature/test.Sha.dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f
BranchName: feature/test
EscapedBranchName: feature-test
Sha: dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f
ShortSha: dd2a29af
VersionSourceSha: 4.10.2
CommitsSinceVersionSource: 19
CommitDate: 2015-11-10
UncommittedChanges: 0
""";

var stringBuilder = new StringBuilder();
Expand Down Expand Up @@ -154,31 +152,29 @@ public void CacheFileExistsOnDisk()
public void CacheFileExistsOnDiskWhenOverrideConfigIsSpecifiedVersionShouldBeDynamicallyCalculatedWithoutSavingInCache()
{
const string versionCacheFileContent = """
{
"Major": 4,
"Minor": 10,
"Patch": 3,
"PreReleaseTag": "test.19",
"PreReleaseTagWithDash": "-test.19",
"PreReleaseLabel": "test",
"PreReleaseLabelWithDash": "-test",
"PreReleaseNumber": 19,
"BuildMetaData": null,
"FullBuildMetaData": "Branch.feature/test.Sha.dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f",
"MajorMinorPatch": "4.10.3",
"SemVer": "4.10.3-test.19",
"AssemblySemVer": "4.10.3.0",
"AssemblySemFileVer": "4.10.3.0",
"FullSemVer": "4.10.3-test.19",
"InformationalVersion": "4.10.3-test.19+Branch.feature/test.Sha.dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f",
"BranchName": "feature/test",
"EscapedBranchName": "feature-test",
"Sha": "dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f",
"ShortSha": "dd2a29af",
"CommitsSinceVersionSource": 19,
"CommitDate": "2015-11-10T00:00:00.000Z",
"UncommittedChanges": 0
}
Major: 4
Minor: 10
Patch: 3
PreReleaseTag: test.19
PreReleaseTagWithDash: -test.19
PreReleaseLabel: test
PreReleaseLabelWithDash: -test
PreReleaseNumber: 19
BuildMetaData:
FullBuildMetaData: Branch.feature/test.Sha.dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f
MajorMinorPatch: 4.10.3
SemVer: 4.10.3-test.19
AssemblySemVer: 4.10.3.0
AssemblySemFileVer: 4.10.3.0
FullSemVer: 4.10.3-test.19
InformationalVersion: 4.10.3-test.19+Branch.feature/test.Sha.dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f
BranchName: feature/test
EscapedBranchName: feature-test
Sha: dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f
ShortSha: dd2a29af
CommitsSinceVersionSource: 19
CommitDate: 2015-11-10
UncommittedChanges: 0
""";

using var fixture = new EmptyRepositoryFixture();
Expand Down Expand Up @@ -232,41 +228,39 @@ public void CacheFileIsMissing()
gitVersionCalculator.CalculateVersionVariables();

var logsMessages = stringBuilder.ToString();
logsMessages.ShouldContain(".json not found", Case.Insensitive, logsMessages);
logsMessages.ShouldMatch("(?s).*Cache file.*(?-s) not found.*");
}

[TestCase(ConfigurationFileLocator.DefaultFileName)]
[TestCase(ConfigurationFileLocator.DefaultAlternativeFileName)]
public void ConfigChangeInvalidatesCache(string configFileName)
{
const string versionCacheFileContent = """
{
"Major": 4,
"Minor": 10,
"Patch": 3,
"PreReleaseTag": "test.19",
"PreReleaseTagWithDash": "-test.19",
"PreReleaseLabel": "test",
"PreReleaseLabelWithDash": "-test",
"PreReleaseNumber": 19,
"WeightedPreReleaseNumber": 19,
"BuildMetaData": null,
"FullBuildMetaData": "Branch.feature/test.Sha.dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f",
"MajorMinorPatch": "4.10.3",
"SemVer": "4.10.3-test.19",
"AssemblySemVer": "4.10.3.0",
"AssemblySemFileVer": "4.10.3.0",
"FullSemVer": "4.10.3-test.19",
"InformationalVersion": "4.10.3-test.19+Branch.feature/test.Sha.dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f",
"BranchName": "feature/test",
"EscapedBranchName": "feature-test",
"Sha": "dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f",
"ShortSha": "dd2a29af",
"VersionSourceSha": "4.10.2",
"CommitsSinceVersionSource": 19,
"CommitDate": "2015-11-10T00:00:00.000Z",
"UncommittedChanges": 0
}
Major: 4
Minor: 10
Patch: 3
PreReleaseTag: test.19
PreReleaseTagWithDash: -test.19
PreReleaseLabel: test
PreReleaseLabelWithDash: -test
PreReleaseNumber: 19
WeightedPreReleaseNumber: 19
BuildMetaData:
FullBuildMetaData: Branch.feature/test.Sha.dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f
MajorMinorPatch: 4.10.3
SemVer: 4.10.3-test.19
AssemblySemVer: 4.10.3.0
AssemblySemFileVer: 4.10.3.0
FullSemVer: 4.10.3-test.19
InformationalVersion: 4.10.3-test.19+Branch.feature/test.Sha.dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f
BranchName: feature/test
EscapedBranchName: feature-test
Sha: dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f
ShortSha: dd2a29af
VersionSourceSha: 4.10.2
CommitsSinceVersionSource: 19
CommitDate: 2015-11-10
UncommittedChanges: 0
""";

using var fixture = new EmptyRepositoryFixture();
Expand Down Expand Up @@ -302,33 +296,31 @@ public void ConfigChangeInvalidatesCache(string configFileName)
public void NoCacheBypassesCache()
{
const string versionCacheFileContent = """
{
"Major": 4,
"Minor": 10,
"Patch": 3,
"PreReleaseTag": "test.19",
"PreReleaseTagWithDash": "-test.19",
"PreReleaseLabel": "test",
"PreReleaseLabelWithDash": "-test",
"PreReleaseNumber": 19,
"WeightedPreReleaseNumber": 19,
"BuildMetaData": null,
"FullBuildMetaData": "Branch.feature/test.Sha.dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f",
"MajorMinorPatch": "4.10.3",
"SemVer": "4.10.3-test.19",
"AssemblySemVer": "4.10.3.0",
"AssemblySemFileVer": "4.10.3.0",
"FullSemVer": "4.10.3-test.19",
"InformationalVersion": "4.10.3-test.19+Branch.feature/test.Sha.dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f",
"BranchName": "feature/test",
"EscapedBranchName": "feature-test",
"Sha": "dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f",
"ShortSha": "dd2a29af",
"VersionSourceSha": "4.10.2",
"CommitsSinceVersionSource": 19,
"CommitDate": "2015-11-10T00:00:00.000Z",
"UncommittedChanges": 0
}
Major: 4
Minor: 10
Patch: 3
PreReleaseTag: test.19
PreReleaseTagWithDash: -test.19
PreReleaseLabel: test
PreReleaseLabelWithDash: -test
PreReleaseNumber: 19
WeightedPreReleaseNumber: 19
BuildMetaData:
FullBuildMetaData: Branch.feature/test.Sha.dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f
MajorMinorPatch: 4.10.3
SemVer: 4.10.3-test.19
AssemblySemVer: 4.10.3.0
AssemblySemFileVer: 4.10.3.0
FullSemVer: 4.10.3-test.19
InformationalVersion: 4.10.3-test.19+Branch.feature/test.Sha.dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f
BranchName: feature/test
EscapedBranchName: feature-test
Sha: dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f
ShortSha: dd2a29af
VersionSourceSha: 4.10.2
CommitsSinceVersionSource: 19
CommitDate: 2015-11-10
UncommittedChanges: 0
""";

using var fixture = new EmptyRepositoryFixture();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,5 @@ private string PrepareCacheDirectory()
return cacheDir;
}

private static string GetCacheFileName(GitVersionCacheKey key, string cacheDir) => PathHelper.Combine(cacheDir, string.Concat(key.Value, ".json"));
private static string GetCacheFileName(GitVersionCacheKey key, string cacheDir) => PathHelper.Combine(cacheDir, string.Concat(key.Value, ".yml"));
}
6 changes: 5 additions & 1 deletion src/GitVersion.Output/GitVersion.Output.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
<EmbeddedResource Include="*\AddFormats\**\*.*" />
<EmbeddedResource Include="*\Templates\**\*.*" />
</ItemGroup>


<ItemGroup>
<PackageReference Include="YamlDotNet" />
</ItemGroup>

<ItemGroup>
<InternalsVisibleTo Include="GitVersion.App.Tests" />
<InternalsVisibleTo Include="GitVersion.Output.Tests" />
Expand Down
13 changes: 9 additions & 4 deletions src/GitVersion.Output/Serializer/VersionVariableSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,19 @@ private static GitVersionVariables FromDictionary(IEnumerable<KeyValuePair<strin

private GitVersionVariables FromFileInternal(string filePath)
{
var json = fileSystem.ReadAllText(filePath);
return FromJson(json);
using var stream = fileSystem.OpenRead(filePath);
using var reader = new StreamReader(stream);
var dictionary = new YamlDotNet.Serialization.Deserializer().Deserialize<Dictionary<string, string>>(reader);
return FromDictionary(dictionary);
}

private void ToFileInternal(GitVersionVariables gitVersionVariables, string filePath)
{
var json = ToJson(gitVersionVariables);
fileSystem.WriteAllText(filePath, json);
var dictionary = gitVersionVariables.ToDictionary(x => x.Key, x => x.Value);
using var stream = fileSystem.OpenWrite(filePath);
using var sw = new StreamWriter(stream);
var serializer = new YamlDotNet.Serialization.Serializer();
serializer.Serialize(sw, dictionary);
}

private static JsonSerializerOptions JsonSerializerOptions() => new() { WriteIndented = true, Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping, Converters = { new VersionVariablesJsonStringConverter() } };
Expand Down

0 comments on commit 030694e

Please sign in to comment.