From 0b7b259d2f7c9fd7d6650d4ab0990013f6f0815a Mon Sep 17 00:00:00 2001 From: qhy040404 Date: Tue, 12 Dec 2023 18:14:23 +0800 Subject: [PATCH 1/3] migrate to GitHub actions --- .github/workflows/alpha.yml | 47 +++++++++++++++++++++++++++++++++++++ build.cake | 22 ++++++++++++++++- 2 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/alpha.yml diff --git a/.github/workflows/alpha.yml b/.github/workflows/alpha.yml new file mode 100644 index 00000000..b3726b2d --- /dev/null +++ b/.github/workflows/alpha.yml @@ -0,0 +1,47 @@ +name: Snap Hutao Alpha +on: + push: + branches: + - main + - develop + paths-ignore: + - '.gitattributes' + - '.github/**' + - '.gitignore' + - '.gitmodules' + - '**.md' + - 'LICENSE' + +jobs: + publish-alpha: + runs-on: windows-latest + steps: + - name: Checkout + uses: actions/checkout@v4.1.1 + + - name: Setup .NET + uses: actions/setup-dotnet@v4.0.0 + with: + dotnet-version: 8.0 + + - name: Cake + shell: pwsh + run: dotnet tool restore && dotnet cake + env: + VERSION_API_TOKEN: ${{ secrets.VERSION_API_TOKEN }} + + - name: Sign Msix + id: signing + uses: skymatic/code-sign-action@v1 + with: + certificate: ${{ secrets.CERTIFICATE }} + password: ${{ secrets.PW }} + certificatename: DGP Studio CI + folder: src/output + + - name: Upload signed msix + if: success() + uses: actions/upload-artifact@v3 + with: + name: Snap.Hutao.${{ steps.signing.outputs.version }} + path: ${{ github.workspace }}/app/build/outputs/apk/foss/release diff --git a/build.cake b/build.cake index 26a16afc..1aec1425 100644 --- a/build.cake +++ b/build.cake @@ -48,6 +48,26 @@ if (AzurePipelines.IsRunningOnAzurePipelines) AzurePipelines.Commands.SetVariable("version", version); } +else if (GitHubActions.IsRunningOnGitHubActions) +{ + repoDir = GitHubActions.Environment.Runner.Workspace.FullPath; + outputPath = System.IO.Path.Combine(repoDir, "src", "output"); + + var versionAuth = HasEnvironmentVariable("VERSION_API_TOKEN") ? EnvironmentVariable("VERSION_API_TOKEN") : throw new Exception("Cannot find VERSION_API_TOKEN"); + version = HttpGet( + "https://internal.snapgenshin.cn/BuildIntergration/RequestNewVersion", + new HttpSettings + { + Headers = new Dictionary + { + { "Authorization", versionAuth } + } + } + ); + Information($"Version: {version}"); + + GitHubActions.Commands.SetOutputParameter("version", version); +} else if (AppVeyor.IsRunningOnAppVeyor) { repoDir = AppVeyor.Environment.Build.Folder; @@ -86,7 +106,7 @@ Task("Generate AppxManifest") var content = System.IO.File.ReadAllText(manifest); - if (AzurePipelines.IsRunningOnAzurePipelines) + if (AzurePipelines.IsRunningOnAzurePipelines || GitHubActions.IsRunningOnGitHubActions) { Information("Using CI configuraion"); content = content From fd2e9980c708ea69583a50185f1689303ac846f8 Mon Sep 17 00:00:00 2001 From: qhy040404 Date: Tue, 12 Dec 2023 19:24:52 +0800 Subject: [PATCH 2/3] fix --- .github/workflows/alpha.yml | 19 +++++++++---------- build.cake | 20 ++++++++++---------- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/.github/workflows/alpha.yml b/.github/workflows/alpha.yml index b3726b2d..433067d5 100644 --- a/.github/workflows/alpha.yml +++ b/.github/workflows/alpha.yml @@ -1,5 +1,6 @@ name: Snap Hutao Alpha on: + workflow_dispatch: push: branches: - main @@ -14,7 +15,7 @@ on: jobs: publish-alpha: - runs-on: windows-latest + runs-on: self-hosted steps: - name: Checkout uses: actions/checkout@v4.1.1 @@ -25,23 +26,21 @@ jobs: dotnet-version: 8.0 - name: Cake + id: cake shell: pwsh run: dotnet tool restore && dotnet cake env: VERSION_API_TOKEN: ${{ secrets.VERSION_API_TOKEN }} - name: Sign Msix - id: signing - uses: skymatic/code-sign-action@v1 - with: - certificate: ${{ secrets.CERTIFICATE }} - password: ${{ secrets.PW }} - certificatename: DGP Studio CI - folder: src/output + shell: pwsh + run: | + [System.Convert]::FromBase64String("${{ secrets.CERTIFICATE }}") | Set-Content -AsByteStream temp.pfx + signtool.exe sign /debug /v /a /fd SHA256 /f temp.pfx /p ${{ secrets.PW }} ${{ github.workspace }}\src\output\Snap.Hutao.Alpha-${{ steps.cake.outputs.version }}.msix - name: Upload signed msix if: success() uses: actions/upload-artifact@v3 with: - name: Snap.Hutao.${{ steps.signing.outputs.version }} - path: ${{ github.workspace }}/app/build/outputs/apk/foss/release + name: Snap.Hutao.Alpha-${{ steps.cake.outputs.version }} + path: ${{ github.workspace }}/src/output/Snap.Hutao.Alpha-${{ steps.cake.outputs.version }}.msix diff --git a/build.cake b/build.cake index 1aec1425..0fdc7daf 100644 --- a/build.cake +++ b/build.cake @@ -50,7 +50,7 @@ if (AzurePipelines.IsRunningOnAzurePipelines) } else if (GitHubActions.IsRunningOnGitHubActions) { - repoDir = GitHubActions.Environment.Runner.Workspace.FullPath; + repoDir = GitHubActions.Environment.Workflow.Workspace.FullPath; outputPath = System.IO.Path.Combine(repoDir, "src", "output"); var versionAuth = HasEnvironmentVariable("VERSION_API_TOKEN") ? EnvironmentVariable("VERSION_API_TOKEN") : throw new Exception("Cannot find VERSION_API_TOKEN"); @@ -74,9 +74,9 @@ else if (AppVeyor.IsRunningOnAppVeyor) outputPath = System.IO.Path.Combine(repoDir, "src", "output"); version = XmlPeek(manifest, "appx:Package/appx:Identity/@Version", new XmlPeekSettings - { - Namespaces = new Dictionary { { "appx", "http://schemas.microsoft.com/appx/manifest/foundation/windows10" } } - })[..^2]; + { + Namespaces = new Dictionary { { "appx", "http://schemas.microsoft.com/appx/manifest/foundation/windows10" } } + })[..^2]; Information($"Version: {version}"); } @@ -92,11 +92,11 @@ Task("NuGet Restore") var nugetConfig = System.IO.Path.Combine(repoDir, "NuGet.Config"); DotNetRestore(project, new DotNetRestoreSettings - { - Verbosity = DotNetVerbosity.Detailed, - Interactive = false, - ConfigFile = nugetConfig - }); + { + Verbosity = DotNetVerbosity.Detailed, + Interactive = false, + ConfigFile = nugetConfig + }); }); Task("Generate AppxManifest") @@ -175,7 +175,7 @@ Task("Build MSIX") .Does(() => { var arguments = "arguments"; - if (AzurePipelines.IsRunningOnAzurePipelines) + if (AzurePipelines.IsRunningOnAzurePipelines || GitHubActions.IsRunningOnGitHubActions) { arguments = "pack /d " + binPath + " /p " + System.IO.Path.Combine(outputPath, $"Snap.Hutao.Alpha-{version}.msix"); } From be6ad70ad6013f1a5f57c894c88cf5c88de47856 Mon Sep 17 00:00:00 2001 From: qhy040404 Date: Tue, 12 Dec 2023 22:02:54 +0800 Subject: [PATCH 3/3] misc --- .github/workflows/alpha.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/alpha.yml b/.github/workflows/alpha.yml index 433067d5..67ed6088 100644 --- a/.github/workflows/alpha.yml +++ b/.github/workflows/alpha.yml @@ -14,7 +14,7 @@ on: - 'LICENSE' jobs: - publish-alpha: + build: runs-on: self-hosted steps: - name: Checkout