diff --git a/.github/workflows/alpha.yml b/.github/workflows/alpha.yml new file mode 100644 index 00000000..67ed6088 --- /dev/null +++ b/.github/workflows/alpha.yml @@ -0,0 +1,46 @@ +name: Snap Hutao Alpha +on: + workflow_dispatch: + push: + branches: + - main + - develop + paths-ignore: + - '.gitattributes' + - '.github/**' + - '.gitignore' + - '.gitmodules' + - '**.md' + - 'LICENSE' + +jobs: + build: + runs-on: self-hosted + 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 + id: cake + shell: pwsh + run: dotnet tool restore && dotnet cake + env: + VERSION_API_TOKEN: ${{ secrets.VERSION_API_TOKEN }} + + - name: Sign Msix + 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.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 26a16afc..0fdc7daf 100644 --- a/build.cake +++ b/build.cake @@ -48,15 +48,35 @@ if (AzurePipelines.IsRunningOnAzurePipelines) AzurePipelines.Commands.SetVariable("version", version); } +else if (GitHubActions.IsRunningOnGitHubActions) +{ + 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"); + 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; 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}"); } @@ -72,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") @@ -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 @@ -155,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"); }