Skip to content

Conversation

felickz
Copy link
Contributor

@felickz felickz commented Aug 1, 2025

Bringing an idea to fruition: a common code base (this one) that can run security tasks on both GitHub Actions and Azure DevOps Pipelines! In this scenario - both using the same Component Detection dotnet tool to detect and generate GitHub Dependency Graph Snapshots to submit back to a GitHub repo. This will aide in migrating ADO customers over to GitHub repos and continue using pipelines as needed.

Before:

  • 0 SCA vulns on 77 NuGet packages (no transitive)
image

After:

image

Ex Pipeline: https://github.com/testing-felickz/eShopOnWeb/blob/main/.ado/gh-cd-submission.yml

trigger:
- main

pool:
  vmImage: ubuntu-latest

steps:
- script: echo Hello, world!
  displayName: 'Run a one-line script'

- script: dotnet restore eShopOnWeb.sln
  displayName: NuGet Restore

- task: component-detection-github-submission-task@0
  inputs:
    githubRepository: 'testing-felickz/eShopOnWeb'
    token: '$(GH_TOKEN)'
    filePath: '$(Build.SourcesDirectory)'
RAW Pipeline log

2025-08-01T03:19:37.3135032Z ##[section]Starting: componentdetectiongithubsubmissiontask
2025-08-01T03:19:37.3141350Z ==============================================================================
2025-08-01T03:19:37.3141508Z Task         : Component Detection GitHub Dependency Submission
2025-08-01T03:19:37.3141609Z Description  : Upload information about your dependencies to the GitHub dependency graph using component detection
2025-08-01T03:19:37.3141765Z Version      : 0.1.10
2025-08-01T03:19:37.3141849Z Author       : GitHub Advanced Security
2025-08-01T03:19:37.3141997Z Help         : [Learn more about this task](https://github.com/advanced-security/component-detection-dependency-submission-action)
2025-08-01T03:19:37.3142139Z ==============================================================================
2025-08-01T03:19:38.2854557Z Running component-detection
2025-08-01T03:19:38.2884683Z [command]/home/vsts/work/1/s/component-detection scan --SourceDirectory /home/vsts/work/1/s --ManifestFile ./output.json
2025-08-01T03:19:38.6641638Z [03:19:38 INF] Finding components...
2025-08-01T03:19:41.9130034Z [03:19:41 INF] Starting enumeration of /home/vsts/work/1/s
2025-08-01T03:19:42.1560268Z [03:19:42 INF] Enumerated 497 files and 139 directories in 00:00:00.2468980
2025-08-01T03:19:42.3087074Z [03:19:42 INF] No instructions received to scan docker images.
2025-08-01T03:19:48.5989995Z                                Detection Summary                                
2025-08-01T03:19:48.6122913Z ┌───────────────────┬───────────────────┬───────────────────┬──────────────────┐
2025-08-01T03:19:48.6123787Z │ Component         │ Detection Time    │ # Components      │ # Explicitly     │
2025-08-01T03:19:48.6124134Z │ Detector Id       │                   │ Found             │ Referenced       │
2025-08-01T03:19:48.6124636Z ├───────────────────┼───────────────────┼───────────────────┼──────────────────┤
2025-08-01T03:19:48.6125054Z │ CocoaPods         │ 0.38 seconds      │ 0                 │ 0                │
2025-08-01T03:19:48.6125365Z │ DotNet            │ 1.5 seconds       │ 2                 │ 1                │
2025-08-01T03:19:48.6125752Z │ Go                │ 0.36 seconds      │ 0                 │ 0                │
2025-08-01T03:19:48.6126131Z │ Gradle            │ 0.37 seconds      │ 0                 │ 0                │
2025-08-01T03:19:48.6126421Z │ Ivy (Beta)        │ 3.8 seconds       │ 0                 │ 0                │
2025-08-01T03:19:48.6126712Z │ Linux             │ 0.44 seconds      │ 0                 │ 0                │
2025-08-01T03:19:48.6126995Z │ MvnCli            │ 4.7 seconds       │ 0                 │ 0                │
2025-08-01T03:19:48.6127279Z │ Npm               │ 3.4 seconds       │ 0                 │ 0                │
2025-08-01T03:19:48.6127566Z │ NpmLockfile3      │ 3.4 seconds       │ 0                 │ 0                │
2025-08-01T03:19:48.6128141Z │ NpmWithRoots      │ 3.4 seconds       │ 0                 │ 0                │
2025-08-01T03:19:48.6128430Z │ NuGet             │ 3.4 seconds       │ 0                 │ 0                │
2025-08-01T03:19:48.6128730Z │ NuGetPackagesConf │ 3.4 seconds       │ 0                 │ 0                │
2025-08-01T03:19:48.6129007Z │ ig                │                   │                   │                  │
2025-08-01T03:19:48.6135982Z │ NuGetProjectCentr │ 3.6 seconds       │ 302               │ 51               │
2025-08-01T03:19:48.6136512Z │ ic                │                   │                   │                  │
2025-08-01T03:19:48.6136815Z │ PipReport         │ 6.6 seconds       │ 0                 │ 0                │
2025-08-01T03:19:48.6137103Z │ Pnpm              │ 3.8 seconds       │ 0                 │ 0                │
2025-08-01T03:19:48.6137405Z │ Poetry (Beta)     │ 3.8 seconds       │ 0                 │ 0                │
2025-08-01T03:19:48.6137743Z │ Ruby              │ 3.8 seconds       │ 0                 │ 0                │
2025-08-01T03:19:48.6138026Z │ RustCli           │ 3.8 seconds       │ 0                 │ 0                │
2025-08-01T03:19:48.6138614Z │ RustCrateDetector │ 3.8 seconds       │ 0                 │ 0                │
2025-08-01T03:19:48.6138924Z │ RustSbom (Beta)   │ 3.8 seconds       │ 0                 │ 0                │
2025-08-01T03:19:48.6139210Z │ Vcpkg             │ 0.37 seconds      │ 0                 │ 0                │
2025-08-01T03:19:48.6139504Z │ Yarn              │ 0.37 seconds      │ 0                 │ 0                │
2025-08-01T03:19:48.6139915Z │ ───────────────── │ ───────────────── │ ───────────────── │ ──────────────── │
2025-08-01T03:19:48.6140283Z │ Total             │ 9.8 seconds       │ 304               │ 52               │
2025-08-01T03:19:48.6140722Z └───────────────────┴───────────────────┴───────────────────┴──────────────────┘
2025-08-01T03:19:48.6141046Z [03:19:48 INF] 
2025-08-01T03:19:48.6141215Z [03:19:48 INF] 
2025-08-01T03:19:48.6143307Z [03:19:48 INF] Detection time: 9.8346228 seconds.
2025-08-01T03:19:48.6710530Z [03:19:48 INF] Scan Manifest file: /home/vsts/work/1/s/output.json
2025-08-01T03:19:48.8184922Z Getting manifests from results
2025-08-01T03:19:48.8628218Z Submitting snapshot with undefined manifests to GitHub repository: testing-felickz/eShopOnWeb
2025-08-01T03:19:48.8668999Z 
2025-08-01T03:19:48.9037776Z ::set-output name=snapshot::{"manifests":{"src/ApplicationCore/ApplicationCore.csproj":{"resolved":{"pkg:nuget/[email protected]":{"package_url":"pkg:nuget/[email protected]","relationship":"indirect","scope":"development","dependencies":[]},"pkg:nuget/[email protected]":{"package_url":"pkg:nuget/[email protected]","relationship":"indirect","scope":"development","dependencies":[]},"pkg:nuget/[email protected]":{"package_url":"pkg:nuget/[email protected]","relationship":"indirect","scope":"development","dependencies":<TRUNCATED THIS IS HUGE>
<TRUNCATED THIS IS HUGE>
<TRUNCATED THIS IS HUGE>
<TRUNCATED THIS IS HUGE>
<TRUNCATED THIS IS HUGE>
<TRUNCATED THIS IS HUGE>
<TRUNCATED THIS IS HUGE>
<TRUNCATED THIS IS HUGE>
   "pkg:nuget/[email protected]"%0A                    ]%0A                },%0A                "pkg:nuget/[email protected]": {%0A                    "package_url": "pkg:nuget/[email protected]",%0A                    "relationship": "indirect",%0A                    "scope": "runtime",%0A                    "dependencies": []%0A                },%0A                "pkg:nuget/[email protected]": {%0A                    "package_url": "pkg:nuget/[email protected]",%0A                    "relationship": "indirect",%0A                    "scope": "runtime",%0A                    "dependencies": []%0A                },%0A                "pkg:nuget/[email protected]": {%0A                    "package_url": "pkg:nuget/[email protected]",%0A                    "relationship": "indirect",%0A                    "scope": "runtime",%0A                    "dependencies": []%0A                },%0A                "pkg:nuget/[email protected]": {%0A                    "package_url": "pkg:nuget/[email protected]",%0A                    "relationship": "indirect",%0A                    "scope": "runtime",%0A                    "dependencies": []%0A                },%0A                "pkg:nuget/[email protected]": {%0A                    "package_url": "pkg:nuget/[email protected]",%0A                    "relationship": "indirect",%0A                    "scope": "runtime",%0A                    "dependencies": []%0A                },%0A                "pkg:nuget/[email protected]": {%0A                    "package_url": "pkg:nuget/[email protected]",%0A                    "relationship": "indirect",%0A                    "scope": "runtime",%0A                    "dependencies": []%0A                }%0A            },%0A            "name": "src/BlazorShared/BlazorShared.csproj",%0A            "file": {%0A                "source_location": "src/BlazorShared/BlazorShared.csproj"%0A            }%0A        }%0A    },%0A    "version": 0,%0A    "job": {%0A        "correlator": "Job",%0A        "id": "71"%0A    },%0A    "sha": "92bc52321e80657edf23dee0d555ca796f1c87d4",%0A    "ref": "refs/heads/main",%0A    "scanned": "2025-08-01T03:19:48.858Z",%0A    "detector": {%0A        "name": "Component Detection",%0A        "version": "0.0.1",%0A        "url": "https://github.com/advanced-security/component-detection-dependency-submission-action"%0A    }%0A}
