Skip to content
Draft
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Remove ModuleBuilder patch.
- Remove install DSC step on Linux.

### Fixed

- `Publish-WikiContent`
- Check if git command is successful. Fixes [#172](https://github.com/dsccommunity/DscResource.DocGenerator/issues/172).

## [0.13.0] - 2025-02-28

### Removed
Expand Down
28 changes: 18 additions & 10 deletions source/Public/Publish-WikiContent.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -163,25 +163,33 @@ function Publish-WikiContent
Invoke-Git -WorkingDirectory $tempPath `
-Arguments @( 'remote', 'set-url', 'origin', "https://$($GitUserName):$($GitHubAccessToken)@github.com/$OwnerName/$RepositoryName.wiki.git" )


Write-Verbose -Message $script:localizedData.AddWikiContentToGitRepoMessage

Invoke-Git -WorkingDirectory $tempPath -Arguments @( 'add', '*' )
$gitAddResult = Invoke-Git -WorkingDirectory $tempPath -Arguments @( 'add', '*' ) -PassThru

Write-Verbose -Message ($script:localizedData.CommitAndTagRepoChangesMessage -f $ModuleVersion)
if ($gitAddResult.ExitCode -eq 1)
{
Write-Verbose -Message $script:localizedData.GitAddFailedMessage
}
else
{
Write-Verbose -Message ($script:localizedData.CommitAndTagRepoChangesMessage -f $ModuleVersion)

Invoke-Git -WorkingDirectory $tempPath `
-Arguments @( 'commit', '--message', "`"$($script:localizedData.UpdateWikiCommitMessage -f $ModuleVersion)`"" )
Invoke-Git -WorkingDirectory $tempPath `
-Arguments @( 'commit', '--message', "`"$($script:localizedData.UpdateWikiCommitMessage -f $ModuleVersion)`"" )

Write-Verbose -Message $script:localizedData.PushUpdatedRepoMessage
Write-Verbose -Message $script:localizedData.PushUpdatedRepoMessage

Invoke-Git -WorkingDirectory $tempPath `
-Arguments @( 'tag', '--annotate', $ModuleVersion, '--message', $ModuleVersion )
Invoke-Git -WorkingDirectory $tempPath `
-Arguments @( 'tag', '--annotate', $ModuleVersion, '--message', $ModuleVersion )

Invoke-Git -WorkingDirectory $tempPath -Arguments @( 'push', 'origin' )
Invoke-Git -WorkingDirectory $tempPath -Arguments @( 'push', 'origin' )

Invoke-Git -WorkingDirectory $tempPath -Arguments @( 'push', 'origin', $ModuleVersion )
Invoke-Git -WorkingDirectory $tempPath -Arguments @( 'push', 'origin', $ModuleVersion )

Write-Verbose -Message $script:localizedData.PublishWikiContentCompleteMessage
Write-Verbose -Message $script:localizedData.PublishWikiContentCompleteMessage
}
Comment on lines 167 to +192
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

Git add guard has correctness gaps and doesn’t yet fix the “nothing to commit” failure from issue #172

A few points on this new block:

  1. Exit code check is too narrow

    if ($gitAddResult.ExitCode -eq 1)
    {
        Write-Verbose -Message $script:localizedData.GitAddFailedMessage
    }
    else
    {
        # commit / tag / push
    }
    • Any non‑zero exit code other than 1 will be treated as “success” and still run commit/tag/push, even though git add actually failed.
    • You almost certainly want to treat any non‑zero exit code as failure:
    if ($gitAddResult.ExitCode -ne 0)
    {
        # handle failure
    }
  2. Real git‑add failures are silently downgraded to verbose

    • In the failure branch you only emit Write-Verbose. With default settings this is invisible, while the comment/message says “Wiki will not be updated”.
    • For an actual git error, callers likely expect the command to clearly fail (e.g., via Write-Error or a terminating error), not just silently skip the publish.
  3. Issue Publishing Wiki content fails if there’s nothing to commit #172 (“nothing to commit, working tree clean”) is not addressed

    • The reported problem is that git commit returns a non‑zero exit code when there’s nothing to commit, causing Publish-WikiContent to fail.
    • git add * still exits 0 when there are no changes, so this guard does not prevent the git commit invocation from running in that scenario.
    • Invoke-Git is still called for commit without -PassThru, so if git commit returns 1 with “nothing to commit, working tree clean”, it will still throw and fail the build as before.

    To truly fix Publishing Wiki content fails if there’s nothing to commit #172 you need to short‑circuit before commit/tag/push when there are no staged changes, for example by using git status --porcelain with -PassThru and the existing NothingToCommitToWiki localized message.

  4. Suggested direction

    Consider something along these lines:

    -        $gitAddResult = Invoke-Git -WorkingDirectory $tempPath -Arguments @( 'add', '*' ) -PassThru
    -
    -        if ($gitAddResult.ExitCode -eq 1)
    -        {
    -            Write-Verbose -Message $script:localizedData.GitAddFailedMessage
    -        }
    -        else
    -        {
    +        $gitAddResult = Invoke-Git -WorkingDirectory $tempPath -Arguments @( 'add', '*' ) -PassThru
    +
    +        if ($gitAddResult.ExitCode -ne 0)
    +        {
    +            Write-Error -Message $script:localizedData.GitAddFailedMessage `
    +                -Category InvalidOperation `
    +                -ErrorId 'PublishWikiContent_GitAddFailed' `
    +                -TargetObject $tempPath
    +
    +            return
    +        }
    +
    +        # No staged changes => nothing to commit; exit gracefully.
    +        $gitStatusResult = Invoke-Git -WorkingDirectory $tempPath -Arguments @( 'status', '--porcelain' ) -PassThru
    +
    +        if ([string]::IsNullOrWhiteSpace($gitStatusResult.StandardOutput))
    +        {
    +            Write-Verbose -Message $script:localizedData.NothingToCommitToWiki
    +            return
    +        }
    +
    +        {
                Write-Verbose -Message ($script:localizedData.CommitAndTagRepoChangesMessage -f $ModuleVersion)
                Invoke-Git -WorkingDirectory $tempPath `
                    -Arguments @( 'commit', '--message', "`"$($script:localizedData.UpdateWikiCommitMessage -f $ModuleVersion)`"" )
                Write-Verbose -Message $script:localizedData.PushUpdatedRepoMessage
                Invoke-Git -WorkingDirectory $tempPath `
                    -Arguments @( 'tag', '--annotate', $ModuleVersion, '--message', $ModuleVersion )
                Invoke-Git -WorkingDirectory $tempPath -Arguments @( 'push', 'origin' )
                Invoke-Git -WorkingDirectory $tempPath -Arguments @( 'push', 'origin', $ModuleVersion )
                Write-Verbose -Message $script:localizedData.PublishWikiContentCompleteMessage
            }

    This way:

Please re‑run the scenario from issue #172 (no changes in the wiki repo) with this function to confirm that Publish-WikiContent no longer fails when there is nothing to commit, and that genuine git errors are still visible to callers.


I'll help you verify this review comment. Let me gather the necessary information by examining the codebase.

Now let me examine the actual codebase:

Now let me examine the actual file and verify the code exists:


🏁 Script executed:

#!/bin/bash
# Check if file exists and examine lines 167-192
if [ -f "source/Public/Publish-WikiContent.ps1" ]; then
    echo "=== Lines 167-192 from Publish-WikiContent.ps1 ==="
    sed -n '167,192p' "source/Public/Publish-WikiContent.ps1"
else
    echo "File not found: source/Public/Publish-WikiContent.ps1"
    find . -name "Publish-WikiContent.ps1" -type f 2>/dev/null | head -5
fi

Length of output: 1233


🏁 Script executed:

#!/bin/bash
# Find and examine Invoke-Git implementation
echo "=== Searching for Invoke-Git function definition ==="
rg -nA 30 'function Invoke-Git' --type ps1 -B 2 | head -80

Length of output: 80


🏁 Script executed:

#!/bin/bash
# Check for localized string key definitions
echo "=== Searching for localized string keys ==="
rg -nA 2 'GitAddFailedMessage|NothingToCommitToWiki' --type psd1 | head -40

Length of output: 72


Let me continue verification with corrected search commands:

Now let me search for the Invoke-Git function and localized strings in the codebase:


🏁 Script executed:

#!/bin/bash
# Find Invoke-Git function without type filter
echo "=== Searching for Invoke-Git function definition ==="
rg -nA 15 'function Invoke-Git' --context=3 | head -100

Length of output: 477


🏁 Script executed:

#!/bin/bash
# Check for localized string key definitions (no type filter)
echo "=== Searching for localized string keys ==="
rg -n 'GitAddFailedMessage|NothingToCommitToWiki' --context=2 | head -60

Length of output: 2729


🏁 Script executed:

#!/bin/bash
# Look for strings.psd1 files to understand where keys are defined
echo "=== Locating strings.psd1 files ==="
find . -name "*.strings.psd1" -type f 2>/dev/null | head -20

Length of output: 88


Now let me examine the Invoke-Git implementation more closely to understand -PassThru behavior:


🏁 Script executed:

#!/bin/bash
# Get full Invoke-Git function implementation
echo "=== Full Invoke-Git function ==="
sed -n '32,120p' source/Public/Invoke-Git.ps1

Length of output: 2981


🏁 Script executed:

#!/bin/bash
# Check Out-GitResult to understand error handling
echo "=== Out-GitResult function start ==="
sed -n '1,100p' source/Private/Out-GitResult.ps1

Length of output: 2778


🏁 Script executed:

#!/bin/bash
# Check how commit/tag/push are called (without -PassThru)
echo "=== Checking Invoke-Git calls in Publish-WikiContent ==="
rg -n 'Invoke-Git' source/Public/Publish-WikiContent.ps1 -B1 -A1 | head -60

Length of output: 1537


Exit code check is too narrow and doesn't prevent the "nothing to commit" failure from issue #172

The new code introduces several issues:

  1. Exit code check only catches 1, not all failures

    The condition if ($gitAddResult.ExitCode -eq 1) catches only exit code 1, but any other non-zero exit code from git add is silently treated as success and continues to the commit/tag/push block. This should be:

    if ($gitAddResult.ExitCode -ne 0)
  2. Real git-add errors are only logged verbosely

    When git add fails with exit code 1, only Write-Verbose is called. Since verbose output is disabled by default, actual git errors are invisible to callers. Error-level output should be used to surface real failures.

  3. The "nothing to commit" failure (Publishing Wiki content fails if there’s nothing to commit #172) is not prevented

    The core issue remains unsolved: git add * exits with code 0 even when there are no changes, so this guard doesn't short-circuit before git commit. When git commit runs and finds nothing to commit, it exits with code 1. Since commit is called without -PassThru, Invoke-Git throws, causing the function to fail—the exact Publishing Wiki content fails if there’s nothing to commit #172 problem.

    To fix this, detect when there are no staged changes before attempting commit. Use git status --porcelain with -PassThru and short-circuit gracefully:

    $gitStatusResult = Invoke-Git -WorkingDirectory $tempPath -Arguments @( 'status', '--porcelain' ) -PassThru
    
    if ([string]::IsNullOrWhiteSpace($gitStatusResult.StandardOutput))
    {
        Write-Verbose -Message $script:localizedData.NothingToCommitToWiki
        return
    }
🤖 Prompt for AI Agents
In source/Public/Publish-WikiContent.ps1 around lines 167-192, the git-add
handling is too narrow and doesn't prevent the "nothing to commit" failure:
change the exit-code check to treat any non-zero as failure (use -ne 0) and log
real git-add failures with an error-level call rather than Write-Verbose; after
git add run git status --porcelain with -PassThru and if its StandardOutput is
empty write the localized "NothingToCommitToWiki" message and return early to
avoid running commit/tag/push; also invoke commit (and other critical git
commands) with -PassThru and verify their ExitCode so failures are handled
explicitly rather than letting Invoke-Git throw unobserved.

}
finally
{
Expand Down
1 change: 1 addition & 0 deletions source/en-US/DscResource.DocGenerator.strings.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ ConvertFrom-StringData @'
ConfigLocalGitMessage = Configuring local Git settings.
CloneWikiGitRepoMessage = Cloning the Wiki Git Repository '{0}'.
AddWikiContentToGitRepoMessage = Adding the Wiki Content to the Git Repository.
GitAddFailedMessage = Adding Git changes failed, Wiki will not be updated.
CommitAndTagRepoChangesMessage = Committing the changes to the Repository and adding build tag '{0}'.
PushUpdatedRepoMessage = Pushing the updated Repository to the Git Wiki.
PublishWikiContentCompleteMessage = Publish Wiki Content complete.
Expand Down
Loading