How to track migrations using Scorecards
Create a Scorecards to filter file contents to track versions of Libraries and Tools during migrations
In this tutorial we will be using Scorecards for tracking and driving migrations. Recently we have introduced new Data Points for git based Data Sources to extract information from files using regex patterns. In this tutorial we will be building some custom checks using these Data Points to track library and language versions from the contents of metadata files.
Before you begin
Before starting, ensure you have:
An active Harness IDP account, at present IDP is enabled on request so fill this form to get IDP enabled for you.
Access to your git provider through the connectors in the Admin section, remember to provide API access. Follow the steps mentioned here to create connector once you are in the connector window.

(Optional) If your catalog-info.yaml does not live at the root of the source code, then ensure the
backstage.io/source-locationannotation appropriately points to the correct source code location.
A registered software component for which you want to track migration.
Understand checks in scorecards
We have added data points for git based datasources (GitHub, GitLab, etc.), to be used to create custom checks in Scorecards that can match and extract specific string patterns from any file in your source code. This feature is particularly useful for tracking versions in various files eg., bazel for java, Dockerfile, go.mod for go, package.json for react and javascript, manifest files, etc.
Set up a custom check
Under Configure section select Scorecards, now go to Checks tab and select Create Custom Check

Now add Name and Description to the custom check.
Select DataSource and DataPoints
Select the git provider datasource, for example GitHub along with
extract string from a filedata point to extract the version number.
Branch specification
Specifying the Branch: If you know the branch name, specify it directly. If not, the system will use the branch from
backstage.io/source-locationannotation.
How to add backstage.io/source-location
Ideally backstage.io/source-location is taken from the root of the catalog-info.yaml in case your services do not live there, you need to add an annotation as mentioned below in your catalog-info.yaml
A Location reference that points to the source code of the entity (typically a Component). Useful when catalog files do not get ingested from the source code repository itself. If the URL points to a folder, it is important that it is suffixed with a '/' in order for relative path resolution to work consistently.
File specification
Defining the File: Specify the filename with its extension or provide the relative path from the root folder. For example, use .bazelrc, package.json, manifest/Dockerfile. Also you can provide the filename as a regex pattern, example for a file path
/backstage/blob/master/scripts/log-20240105.anyextensionthe regex would be/backstage/blob/master/scripts/log-20240105\..*
Specify the pattern
Since I am trying to track to Java Version of my project using the bazelrc file which mentions my java version as
build --java_language_version=17and the corresponding Regex Pattern to be used for the same is^build --java_language_version=(\d+)

Create a scorecard
Once the Checks are created, now we need to add them to a new Scorecard.
Go to Scorecards on the left nav and select Create New Scorecard
Add Name, Description, Owner (same as that of the software component you want to add this scorecard to) and select the Checks you created above to track the migration and publish the Scorecard.

Check score
Now go to the software component in your catalog and under the Scorecards tab you can view the scores, also you can re-run the check to compute score instantaneously.

How does the score gets computed?
Pattern extraction
Extracting Data: The system fetches the file, searches for the specified regex pattern within its contents, and then extracts and returns the value.
Return value
Result: The system returns a true/false value based on whether the pattern was found in the file or whether a value is the same as desired.
Troubleshooting
Incorrect file path:
Ensure the file path is relative to the root folder of the repository.
Pattern matching errors:
Verify the accuracy of the pattern you are trying to match. You can use this website for the same, also check for the group () for the string you are trying to match.
Best practices
Regularly update the backstage.io/source-location annotation to reflect any changes in the repository structure. Check the regex used for pattern matching.
Conclusion
In this tutorial, we covered how to use Scorecards in Harness IDP for tracking and driving migrations. This tool is incredibly useful for maintaining up-to-date information on various aspects of your software projects, such as dependency versions.
For more detailed information and support, refer to the Harness IDP documentation and community forums.
Last updated
Was this helpful?

