Skip to content

Release#79

Merged
CedaryCat merged 3 commits intorelease/0.2.0from
main
Mar 16, 2026
Merged

Release#79
CedaryCat merged 3 commits intorelease/0.2.0from
main

Conversation

@CedaryCat
Copy link
Owner

@CedaryCat CedaryCat commented Mar 16, 2026

Summary by Sourcery

Update documentation metadata generation to derive the referenced Terraria version from restored package assets and align CI to restore dependencies before running the sync check.

Enhancements:

  • Teach the docs metadata sync script to read project restore assets and resolve the Terraria assembly version from the restored OTAPI package.
  • Adjust the docs sync failure message to clearly instruct running the script in apply mode.

CI:

  • Run a dotnet restore step before checking docs metadata sync in the build workflow and remove the later redundant restore.

Documentation:

  • Refresh the English and Chinese README version matrix to reflect the new Terraria and OTAPI USP versions and document that the Terraria version comes from restored OTAPI.dll assets.

@sourcery-ai
Copy link

sourcery-ai bot commented Mar 16, 2026

Reviewer's Guide

Updates the docs metadata sync script to derive the Terraria version from restored NuGet assets (OTAPI.dll) instead of a hard-coded helper, wires this into the CI build so restore happens before the check, and refreshes the README version matrix values and wording accordingly.

Sequence diagram for CI docs metadata sync using restored NuGet assets

sequenceDiagram
    actor Developer
    participant GitHubActions
    participant DotNetCLI
    participant SyncDocMetadataScript
    participant RestoreAssetsJson as project.assets.json
    participant OTAPIAssembly as OTAPI.dll

    Developer->>GitHubActions: Push commit / open PR
    GitHubActions->>GitHubActions: Checkout repository
    GitHubActions->>GitHubActions: Setup .NET SDK

    GitHubActions->>DotNetCLI: dotnet restore PROJECT_PATH
    DotNetCLI->>RestoreAssetsJson: Generate restore assets

    GitHubActions->>SyncDocMetadataScript: Run sync-doc-metadata.ps1 -Mode check
    SyncDocMetadataScript->>RestoreAssetsJson: Get-RestoreAssets(Path, ProjectPath)
    RestoreAssetsJson-->>SyncDocMetadataScript: Parsed assets object

    SyncDocMetadataScript->>SyncDocMetadataScript: Get-TerrariaVersionFromRestoreAssets(Assets, TargetFramework, ProjectPath)
    SyncDocMetadataScript->>SyncDocMetadataScript: Resolve-RestoredPackageAssetPath(Assets, TargetFramework, PackageId, AssetFileName, ProjectPath)
    SyncDocMetadataScript->>OTAPIAssembly: Get-AssemblyFileVersion(Path)
    OTAPIAssembly-->>SyncDocMetadataScript: FileVersion (TerrariaVersion)

    SyncDocMetadataScript->>SyncDocMetadataScript: Build-EnglishVersionBlock(Metadata)
    SyncDocMetadataScript->>SyncDocMetadataScript: Build-ChineseVersionBlock(Metadata)
    SyncDocMetadataScript->>SyncDocMetadataScript: Sync-MarkedBlock on README files

    alt README out of sync and Mode is check
        SyncDocMetadataScript-->>GitHubActions: Throw error (metadata out of sync)
        GitHubActions-->>Developer: CI job fails, instruct to run script in apply mode
    else README in sync
        SyncDocMetadataScript-->>GitHubActions: Success message
        GitHubActions-->>Developer: CI job passes
    end
Loading

File-Level Changes

Change Details Files
Derive Terraria version from restored NuGet package assets in the sync-doc-metadata script.
  • Add helpers to load project.assets.json, normalize NuGet relative paths, and locate a restored library and its runtime assets for a given target framework and package ID.
  • Resolve OTAPI.dll from the OTAPI.USP package via project restore assets and read its assembly file version.
  • Expose a Get-TerrariaVersionFromRestoreAssets function and include its value as TerrariaVersion in the metadata object used by the script.
  • Adjust error messages to instruct the user to run dotnet restore or rerun the sync script in apply mode when prerequisites are missing or docs are out of sync.
tools/sync-doc-metadata.ps1
Update the build workflow to restore dependencies before running the docs metadata sync check.
  • Move the dotnet restore step to run directly after setting up .NET in the build job.
  • Run the sync-doc-metadata.ps1 -Mode check step after restore so project.assets.json is available.
  • Remove the now-redundant restore step that previously ran later in the workflow.
.github/workflows/build.yaml
Refresh README version matrix values and descriptions to match the new metadata source.
  • Update English README version matrix text to state that baseline values come from project files and restored package assets.
  • Change the documented Terraria version and OTAPI USP version to 1.4.5.6 and 1.1.0-pre-release-upstream.30, respectively.
  • Align the Chinese README version matrix wording and version values with the English README.
README.md
docs/README.zh-cn.md

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@CedaryCat CedaryCat merged commit 79e2842 into release/0.2.0 Mar 16, 2026
13 checks passed
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 2 issues, and left some high level feedback:

  • In Resolve-RestoredPackageAssetPath, you assume runtime assets always exist for the target; consider explicitly handling the case where runtime is null/missing (e.g., falling back to compile or runtimeTargets) to avoid unexpected null dereferences on different package layouts.
  • The Get-RestoredPackageLibrary function picks the first library whose name matches the ^{PackageId}/ pattern; if multiple versions of the same package are present, it may be worth tightening the match (e.g., including version or target) or at least asserting that only one candidate exists to make behavior predictable.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `Resolve-RestoredPackageAssetPath`, you assume `runtime` assets always exist for the target; consider explicitly handling the case where `runtime` is null/missing (e.g., falling back to `compile` or `runtimeTargets`) to avoid unexpected null dereferences on different package layouts.
