Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
51 changes: 51 additions & 0 deletions .github/workflows/generate-types-autopr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Weekly Type Generation and Auto PR

on:
schedule:
- cron: '0 3 * * 1' # Every Monday at 03:00 UTC
workflow_dispatch:

jobs:
generate-and-pr:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup .NET 9
uses: actions/setup-dotnet@v4
with:
dotnet-version: '9.0.x'

- name: Restore dependencies
run: dotnet restore

- name: Run generator
run: dotnet run --project Generator/System.Management.Generator.csproj

- name: Check for changes
id: git-check
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add Types/**/*.g.cs
if git diff --cached --quiet; then
echo "no_changes=true" >> $GITHUB_OUTPUT
else
echo "no_changes=false" >> $GITHUB_OUTPUT
fi

- name: Create Pull Request
if: steps.git-check.outputs.no_changes == 'false'
uses: peter-evans/create-pull-request@v6
with:
commit-message: "chore(types): update generated types"
branch: "auto/generated-types-update"
title: "chore(types): update generated types"
body: |
Automated update of generated types from learn.microsoft.com.
This PR was created by a scheduled GitHub Action.
delete-branch: true
58 changes: 58 additions & 0 deletions .github/workflows/generate-types-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: PR Type Generation

on:
pull_request:
paths:
- 'Generator/*.*'
- 'Types/**/*.g.cs'
- '.github/workflows/generate-types-pr.yml'

jobs:
generate-and-commit:
runs-on: ubuntu-latest

steps:
- name: Checkout PR branch
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.head_ref }}

- name: Check last commit author
id: last-commit
run: |
AUTHOR=$(git log -1 --pretty=format:'%an')
echo "author=$AUTHOR" >> $GITHUB_OUTPUT
- name: Setup .NET 9
if: steps.last-commit.outputs.author != 'github-actions[bot]'
uses: actions/setup-dotnet@v4
with:
dotnet-version: '9.0.x'

- name: Restore dependencies
if: steps.last-commit.outputs.author != 'github-actions[bot]'
run: dotnet restore

- name: Run generator
if: steps.last-commit.outputs.author != 'github-actions[bot]'
run: dotnet run --project Generator/System.Management.Generator.csproj

- name: Check for changes
if: steps.last-commit.outputs.author != 'github-actions[bot]'
id: git-check
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add Types/**/*.g.cs
if git diff --cached --quiet; then
echo "no_changes=true" >> $GITHUB_OUTPUT
else
echo "no_changes=false" >> $GITHUB_OUTPUT
fi
- name: Commit and push changes to PR branch
if: steps.last-commit.outputs.author != 'github-actions[bot]' && steps.git-check.outputs.no_changes == 'false'
run: |
git commit -m "chore(types): update generated types (PR auto-update)"
git push
3 changes: 3 additions & 0 deletions .github/workflows/nuget-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ on:
jobs:
build:
runs-on: ubuntu-latest
# Only depend on generate-and-commit if this is a PR event
needs: ${{ github.event_name == 'pull_request' && 'generate-and-commit' || '' }}
if: ${{ github.event_name != 'pull_request' || always() }}
steps:
- uses: actions/checkout@v4

Expand Down
40 changes: 20 additions & 20 deletions Generator/DefinitionLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -359,29 +359,29 @@
/// <param name="classUri">Specifies the list of drives to schedule for Autochk at the next reboot. The string syntax consists of the drive letter followed by a colon for the logical disk, for example: "C:"</param>
/// <param name="methodBlock"></param>
/// <returns>Returns a value of 0 (zero) if successful, and some other value if any other error occurs. Values are listed in the following list.</returns>
private static async Task<List<MethodDefinition>> ParseMethods(Uri classUri, string methodBlock)

Check warning on line 362 in Generator/DefinitionLoader.cs

View workflow job for this annotation

GitHub Actions / generate-and-commit

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
List<MethodDefinition> result = [];
var tBodyIndex = methodBlock.IndexOf("<tbody");
foreach (Match methodRow in TableRowRegex.Matches(methodBlock[tBodyIndex..]))
{
List<string> cells = [..TableCellRegex.Matches(methodRow.Groups[1].Value).Select(c => c.Groups[1].Value)];
if (cells.Count != 2)
{
ErrorReporter.Report($"Found unexpected number({cells.Count}) of cells in method Row.");
}

var nameCell = cells[0];
var linkMatch = LinkRegex.Match(nameCell);
if (!linkMatch.Success)
{
continue;
}

var name = TrimHTML(nameCell);
var description = TrimHTML(cells[1]);
var methodPageContent = await GetPageContentsAsync(new Uri(classUri, linkMatch.Groups[1].Value));
}
//var tBodyIndex = methodBlock.IndexOf("<tbody");
//foreach (Match methodRow in TableRowRegex.Matches(methodBlock[tBodyIndex..]))
//{
// List<string> cells = [..TableCellRegex.Matches(methodRow.Groups[1].Value).Select(c => c.Groups[1].Value)];
// if (cells.Count != 2)
// {
// ErrorReporter.Report($"Found unexpected number({cells.Count}) of cells in method Row.");
// }

// var nameCell = cells[0];
// var linkMatch = LinkRegex.Match(nameCell);
// if (!linkMatch.Success)
// {
// continue;
// }

// var name = TrimHTML(nameCell);
// var description = TrimHTML(cells[1]);
// var methodPageContent = await GetPageContentsAsync(new Uri(classUri, linkMatch.Groups[1].Value));
//}

return result;
}
Expand Down
Loading