Skip to content

Fix CI: replace brittle HtmlAgilityPack.dll search with PSParseHTML module import#721

Closed
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-gh-actions-job-failure
Closed

Fix CI: replace brittle HtmlAgilityPack.dll search with PSParseHTML module import#721
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-gh-actions-job-failure

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 12, 2026

Export-GHEntraFido was recursively scanning $HOME for HtmlAgilityPack.dll and throwing when not found on GitHub-hosted runners, even though the workflow already installs PSParseHTML. The function also duplicated the Invoke-WebRequest/LoadHtml sequence unnecessarily.

Changes

  • Scripts/Export-GHEntraFido.ps1 — replace the Get-ChildItem DLL hunt with a standard module import guard; remove the duplicate web fetch/parse block:

    # Before: recursive DLL search + duplicate Invoke-WebRequest block
    if (-not ('HtmlAgilityPack.HtmlDocument' -as [type])) {
        $dll = Get-ChildItem -Path $HOME -Recurse -Filter HtmlAgilityPack.dll ...
        if (-not $dll) { throw "HtmlAgilityPack.dll not found..." }
        Add-Type -Path $dll.FullName
    }
    # ... then Invoke-WebRequest + LoadHtml duplicated twice
    
    # After: module import guard, single fetch/parse pass
    if (-not (Get-Module -Name PSParseHTML)) {
        Import-Module PSParseHTML -ErrorAction Stop
    }
  • .github/workflows/GHMerge.yml — harden the install step to trust PSGallery and verify the import at install time, so failures surface in their own step:

    run: |
      Set-PSRepository PSGallery -InstallationPolicy Trusted
      Install-Module -Name PSParseHTML -Force -Scope CurrentUser
      Import-Module PSParseHTML -Force
Original prompt

Fix the failing GitHub Actions job in repository DevClate/EntraFIDOFinder.

Context:

  • Failing job URL: https://github.com/DevClate/EntraFIDOFinder/actions/runs/25724537808/job/75533797431
  • Workflow: .github/workflows/GHMerge.yml
  • Failing commit/ref: f5a4d8dbe04d5be3992f3a38d691809036342b58
  • The job fails while running Merge-GHFidoData, which calls Export-GHEntraFido.
  • The logs show this error:
    • Failed to fetch data from URL: HtmlAgilityPack.dll not found. Ensure the dependency is installed before running Export-GHEntraFido.

Relevant files already identified:

  • .github/workflows/GHMerge.yml
  • Scripts/Export-GHEntraFido.ps1
  • Scripts/Merge-GHFidoData.ps1

Observed root cause:

  • The workflow installs/imports PSParseHTML, but Scripts/Export-GHEntraFido.ps1 manually searches for HtmlAgilityPack.dll under $HOME and throws if it cannot find the DLL.
  • This is brittle on GitHub-hosted runners and causes the job failure.
  • The script also appears to duplicate the Invoke-WebRequest / LoadHtml sequence and should be cleaned up.

Requested change:

  • Update the implementation so the script no longer relies on recursively finding HtmlAgilityPack.dll in the runner home directory.
  • Prefer a robust module-based approach, e.g. importing PSParseHTML (or otherwise ensuring HtmlAgilityPack types are loaded in a reliable way) before creating HtmlAgilityPack.HtmlDocument.
  • Preserve the existing behavior of parsing the Microsoft Entra FIDO table.
  • Remove duplicate request/parsing code if present.
  • If needed, harden the workflow step in .github/workflows/GHMerge.yml so the dependency is reliably installed/imported in CI.

Acceptance criteria:

  • The failing workflow/job should no longer fail due to missing HtmlAgilityPack.dll.
  • Merge-GHFidoData should still be able to call Export-GHEntraFido successfully in GitHub Actions.
  • Keep the fix minimal and targeted.
  • Open a pull request with the change.

The following is the prior conversation context from the user's chat exploration (may be truncated):

User: Please find a solution for this failing job. Use the logs, job definition, and any referenced files where the failure occurred. Keep your response focused on the solution and include code suggestions when appropriate.

Assistant: The failure is caused by Export-GHEntraFido not being able to load HtmlAgilityPack.dll, even though the workflow installs PSParseHTML.

Root cause

In the workflow, the module is installed and imported:

But the script still manually searches for a DLL under $HOME:

That logic is brittle on GitHub-hosted runners and is exactly what throws the error seen in the logs. The exception is surfaced here:

Best fix

Stop depending on a manual DLL lookup. Since the workflow already imports PSParseHTML, Export-GHEntraFido should either:

  1. rely on the module being imported, or
  2. explicitly import it itself.

Recommended code change

Replace the DLL-loading block in Scripts/Export-GHEntraFido.ps1 with a module import guard.

Function Export-GHEntraFido {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory = $true)]
        [string]$Url
    )

    if (-not (Get-Module -Name PSParseHTML)) {
        Import-Module PSParseHTML -ErrorAction Stop
    }

    if (-not ('HtmlAgilityPack.HtmlDocument' -as [type])) {
        throw "HtmlAgilityPack types are not available after importing PSParseHTML."
    }

    $response = Invoke-WebRequest -Uri $Url
    $htmlContent = $response.Content

    $htmlDocument = New-Object HtmlAgilityPack.HtmlDocument
    $htmlDocument.LoadHtml($htmlContent)

    $tableNodes = $htmlDocument.DocumentNode.SelectNodes("//table")
    $targetTableNode = $null

    foreach ($tableNode in $tableNodes) {
        $headers = $tableNode.SelectNodes(".//thead/tr/th") | ForEach-Object { $_.InnerText.Trim() }
        if ($headers -contains "Description" -and $headers -contains "AAGUID") {
            $targetTableNode = $tableNode
            break
        }
    }

    if ($null -ne $targetTableNode) {
        $headers = $targetTableNode.SelectNodes(".//thead/tr/th") | ForEach-Object { $_.InnerText.Trim() }
        $data = @()

        $rowNodes = $targetTableNode.SelectNodes(".//tbody/tr")
        foreach ($rowNode in $rowNodes) {
            $cellNodes = $rowNode.SelectNodes("td")
            $row = @{
                Description = ""
                AAGUID      = ""
          ...

</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

*This pull request was created from Copilot chat.*
>

…rt; remove duplicate request/parse block

Agent-Logs-Url: https://github.com/DevClate/EntraFIDOFinder/sessions/7ecb517c-bbc6-4d57-950b-bc7051393d02

Co-authored-by: DevClate <107187714+DevClate@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix failing GitHub Actions job in EntraFIDOFinder Fix CI: replace brittle HtmlAgilityPack.dll search with PSParseHTML module import May 12, 2026
Copilot AI requested a review from DevClate May 12, 2026 09:13
@DevClate DevClate closed this May 12, 2026
@DevClate DevClate deleted the copilot/fix-gh-actions-job-failure branch May 12, 2026 10:20
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.

2 participants