- The `Get-RestoredPackageLibrary` function picks the first library whose name matches the `^{PackageId}/` pattern; if multiple versions of the same package are present, it may be worth tightening the match (e.g., including version or target) or at least asserting that only one candidate exists to make behavior predictable.

## Individual Comments

### Comment 1
<location path="tools/sync-doc-metadata.ps1" line_range="62" />
<code_context>
+        throw "Could not locate restore assets '$Path'. Run: dotnet restore '$ProjectPath'"
+    }
+
+    return (Get-Content -Path $Path -Raw -Encoding UTF8 | ConvertFrom-Json)
+}
+
</code_context>
<issue_to_address>
**issue (bug_risk):** project.assets.json is deeply nested and may be truncated without an explicit ConvertFrom-Json -Depth

On Windows PowerShell, `ConvertFrom-Json` defaults to `-Depth 2`, which will silently truncate this deeply nested file and can lead to subtle runtime issues when accessing nested properties. Please specify an explicit depth (e.g. `ConvertFrom-Json -Depth 100`) so the assets file is fully parsed across PowerShell versions.
</issue_to_address>

### Comment 2
<location path="tools/sync-doc-metadata.ps1" line_range="130-132" />
<code_context>
+
+    $library = Get-RestoredPackageLibrary -Assets $Assets -PackageId $PackageId
+    $targetPackage = Get-RestoredTargetPackageEntry -Assets $Assets -TargetFramework $TargetFramework -PackageLibraryName $library.Name
+    $runtimeAssets = @($targetPackage.runtime.PSObject.Properties)
+    $assetRelativePath = $runtimeAssets |
+        Where-Object { [System.IO.Path]::GetFileName([string]$_.Name) -ieq $AssetFileName } |
</code_context>
<issue_to_address>
**suggestion:** Handle missing runtime assets more gracefully to avoid null-reference errors

If the resolved package entry has no `runtime` section (or it’s empty), `$targetPackage.runtime` will be `$null` and this line will throw a generic null-reference error. Please add an explicit `$null` check before accessing `.runtime` and raise a clearer, targeted error when no runtime assets exist for the resolved package/TFM, consistent with the other guarded cases in this script.

```suggestion
    $library = Get-RestoredPackageLibrary -Assets $Assets -PackageId $PackageId
    $targetPackage = Get-RestoredTargetPackageEntry -Assets $Assets -TargetFramework $TargetFramework -PackageLibraryName $library.Name

    if (-not $targetPackage.runtime) {
        throw "Restored package '$PackageId' for target framework '$TargetFramework' does not contain any runtime assets."
    }

    $runtimeAssets = @($targetPackage.runtime.PSObject.Properties)
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

throw "Could not locate restore assets '$Path'. Run: dotnet restore '$ProjectPath'"
}

return (Get-Content -Path $Path -Raw -Encoding UTF8 | ConvertFrom-Json)
Copy link

Choose a reason for hiding this comment

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

issue (bug_risk): project.assets.json is deeply nested and may be truncated without an explicit ConvertFrom-Json -Depth

On Windows PowerShell, ConvertFrom-Json defaults to -Depth 2, which will silently truncate this deeply nested file and can lead to subtle runtime issues when accessing nested properties. Please specify an explicit depth (e.g. ConvertFrom-Json -Depth 100) so the assets file is fully parsed across PowerShell versions.

Comment on lines +130 to +132
$library = Get-RestoredPackageLibrary -Assets $Assets -PackageId $PackageId
$targetPackage = Get-RestoredTargetPackageEntry -Assets $Assets -TargetFramework $TargetFramework -PackageLibraryName $library.Name
$runtimeAssets = @($targetPackage.runtime.PSObject.Properties)
Copy link

Choose a reason for hiding this comment

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

suggestion: Handle missing runtime assets more gracefully to avoid null-reference errors

If the resolved package entry has no runtime section (or it’s empty), $targetPackage.runtime will be $null and this line will throw a generic null-reference error. Please add an explicit $null check before accessing .runtime and raise a clearer, targeted error when no runtime assets exist for the resolved package/TFM, consistent with the other guarded cases in this script.

Suggested change
$library = Get-RestoredPackageLibrary -Assets $Assets -PackageId $PackageId
$targetPackage = Get-RestoredTargetPackageEntry -Assets $Assets -TargetFramework $TargetFramework -PackageLibraryName $library.Name
$runtimeAssets = @($targetPackage.runtime.PSObject.Properties)
$library = Get-RestoredPackageLibrary -Assets $Assets -PackageId $PackageId
$targetPackage = Get-RestoredTargetPackageEntry -Assets $Assets -TargetFramework $TargetFramework -PackageLibraryName $library.Name
if (-not $targetPackage.runtime) {
throw "Restored package '$PackageId' for target framework '$TargetFramework' does not contain any runtime assets."
}
$runtimeAssets = @($targetPackage.runtime.PSObject.Properties)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant