Skip to content

Separate tasks in our workflows #1269

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
wants to merge 6 commits into
base: draft-v8
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion .github/workflows/renumber-sections.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}'
}
})
26 changes: 26 additions & 0 deletions .github/workflows/report-status.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
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 }}
4 changes: 2 additions & 2 deletions .github/workflows/smart-quotes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test-examples.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/tools-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/update-on-merge.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/word-converter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
4 changes: 2 additions & 2 deletions tools/ExampleTester/ExampleTester.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<IsPackable>false</IsPackable>
Expand Down
2 changes: 1 addition & 1 deletion tools/MarkdownConverter/MarkdownConverter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<NoWarn>NU1701</NoWarn>
Expand Down
2 changes: 1 addition & 1 deletion tools/StandardAnchorTags/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ static async Task<int> 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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert this change, as it appears to be unused? (Or emit the annotations somewhere?)

}
}
return logger.Success ? 0 : 1;
Expand Down
4 changes: 2 additions & 2 deletions tools/StandardAnchorTags/StandardAnchorTags.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
Expand Down
12 changes: 12 additions & 0 deletions tools/Utilities/CustomSerializer.cs
Original file line number Diff line number Diff line change
@@ -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<NewCheckRunAnnotation>))]
public sealed partial class JsonCheckRunAnnotationSerializerContext : JsonSerializerContext;
60 changes: 58 additions & 2 deletions tools/Utilities/StatusCheckLogger.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using Octokit;
using Actions.Core.Extensions;
using Actions.Core.Services;
using Microsoft.Extensions.DependencyInjection;

namespace Utilities;

Expand All @@ -24,6 +27,17 @@ public record StatusCheckMessage(string file, int StartLine, int EndLine, string
/// <param name="toolName">The name of the tool that is running the check</param>
public class StatusCheckLogger(string pathToRoot, string toolName)
{
private Lazy<ICoreService> _gitHubCoreService = new(() => InitializeCoreService());

private static ICoreService InitializeCoreService()
{
using var provider = new ServiceCollection()
.AddGitHubActionsCore()
.BuildServiceProvider();

return provider.GetRequiredService<ICoreService>();
}

private List<NewCheckRunAnnotation> annotations = [];
public bool Success { get; private set; } = true;

Expand Down Expand Up @@ -153,13 +167,17 @@ public void ExitOnFailure(StatusCheckMessage d)
/// <param name="repo">The GitHub repo name</param>
/// <param name="sha">The head sha when running as a GitHub action</param>
/// <returns>The full check run result object</returns>
public async Task BuildCheckRunResult(string token, string owner, string repo, string sha)
public async Task<IList<NewCheckRunAnnotation>> 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
}
Expand All @@ -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);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe group these into pairs of lines (so remove the blank line between the two check_name-related lines, and then between the two conclusion-related lines, etc.)

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;
}
}
6 changes: 4 additions & 2 deletions tools/Utilities/Utilities.csproj
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="GitHub.Actions.Core" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.1" />
<PackageReference Include="Octokit" Version="14.0.0" />
<PackageReference Include="System.Text.Json" Version="9.0.1" />
</ItemGroup>
Expand Down
3 changes: 2 additions & 1 deletion tools/run-section-renumber.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading