Skip to content

Commit

Permalink
fix: odds and ends
Browse files Browse the repository at this point in the history
- gh cli token
- upload nightly build on non-default branch
- failed to build on pr
- failed to build on symbol embedded
- more info outputs
  • Loading branch information
moomiji committed Oct 8, 2024
1 parent 1b6e1c1 commit 8ae8818
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
13 changes: 11 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 9 additions & 7 deletions tools/Builder/Build.csx
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>(tag.TrimStart('v').Split('-'));
var version = tags.Count switch
{
Expand All @@ -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");

Expand All @@ -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
{
Expand All @@ -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)
{
Expand Down

0 comments on commit 8ae8818

Please sign in to comment.