diff --git a/.github/workflows/renumber-sections.yaml b/.github/workflows/renumber-sections.yaml index 13f4ecba7..41bd91418 100644 --- a/.github/workflows/renumber-sections.yaml +++ b/.github/workflows/renumber-sections.yaml @@ -29,9 +29,28 @@ jobs: - name: Setup .NET 8.0 uses: actions/setup-dotnet@v1 with: - dotnet-version: 8.0.x + dotnet-version: 9.0.x - name: Run section renumbering dry run + id: section-renumber run: | cd tools ./run-section-renumber.sh + + - name: Trigger Workflow + uses: actions/github-script@v7 + with: + script: | + github.rest.actions.createWorkflowDispatch({ + owner: "dotnet", + repo: "csharpstandard", + workflow_id: 'report-status.yml', + ref: '${{ github.head_ref }}', + inputs: { + "head_sha": '${{ steps.section-renumber.output.head_sha }}', + "name": '${{ steps.section-renumber.output.check_name }}', + "conclusion": '${{ steps.section-renumber.output.conclusion }}', + "summary": '${{ steps.section-renumber.output.summary }}', + "annotations": '${{ steps.section-renumber.output.annotations }}' + } + }) diff --git a/.github/workflows/report-status.yml b/.github/workflows/report-status.yml new file mode 100644 index 000000000..63b71b144 --- /dev/null +++ b/.github/workflows/report-status.yml @@ -0,0 +1,26 @@ +name: Report status + +# Triggers the workflow when a workflow that generates status completes +on: + workflow_run: + workflows: ["Renumber standard TOC"] + types: + - completed + +jobs: + report-status: + runs-on: ubuntu-latest + permissions: + checks: write + pull-requests: write + steps: + - uses: LouisBrunner/checks-action@v2.0.0 + with: + token: ${{ secrets.GITHUB_TOKEN }} + sha: ${{ inputs.head_sha }} + name: ${{ inputs.check_name }} + conclusion: ${{ inputs.conclusion}} + # output.summary is required with actions! + output: | + {"summary":"${{inputs.summary}}"} + annotations: ${{ inputs.annotations }} diff --git a/.github/workflows/smart-quotes.yaml b/.github/workflows/smart-quotes.yaml index 551084179..f2746bf63 100644 --- a/.github/workflows/smart-quotes.yaml +++ b/.github/workflows/smart-quotes.yaml @@ -24,10 +24,10 @@ jobs: - name: Check out our repo uses: actions/checkout@v2 - - name: Setup .NET 8.0 + - name: Setup .NET 9.0 uses: actions/setup-dotnet@v1 with: - dotnet-version: 8.0.x + dotnet-version: 9.0.x - name: Smarten quotes id: smarten-quote diff --git a/.github/workflows/test-examples.yaml b/.github/workflows/test-examples.yaml index 727e996fb..f5f20d3f7 100644 --- a/.github/workflows/test-examples.yaml +++ b/.github/workflows/test-examples.yaml @@ -32,12 +32,12 @@ jobs: # 8.0 for the tools themselves. (The closer we # are to the target language version we're standardising, # the better.) - - name: Setup .NET 6.0 and 8.0 + - name: Setup .NET 6.0 and 9.0 uses: actions/setup-dotnet@v3 with: dotnet-version: | 6.0.x - 8.0.x + 9.0.x - name: Extract and validate tests run: | diff --git a/.github/workflows/tools-tests.yaml b/.github/workflows/tools-tests.yaml index ff3790536..0ee087ebf 100644 --- a/.github/workflows/tools-tests.yaml +++ b/.github/workflows/tools-tests.yaml @@ -25,10 +25,10 @@ jobs: - name: Check out our repo uses: actions/checkout@v2 - - name: Setup .NET 8.0 + - name: Setup .NET 9.0 uses: actions/setup-dotnet@v1 with: - dotnet-version: 8.0.x + dotnet-version: 9.0.x - name: Run all tests run: | diff --git a/.github/workflows/update-on-merge.yaml b/.github/workflows/update-on-merge.yaml index 56fe69db8..1cc7a277f 100644 --- a/.github/workflows/update-on-merge.yaml +++ b/.github/workflows/update-on-merge.yaml @@ -30,10 +30,10 @@ jobs: - name: Check out our repo uses: actions/checkout@v2 - - name: Setup .NET 8.0 + - name: Setup .NET 9.0 uses: actions/setup-dotnet@v1 with: - dotnet-version: 8.0.x + dotnet-version: 9.0.x - name: Set up JDK 15 uses: actions/setup-java@v1 diff --git a/.github/workflows/word-converter.yaml b/.github/workflows/word-converter.yaml index 696f998fd..939e47160 100644 --- a/.github/workflows/word-converter.yaml +++ b/.github/workflows/word-converter.yaml @@ -26,10 +26,10 @@ jobs: - name: Check out our repo uses: actions/checkout@v2 - - name: Setup .NET 8.0 + - name: Setup .NET 9.0 uses: actions/setup-dotnet@v1 with: - dotnet-version: 8.0.x + dotnet-version: 9.0.x - name: Run converter run: | diff --git a/tools/ExampleTester/ExampleTester.csproj b/tools/ExampleTester/ExampleTester.csproj index a6923d2bd..7b1e485a6 100644 --- a/tools/ExampleTester/ExampleTester.csproj +++ b/tools/ExampleTester/ExampleTester.csproj @@ -1,8 +1,8 @@ - + Exe - net8.0 + net9.0 enable enable diff --git a/tools/MarkdownConverter.Tests/MarkdownConverter.Tests.csproj b/tools/MarkdownConverter.Tests/MarkdownConverter.Tests.csproj index 2e30c08b4..8390ef41c 100644 --- a/tools/MarkdownConverter.Tests/MarkdownConverter.Tests.csproj +++ b/tools/MarkdownConverter.Tests/MarkdownConverter.Tests.csproj @@ -1,7 +1,7 @@  - net8.0 + net9.0 enable enable false diff --git a/tools/MarkdownConverter/MarkdownConverter.csproj b/tools/MarkdownConverter/MarkdownConverter.csproj index eb0bc9534..cc1056e1d 100644 --- a/tools/MarkdownConverter/MarkdownConverter.csproj +++ b/tools/MarkdownConverter/MarkdownConverter.csproj @@ -2,7 +2,7 @@ Exe - net8.0 + net9.0 enable enable NU1701 diff --git a/tools/StandardAnchorTags/Program.cs b/tools/StandardAnchorTags/Program.cs index 6c0f77449..89b646b25 100644 --- a/tools/StandardAnchorTags/Program.cs +++ b/tools/StandardAnchorTags/Program.cs @@ -61,7 +61,7 @@ static async Task Main(string owner, string repo, bool dryrun =false) { if ((token is not null) && (headSha is not null)) { - await logger.BuildCheckRunResult(token, owner, repo, headSha); + var annotations = await logger.BuildCheckRunResult(token, owner, repo, headSha); } } return logger.Success ? 0 : 1; diff --git a/tools/StandardAnchorTags/StandardAnchorTags.csproj b/tools/StandardAnchorTags/StandardAnchorTags.csproj index 8157f79fc..ddbfffd35 100644 --- a/tools/StandardAnchorTags/StandardAnchorTags.csproj +++ b/tools/StandardAnchorTags/StandardAnchorTags.csproj @@ -1,8 +1,8 @@ - + Exe - net8.0 + net9.0 enable enable diff --git a/tools/Utilities/CustomSerializer.cs b/tools/Utilities/CustomSerializer.cs new file mode 100644 index 000000000..2d2705ea6 --- /dev/null +++ b/tools/Utilities/CustomSerializer.cs @@ -0,0 +1,12 @@ +using System.Text.Json.Serialization; +using Octokit; + +namespace Utilities; + +// This defines the custom serializer for the annotations block. +// That enables the status checks to write the annotations to +// the GitHub Actions output. That lets a subsequent action read +// these annotations in a different security context and write +// them to the PR. +[JsonSerializable(typeof(IList))] +public sealed partial class JsonCheckRunAnnotationSerializerContext : JsonSerializerContext; diff --git a/tools/Utilities/StatusCheckLogger.cs b/tools/Utilities/StatusCheckLogger.cs index 2feaeb65c..73c7d90b2 100644 --- a/tools/Utilities/StatusCheckLogger.cs +++ b/tools/Utilities/StatusCheckLogger.cs @@ -1,4 +1,7 @@ using Octokit; +using Actions.Core.Extensions; +using Actions.Core.Services; +using Microsoft.Extensions.DependencyInjection; namespace Utilities; @@ -24,6 +27,17 @@ public record StatusCheckMessage(string file, int StartLine, int EndLine, string /// The name of the tool that is running the check public class StatusCheckLogger(string pathToRoot, string toolName) { + private Lazy _gitHubCoreService = new(() => InitializeCoreService()); + + private static ICoreService InitializeCoreService() + { + using var provider = new ServiceCollection() + .AddGitHubActionsCore() + .BuildServiceProvider(); + + return provider.GetRequiredService(); + } + private List annotations = []; public bool Success { get; private set; } = true; @@ -153,13 +167,17 @@ public void ExitOnFailure(StatusCheckMessage d) /// The GitHub repo name /// The head sha when running as a GitHub action /// The full check run result object - public async Task BuildCheckRunResult(string token, string owner, string repo, string sha) + public async Task> BuildCheckRunResult(string token, string owner, string repo, string sha) { + + var title = $"{toolName} Check Run results"; + var summary = $"{toolName} result is {(Success ? "success" : "failure")} with {annotations.Count} diagnostics."; + NewCheckRun result = new(toolName, sha) { Status = CheckStatus.Completed, Conclusion = Success ? CheckConclusion.Success : CheckConclusion.Failure, - Output = new($"{toolName} Check Run results", $"{toolName} result is {(Success ? "success" : "failure")} with {annotations.Count} diagnostics.") + Output = new(title, summary) { Annotations = annotations } @@ -182,5 +200,43 @@ public async Task BuildCheckRunResult(string token, string owner, string repo, s Console.WriteLine("Exception details:"); Console.WriteLine(e); } + try + { + var core = _gitHubCoreService.Value; + + await core.GroupAsync("Writing run outputs", async () => + { + await core.SetOutputAsync("check_name", title, JsonCheckRunAnnotationSerializerContext.Default.String); + + core.WriteInfo("Set check_name output"); + + await core.SetOutputAsync("conclusion", Success ? "success" : "failure", JsonCheckRunAnnotationSerializerContext.Default.String); + + core.WriteInfo("Set conclusion output"); + + await core.SetOutputAsync("summary", summary, JsonCheckRunAnnotationSerializerContext.Default.String); + + core.WriteInfo("Set summary output"); + + await core.SetOutputAsync("head_sha", sha, JsonCheckRunAnnotationSerializerContext.Default.String); + + core.WriteInfo("Set head_sha output"); + + await core.SetOutputAsync("annotations", annotations, JsonCheckRunAnnotationSerializerContext.Default.IListNewCheckRunAnnotation); + + core.WriteInfo("Set annotations output"); + return true; // to get a natural lambda type. + }); + // Now, we have a file named annotations. + } + // If the token does not have the correct permissions, we will get a 403 + // Once running on a branch on the dotnet org, this should work correctly. + catch (ForbiddenException e) + { + Console.WriteLine("===== WARNING: Could not create a check run.====="); + Console.WriteLine("Exception details:"); + Console.WriteLine(e); + } + return annotations; } } diff --git a/tools/Utilities/Utilities.csproj b/tools/Utilities/Utilities.csproj index b04c9d095..d811a0f28 100644 --- a/tools/Utilities/Utilities.csproj +++ b/tools/Utilities/Utilities.csproj @@ -1,12 +1,14 @@ - + - net8.0 + net9.0 enable enable + + diff --git a/tools/run-section-renumber.sh b/tools/run-section-renumber.sh index bb9b38584..e22e22b61 100755 --- a/tools/run-section-renumber.sh +++ b/tools/run-section-renumber.sh @@ -8,5 +8,6 @@ dotnet run --project $PROJECT -- --owner dotnet --repo csharpstandard if [ -n "$GITHUB_OUTPUT" ] then - echo "status=success" >> $GITHUB_OUTPUT + echo "status=success" >> $GITHUB_OUTPUT + # blob is in the GITHUB_OUTPUT fi