From 4ef03f916a1d4d46aab2495467bc4892fc7d510d Mon Sep 17 00:00:00 2001 From: Gregoire Poncelet Date: Thu, 10 Nov 2022 14:00:46 +0100 Subject: [PATCH 1/8] feat(Tests): add placehoder for environement variable --- .gitignore | 1 + .../IncrementVersionWithGitHintsHandlerTests.cs | 6 ++++-- .../GitIntegrationTests.LibGit2ServiceTests.cs | 13 +++++++++---- .../Setup/EnvironmentVariable.cs | 17 +++++++++++++++++ tst/Integration.Tests/Setup/GitSetup.cs | 4 +++- 5 files changed, 34 insertions(+), 7 deletions(-) create mode 100644 tst/Integration.Tests/Setup/EnvironmentVariable.cs diff --git a/.gitignore b/.gitignore index d47c237..07f1a78 100644 --- a/.gitignore +++ b/.gitignore @@ -357,3 +357,4 @@ MigrationBackup/ # Azure Functions local settings file local.settings.json +/tst/Integration.Tests/Setup/Local.cs diff --git a/tst/Integration.Tests/Handlers/IncrementVersionWithGitHintsHandlerTests.cs b/tst/Integration.Tests/Handlers/IncrementVersionWithGitHintsHandlerTests.cs index 43c706a..454fab4 100644 --- a/tst/Integration.Tests/Handlers/IncrementVersionWithGitHintsHandlerTests.cs +++ b/tst/Integration.Tests/Handlers/IncrementVersionWithGitHintsHandlerTests.cs @@ -27,8 +27,10 @@ public void Handle_WorksAsExpected() using var repo = new Repository(TestRepoDirectory); repo.Network.Remotes.Update("origin", updater => { - var token = Environment.GetEnvironmentVariable("GitHubAccessToken"); - var url = $"https://cbcrouse:{token}@github.com/cbcrouse/Versioning.NET.Tests.git"; + var actor = Environment.GetEnvironmentVariable("GitHubActor") ?? EnvironmentVariable.local.GitHubActor; + var token = Environment.GetEnvironmentVariable("GitHubAccessToken") ?? EnvironmentVariable.local.GitHubAccessToken; + var testRepo = Environment.GetEnvironmentVariable("GitHubTestRepoAddress") ?? EnvironmentVariable.local.GitHubTestRepoAddress ?? $"github.com/{actor}/Versioning.NET.Tests.git"; + var url = $"https://{actor}:{token}@{testRepo}"; updater.Url = url; updater.PushUrl = url; }); diff --git a/tst/Integration.Tests/Services/GitIntegrationTests.LibGit2ServiceTests.cs b/tst/Integration.Tests/Services/GitIntegrationTests.LibGit2ServiceTests.cs index d6b4f65..da92f49 100644 --- a/tst/Integration.Tests/Services/GitIntegrationTests.LibGit2ServiceTests.cs +++ b/tst/Integration.Tests/Services/GitIntegrationTests.LibGit2ServiceTests.cs @@ -1,5 +1,6 @@ using Domain.Entities; using Infrastructure.Services; +using Integration.Tests.Setup; using LibGit2Sharp; using System; using System.IO; @@ -150,8 +151,10 @@ public void CanPushRemoteBranch() using var repo = new Repository(TestRepoDirectory); repo.Network.Remotes.Update("origin", updater => { - var token = Environment.GetEnvironmentVariable("GitHubAccessToken"); - var url = $"https://cbcrouse:{token}@github.com/cbcrouse/Versioning.NET.Tests.git"; + var actor = Environment.GetEnvironmentVariable("GitHubActor") ?? EnvironmentVariable.local.GitHubActor; + var token = Environment.GetEnvironmentVariable("GitHubAccessToken") ?? EnvironmentVariable.local.GitHubAccessToken; + var testRepo = Environment.GetEnvironmentVariable("GitHubTestRepoAddress") ?? EnvironmentVariable.local.GitHubTestRepoAddress ?? $"github.com/{actor}/Versioning.NET.Tests.git"; + var url = $"https://{actor}:{token}@{testRepo}"; updater.Url = url; updater.PushUrl = url; }); @@ -183,8 +186,10 @@ public void CanPushRemoteTag() using var repo = new Repository(TestRepoDirectory); repo.Network.Remotes.Update("origin", updater => { - var token = Environment.GetEnvironmentVariable("GitHubAccessToken"); - var url = $"https://cbcrouse:{token}@github.com/cbcrouse/Versioning.NET.Tests.git"; + var actor = Environment.GetEnvironmentVariable("GitHubActor") ?? EnvironmentVariable.local.GitHubActor; + var token = Environment.GetEnvironmentVariable("GitHubAccessToken") ?? EnvironmentVariable.local.GitHubAccessToken; + var testRepo = Environment.GetEnvironmentVariable("GitHubTestRepoAddress") ?? EnvironmentVariable.local.GitHubTestRepoAddress ?? $"github.com/{actor}/Versioning.NET.Tests.git"; + var url = $"https://{actor}:{token}@{testRepo}"; updater.Url = url; updater.PushUrl = url; }); diff --git a/tst/Integration.Tests/Setup/EnvironmentVariable.cs b/tst/Integration.Tests/Setup/EnvironmentVariable.cs new file mode 100644 index 0000000..be48c73 --- /dev/null +++ b/tst/Integration.Tests/Setup/EnvironmentVariable.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Integration.Tests.Setup +{ + partial class EnvironmentVariable + { + public static EnvironmentVariable local = new EnvironmentVariable(); + + public string GitHubActor = null; + public string GitHubAccessToken = null; + public string GitHubTestRepoAddress = null; + } +} diff --git a/tst/Integration.Tests/Setup/GitSetup.cs b/tst/Integration.Tests/Setup/GitSetup.cs index 0594eec..3b5dd2c 100644 --- a/tst/Integration.Tests/Setup/GitSetup.cs +++ b/tst/Integration.Tests/Setup/GitSetup.cs @@ -19,8 +19,10 @@ public GitSetup() private void CloneTestRepository() { + var actor = Environment.GetEnvironmentVariable("GitHubActor") ?? EnvironmentVariable.local.GitHubActor; + var testRepo = Environment.GetEnvironmentVariable("GitHubTestRepoAddress") ?? EnvironmentVariable.local.GitHubTestRepoAddress ?? $"github.com/{actor}/Versioning.NET.Tests.git"; CreateTempDirectory(); - var gitPath = Repository.Clone("https://github.com/cbcrouse/Versioning.NET.Tests", _testRepoParentDirectory); + var gitPath = Repository.Clone($"https://{testRepo}", _testRepoParentDirectory); TestRepoDirectory = Directory.GetParent(gitPath)!.Parent!.FullName; } From 6bbba3f9be6eba72cebf64a74c63d05e947faee1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Poncelet=20Gr=C3=A9goire?= <102674985+0nary@users.noreply.github.com> Date: Thu, 10 Nov 2022 15:21:00 +0100 Subject: [PATCH 2/8] feat(dotnet.main.status): make test more flexible --- .github/workflows/dotnet.main.status.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/dotnet.main.status.yml b/.github/workflows/dotnet.main.status.yml index 052349b..10cd185 100644 --- a/.github/workflows/dotnet.main.status.yml +++ b/.github/workflows/dotnet.main.status.yml @@ -33,8 +33,9 @@ jobs: --collect:"XPlat Code Coverage" -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=opencover env: - GitHubAccessToken: ${{ secrets.GITHUBACCESSTOKEN }} - + GitHubActor: ${{ github.actor }} + GitHubAccessToken: ${{ secrets.GITHUB_TOKEN }} + #GitHubTestRepoAddress: "github.com/${{ github.actor }}/${{ github.repository }}.Tests.git" - name: Codecov # You may pin to the exact commit or the version. # uses: codecov/codecov-action@fcebab03f26c7530a22baa63f06b3e0515f0c7cd From 702854afb12553d4dae0d976f913e4d5db5a78ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Poncelet=20Gr=C3=A9goire?= <102674985+0nary@users.noreply.github.com> Date: Thu, 10 Nov 2022 15:22:16 +0100 Subject: [PATCH 3/8] feat(dotnet): make test more flexible --- .github/workflows/dotnet.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index cdf11e8..5f453fb 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -35,4 +35,6 @@ jobs: --collect:"XPlat Code Coverage" -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=opencover env: - GitHubAccessToken: ${{ secrets.GITHUBACCESSTOKEN }} + GitHubActor: ${{ github.actor }} + GitHubAccessToken: ${{ secrets.GITHUB_TOKEN }} + #GitHubTestRepoAddress: "github.com/${{ github.actor }}/${{ github.repository }}.Tests.git" From 63a22ce6c99a73c31635f91cb6ae9d186fd15c55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Poncelet=20Gr=C3=A9goire?= <102674985+0nary@users.noreply.github.com> Date: Thu, 10 Nov 2022 15:32:38 +0100 Subject: [PATCH 4/8] fix(dotnet.main.status): fix error replacing GITHUBACCESSTOKEN --- .github/workflows/dotnet.main.status.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dotnet.main.status.yml b/.github/workflows/dotnet.main.status.yml index 10cd185..dbd1ed3 100644 --- a/.github/workflows/dotnet.main.status.yml +++ b/.github/workflows/dotnet.main.status.yml @@ -34,7 +34,7 @@ jobs: -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=opencover env: GitHubActor: ${{ github.actor }} - GitHubAccessToken: ${{ secrets.GITHUB_TOKEN }} + GitHubAccessToken: ${{ GITHUBACCESSTOKEN }} #GitHubTestRepoAddress: "github.com/${{ github.actor }}/${{ github.repository }}.Tests.git" - name: Codecov # You may pin to the exact commit or the version. From f725d5521b50ecca267d3b89582fc721e3b84f42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Poncelet=20Gr=C3=A9goire?= <102674985+0nary@users.noreply.github.com> Date: Thu, 10 Nov 2022 15:33:15 +0100 Subject: [PATCH 5/8] fix(dotnet): fix error replacing GITHUBACCESSTOKEN --- .github/workflows/dotnet.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 5f453fb..e0e72e7 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -36,5 +36,5 @@ jobs: -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=opencover env: GitHubActor: ${{ github.actor }} - GitHubAccessToken: ${{ secrets.GITHUB_TOKEN }} + GitHubAccessToken: ${{ secrets.GITHUBACCESSTOKEN }} #GitHubTestRepoAddress: "github.com/${{ github.actor }}/${{ github.repository }}.Tests.git" From 03336dc24f9fe525b20a8bd3b565b3cf998f66f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Poncelet=20Gr=C3=A9goire?= <102674985+0nary@users.noreply.github.com> Date: Thu, 10 Nov 2022 15:34:36 +0100 Subject: [PATCH 6/8] fix(dotnet.main.status): fix error removing secerts --- .github/workflows/dotnet.main.status.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dotnet.main.status.yml b/.github/workflows/dotnet.main.status.yml index dbd1ed3..087641e 100644 --- a/.github/workflows/dotnet.main.status.yml +++ b/.github/workflows/dotnet.main.status.yml @@ -34,7 +34,7 @@ jobs: -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=opencover env: GitHubActor: ${{ github.actor }} - GitHubAccessToken: ${{ GITHUBACCESSTOKEN }} + GitHubAccessToken: ${{ secrets.GITHUBACCESSTOKEN }} #GitHubTestRepoAddress: "github.com/${{ github.actor }}/${{ github.repository }}.Tests.git" - name: Codecov # You may pin to the exact commit or the version. From a5b4da0bb0e17a04a839673ee2b2e902c77ae643 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Poncelet=20Gr=C3=A9goire?= <102674985+0nary@users.noreply.github.com> Date: Mon, 14 Nov 2022 09:24:03 +0100 Subject: [PATCH 7/8] fix(dotnet.yml): replace actor by repository_owner --- .github/workflows/dotnet.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index e0e72e7..eaeba6b 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -35,6 +35,6 @@ jobs: --collect:"XPlat Code Coverage" -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=opencover env: - GitHubActor: ${{ github.actor }} + GitHubActor: ${{ github.repository_owner }} GitHubAccessToken: ${{ secrets.GITHUBACCESSTOKEN }} - #GitHubTestRepoAddress: "github.com/${{ github.actor }}/${{ github.repository }}.Tests.git" + #GitHubTestRepoAddress: "github.com/${{ github.repository }}.Tests.git" From 35333b4721b53d3bd2d3a904ce3c4326ad68c6d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Poncelet=20Gr=C3=A9goire?= <102674985+0nary@users.noreply.github.com> Date: Mon, 14 Nov 2022 09:24:53 +0100 Subject: [PATCH 8/8] fix(dotnet.main.status.yml): replace actor by repository_owner --- .github/workflows/dotnet.main.status.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/dotnet.main.status.yml b/.github/workflows/dotnet.main.status.yml index 087641e..b340349 100644 --- a/.github/workflows/dotnet.main.status.yml +++ b/.github/workflows/dotnet.main.status.yml @@ -33,9 +33,9 @@ jobs: --collect:"XPlat Code Coverage" -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=opencover env: - GitHubActor: ${{ github.actor }} + GitHubActor: ${{ github.repository_owner }} GitHubAccessToken: ${{ secrets.GITHUBACCESSTOKEN }} - #GitHubTestRepoAddress: "github.com/${{ github.actor }}/${{ github.repository }}.Tests.git" + #GitHubTestRepoAddress: "github.com/${{ github.repository }}.Tests.git" - name: Codecov # You may pin to the exact commit or the version. # uses: codecov/codecov-action@fcebab03f26c7530a22baa63f06b3e0515f0c7cd