-
-
Notifications
You must be signed in to change notification settings - Fork 230
chore: Added a little dev script to help contributors #4793
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jamescrosswell
wants to merge
12
commits into
main
Choose a base branch
from
dev-scripts
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 8 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
21f50cc
Added a simple dev script to replicate my zshrc file
jamescrosswell 4f48ec5
Made default solution platform dependent
jamescrosswell c060c65
Changed to top level statements
jamescrosswell 13373eb
Fixed dry-run
jamescrosswell 299beff
Fixed comment
jamescrosswell 28bfdbb
Add --init to submodule update commands
jamescrosswell f871520
Merge remote-tracking branch 'origin/main' into dev-scripts
jamescrosswell 2bc70cf
Added an `aiup` command to initialise skills in a fresh repo/worktree
jamescrosswell 31dbe11
Review feedback
jamescrosswell 64c0d53
review feedback
jamescrosswell 4d3b703
Merge remote-tracking branch 'origin/main' into dev-scripts
jamescrosswell 1b2d34a
fix: Use where.exe on Windows and redirect streams in IsCommandAvaila…
jamescrosswell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,218 @@ | ||
| #!/usr/bin/env dotnet | ||
| #:package Cocona@2.2.0 | ||
|
|
||
| #nullable enable | ||
|
|
||
| using System.Diagnostics; | ||
| using System.Runtime.InteropServices; | ||
| using Cocona; | ||
|
|
||
| // Simple dev helper CLI implemented as a .NET file-based app using Cocona. | ||
| // Usage examples (run from repo root): | ||
| // ./dev.cs --help | ||
| // ./dev.cs cleanslate | ||
| // ./dev.cs cleanslate Sentry-CI-Build-macOS.slnf | ||
| // ./dev.cs subup | ||
| // ./dev.cs wrest | ||
| // ./dev.cs nrest | ||
| // ./dev.cs aiup | ||
| // ./dev.cs cleanslate --dry-run | ||
| // | ||
| // This is intended to be run from the repo root so that git/dotnet | ||
| // commands operate on this repository. | ||
|
|
||
| var app = CoconaApp.Create(); | ||
|
|
||
| app.AddCommands<DevCommands>(); | ||
|
|
||
| app.Run(); | ||
|
|
||
| // ----------------- Options & Commands ----------------- | ||
|
|
||
| public class GlobalOptions : ICommandParameterSet | ||
| { | ||
| [Option("dry-run", new[] { 'n' }, Description = "Print commands instead of executing them.")] | ||
| public bool DryRun { get; set; } | ||
| } | ||
|
|
||
| public class DevCommands | ||
| { | ||
| [Command("cleanslate", Description = "Clean repo, update submodules, and restore the solution.")] | ||
| public async Task<int> CleanSlateAsync( | ||
| [Argument("solution", Description = "Solution file to restore. Defaults to platform-specific CI solution if omitted.")] string? solution = null, | ||
| GlobalOptions options = default!) | ||
| { | ||
| solution ??= DevConfig.DefaultSolution; | ||
|
|
||
| Console.WriteLine($"[dev] cleanslate for solution: {solution}"); | ||
|
|
||
| var steps = new (string Description, string FileName, string Arguments)[] | ||
| { | ||
| ("git clean", "git", "clean -dfx"), | ||
| ("git submodule update", "git", "submodule update --init --recursive"), | ||
| ("dotnet restore", "dotnet", $"restore \"{solution}\""), | ||
| ("npx @sentry/dotagents install", "npx", "@sentry/dotagents install") | ||
| }; | ||
|
|
||
| foreach (var (description, fileName, arguments) in steps) | ||
| { | ||
| int code = await RunStepAsync(description, fileName, arguments, options.DryRun); | ||
| if (code != 0) | ||
| { | ||
| Console.Error.WriteLine($"[dev] Step '{description}' failed with exit code {code}."); | ||
| return code; | ||
| } | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| [Command("subup", Description = "Update git submodules recursively.")] | ||
| public Task<int> SubmoduleUpdateAsync(GlobalOptions options = default!) | ||
| { | ||
| Console.WriteLine("[dev] Updating git submodules (recursive)"); | ||
| return RunStepAsync("git submodule update", "git", "submodule update --init --recursive", options.DryRun); | ||
| } | ||
|
|
||
| [Command("wrest", Description = "Run 'dotnet workload restore' (with sudo on Unix if available).")] | ||
| public async Task<int> WorkloadRestoreAsync(GlobalOptions options = default!) | ||
| { | ||
| Console.WriteLine("[dev] Restoring dotnet workloads"); | ||
|
|
||
| if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) | ||
| { | ||
| // No sudo on Windows | ||
| return await RunStepAsync("dotnet workload restore", "dotnet", "workload restore", options.DryRun); | ||
| } | ||
|
|
||
| bool sudoAvailable = await IsCommandAvailableAsync("sudo"); | ||
|
|
||
| if (sudoAvailable) | ||
| { | ||
| return await RunStepAsync("sudo dotnet workload restore", "sudo", "dotnet workload restore", options.DryRun); | ||
| } | ||
|
|
||
| Console.WriteLine("[dev] 'sudo' not found; running 'dotnet workload restore' without sudo."); | ||
| return await RunStepAsync("dotnet workload restore", "dotnet", "workload restore", options.DryRun); | ||
| } | ||
|
|
||
| [Command("aiup", Description = "Install/update AI agent files via @sentry/dotagents.")] | ||
| public Task<int> AiUpdateAsync(GlobalOptions options = default!) | ||
| { | ||
| Console.WriteLine("[dev] Installing/updating AI agent files"); | ||
| return RunStepAsync("npx @sentry/dotagents install", "npx", "@sentry/dotagents install", options.DryRun); | ||
| } | ||
|
|
||
| [Command("nrest", Description = "Restore the default CI solution.")] | ||
| public Task<int> SolutionRestoreAsync( | ||
| [Argument("solution", Description = "Solution file to restore. Defaults to platform-specific CI solution if omitted.")] string? solution = null, | ||
| GlobalOptions options = default!) | ||
| { | ||
| solution ??= DevConfig.DefaultSolution; | ||
| Console.WriteLine($"[dev] Restoring solution: {solution}"); | ||
| return RunStepAsync("dotnet restore", "dotnet", $"restore \"{solution}\"", options.DryRun); | ||
| } | ||
|
|
||
| private static async Task<int> RunStepAsync(string description, string fileName, string arguments, bool dryRun) | ||
| { | ||
| Console.WriteLine($"==> {description}: {fileName} {arguments}"); | ||
| return await RunProcessAsync(fileName, arguments, dryRun); | ||
| } | ||
|
|
||
| private static async Task<int> RunProcessAsync(string fileName, string arguments, bool dryRun) | ||
| { | ||
| if (dryRun) | ||
| { | ||
| Console.WriteLine($"[DRY RUN] {fileName} {arguments}"); | ||
| return 0; | ||
| } | ||
|
|
||
| var startInfo = new ProcessStartInfo | ||
| { | ||
| FileName = fileName, | ||
| Arguments = arguments, | ||
| UseShellExecute = false, | ||
| RedirectStandardOutput = false, | ||
| RedirectStandardError = false, | ||
| CreateNoWindow = false, | ||
| }; | ||
cursor[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| using var process = new Process { StartInfo = startInfo }; | ||
|
|
||
| try | ||
| { | ||
| if (!process.Start()) | ||
| { | ||
| Console.Error.WriteLine($"[dev] Failed to start process: {fileName}"); | ||
| return 1; | ||
| } | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| Console.Error.WriteLine($"[dev] Exception starting process '{fileName}': {ex.Message}"); | ||
| return 1; | ||
| } | ||
|
|
||
| await process.WaitForExitAsync(); | ||
| return process.ExitCode; | ||
| } | ||
|
|
||
| private static async Task<bool> IsCommandAvailableAsync(string command) | ||
| { | ||
| if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) | ||
| { | ||
| return await Task.FromResult(true); | ||
| } | ||
cursor[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| var startInfo = new ProcessStartInfo | ||
| { | ||
| FileName = "which", | ||
| Arguments = command, | ||
| UseShellExecute = false, | ||
| RedirectStandardOutput = true, | ||
| RedirectStandardError = true, | ||
| CreateNoWindow = true, | ||
| }; | ||
cursor[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| using var process = new Process { StartInfo = startInfo }; | ||
|
|
||
| try | ||
| { | ||
| if (!process.Start()) | ||
| { | ||
| return false; | ||
| } | ||
| } | ||
| catch | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| await process.WaitForExitAsync(); | ||
| return process.ExitCode == 0; | ||
cursor[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
|
|
||
|
|
||
| // Central configuration/constants for the dev script. | ||
| public static class DevConfig | ||
| { | ||
| public static string DefaultSolution | ||
| { | ||
| get | ||
| { | ||
| if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) | ||
| { | ||
| return "Sentry-CI-Build-Windows.slnf"; | ||
| } | ||
|
|
||
| if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) | ||
| { | ||
| return "Sentry-CI-Build-Linux.slnf"; | ||
| } | ||
|
|
||
| // Fallback: macOS solution | ||
| return "Sentry-CI-Build-macOS.slnf"; | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.