2025-08-01T03:19:49.4157335Z ::notice::Snapshot successfully created at 2025-08-01T03:19:49.223Z
2025-08-01T03:19:49.4157703Z Component detection and dependency submission completed successfully
2025-08-01T03:19:49.5144520Z ##[section]Finishing: componentdetectiongithubsubmissiontask

TODO

felickz added 13 commits July 31, 2025 21:41
The Fix:

Added package.json with "type": "commonjs" in the task directory
This tells Node.js to treat the index.js file as CommonJS instead of ES modules
Azure DevOps can now properly execute the bundled code
… "type": "module" in the package.json or use the .mjs extension.

✅ Execute properly in Azure DevOps (CommonJS format)
✅ Display proper marketplace overview (README content)
✅ Have a clean package (no unnecessary build artifacts)
- Replace CommonJS conversion with native ES module approach using .mjs extension
- Simplify build process by directly copying ncc output as index.mjs
- Remove complex regex-based ES-to-CommonJS conversion script
- Update Azure DevOps task execution target from index.js to index.mjs
- Leverage Node20_1 native ES module support instead of compatibility workarounds

This eliminates the need for post-processing ES modules to CommonJS,
resulting in cleaner code and a more maintainable build pipeline.
…work/_tasks/component-detection-github-submission-task_5065f07b-c417-4050-bf2b-f8520ce76aba/0.1.7/sourcemap-register.cjs' imported from /home/vsts/work/_tasks/component-detection-github-submission-task_5065f07b-c417-4050-bf2b-f8520ce76aba/0.1.7/index.mjs

