From 8ae8818328839a437dc9b9906ef14cfa3bf73437 Mon Sep 17 00:00:00 2001 From: moomiji <35213527+moomiji@users.noreply.github.com> Date: Mon, 7 Oct 2024 22:18:15 +0800 Subject: [PATCH] fix: odds and ends - gh cli token - upload nightly build on non-default branch - failed to build on pr - failed to build on symbol embedded - more info outputs --- .github/workflows/ci.yml | 13 +++++++++++-- tools/Builder/Build.csx | 16 +++++++++------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 00acc89..4533f16 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -44,12 +44,21 @@ jobs: - run: dotnet tool install -g dotnet-script - id: build + env: + GH_TOKEN: ${{ github.token }} run: dotnet script ./tools/Builder/Build.csx - - uses: moomiji/host-nuget-on-github@v1 + - uses: actions/upload-artifact@v4 + with: + name: nupkgs + path: ./nupkgs + retention-days: 1 + + - if: github.ref == 'refs/heads/${{ steps.build.outputs.default_branch }}' && github.repository_owner_id == '161146573' + uses: moomiji/host-nuget-on-github@v1 with: base-uri: https://maaxyz.github.io/pkg/nuget/ - package-paths: nupkgs + package-paths: ./nupkgs feed-path: nuget force: true repository: MaaXYZ/pkg diff --git a/tools/Builder/Build.csx b/tools/Builder/Build.csx index fa8353e..da2941a 100644 --- a/tools/Builder/Build.csx +++ b/tools/Builder/Build.csx @@ -15,10 +15,11 @@ var d = DateTimeOffset.Parse(StartProcess($"gh run view {GITHUB_RUN_ID} --json c var dateTime = ((d.Year - 2000) * 1000 + d.Month * 50 + d.Day).ToString("D5"); var todayBuildTimes = StartProcess($"gh run list --workflow {GITHUB_WORKFLOW} --created {d.ToString("yyyy-MM-ddT00:00:00+08:00")}..{d.ToString("yyyy-MM-ddT23:59:59+08:00")} --limit 99 --json createdAt --jq length"); +var defaultBranch = StartProcess("gh repo view --json defaultBranchRef --jq .defaultBranchRef.name"); var branch = StartProcess("git rev-parse --abbrev-ref HEAD"); var commit = StartProcess("git rev-parse HEAD"); var isRelease = GITHUB_REF.StartsWith("refs/tags/v"); -var tag = StartProcess($"git describe --tags --match v* {GITHUB_REF}"); +var tag = StartProcess($"git describe --tags --match v*"); var tags = new List(tag.TrimStart('v').Split('-')); var version = tags.Count switch { @@ -40,11 +41,12 @@ var verStr = version.ToFullString(); TeeToGithubOutput( $"tag={tag}", $"version={verStr}", - $"is_release={isRelease}" + $"is_release={isRelease}", + $"default_branch={defaultBranch}" ); StartProcess( redirectStandardOutputToReturn: false, - cmd: $"dotnet build --configuration Release --no-restore \"-p:Version={verStr};RepositoryBranch={branch};RepositoryCommit={commit};{(isRelease ? string.Empty : "DebugType=embedded;")}\"" + cmd: $"dotnet build --configuration Release --no-restore -p:Version={verStr};RepositoryBranch={branch};RepositoryCommit={commit};{(isRelease ? string.Empty : "DebugType=embedded;IncludeSymbols=false")}" ); MoveNupkgFiles("nupkgs"); @@ -60,7 +62,7 @@ void TeeToGithubOutput(params string[] outputs) } string StartProcess(string cmd, bool redirectStandardOutputToReturn = true) { - Console.WriteLine(cmd); + Console.WriteLine(">> {0}", cmd); var cmds = cmd.Split(' ', 2, StringSplitOptions.TrimEntries); using var p = Process.Start(new ProcessStartInfo { @@ -71,9 +73,9 @@ string StartProcess(string cmd, bool redirectStandardOutputToReturn = true) p.WaitForExit(); if (p.ExitCode != 0) throw new InvalidOperationException($"ExitCode is {p.ExitCode} from {cmd}."); - return redirectStandardOutputToReturn - ? p.StandardOutput.ReadToEnd().Trim() - : string.Empty; + var output = redirectStandardOutputToReturn ? p.StandardOutput.ReadToEnd().Trim() : string.Empty; + Console.WriteLine(output); + return output; } void MoveNupkgFiles(string destDir) {