Updated build script to copy both index.js → index.mjs and sourcemap-register.cjs
Both files are now included in the Azure DevOps task directory
The ES module can now properly resolve its dependencies
Fixed GitHub token authentication issue: Modified the Octokit configuration to only use authentication when a token is provided, preventing "Bad credentials" errors when accessing the public microsoft/component-detection repository.

Enhanced error handling: Added comprehensive error handling and validation throughout the component detection process:

Better error messages when download fails
Verification that the executable file was created successfully
Validation that the executable has proper permissions on Unix systems
Verification that the output.json file was created after running component-detection
Improved logging: Added debug logging to help troubleshoot issues:

Shows the download URL being used
Lists available assets from the GitHub release
Shows which asset was matched for the current platform
Logs the exact command being executed
Enhanced input validation: Added validation in the ADO entry point to ensure required inputs (GitHub repository and token) are provided before proceeding.

Set GitHub token environment variable: Ensured the GitHub token is available to the dependency-submission-toolkit.
Enhanced error handling for GitHub submission: Added try-catch around the submitSnapshot call with detailed error logging including HTTP status codes and response data.

Added early validation: Check if manifests exist before attempting submission to avoid unnecessary API calls.

Enhanced environment variable setup: Set additional environment variables that the dependency-submission-toolkit might expect:

GITHUB_REPOSITORY
GITHUB_API_URL
GITHUB_SERVER_URL
GITHUB_GRAPHQL_URL
Improved debug logging: Added more detailed logging around the submission process including snapshot details and correlator information.

Better manifest validation: Added check to ensure manifests aren't empty before proceeding with submission.
- split scripts for ado:build and add ado:debugbuild so that sourcemap-register.cjs is no longer needed (has a CodeQL alert)
…t-detection-dependency-submission-action into gh-ado-bundle
-  enhance tests for platform detection and CLI execution
…e logging

- The issue was that @actions/github doesn't export a default export. Instead, it exports named exports like context directly.
- "Submitting snapshot with undefined manifests to GitHub repository: testing-felickz/eShopOnWeb"
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