Skip to content

Remove js-yaml dependency from badge generator, use regex-based parsing#2108

Merged
pelikhan merged 3 commits intomainfrom
copilot/remove-js-yml-dependency
Oct 22, 2025
Merged

Remove js-yaml dependency from badge generator, use regex-based parsing#2108
pelikhan merged 3 commits intomainfrom
copilot/remove-js-yml-dependency

Conversation

Copy link
Contributor

Copilot AI commented Oct 22, 2025

Problem

The scripts/generate-status-badges.js script was importing js-yaml to parse workflow lock files and extract the name field. However, this dependency was not installed in the project, causing the script to fail when executed:

Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'js-yaml' imported from /home/runner/work/gh-aw/gh-aw/scripts/generate-status-badges.js

See: https://github.com/githubnext/gh-aw/actions/runs/18710130246/job/53356355485#step:5:1

Solution

Replaced the js-yaml dependency with a simple regex-based parser that extracts the name: field directly from the YAML content. Since the badge generator only needs to read a single field from each workflow file, a full YAML parser is unnecessary overhead.

Implementation

The new approach uses a regex pattern to match the workflow name:

/^name:\s*["']?([^"'\n]+?)["']?\s*$/m

This pattern:

  • Matches name: at the start of a line
  • Handles quoted (single/double) and unquoted values
  • Ensures single-line values (no embedded newlines)
  • Works with all 42 workflow lock files in the repository

Before:

import yaml from 'js-yaml';

const workflow = yaml.load(content);
if (!workflow || !workflow.name) {
  return null;
}
return { name: workflow.name, ... };

After:

const nameMatch = content.match(/^name:\s*["']?([^"'\n]+?)["']?\s*$/m);
if (!nameMatch) {
  return null;
}
return { name: nameMatch[1].trim(), ... };

Benefits

  • ✅ Removes external dependency on js-yaml
  • ✅ Simpler, lighter-weight solution
  • ✅ Same functionality and output
  • ✅ Successfully parses all 42 workflow lock files
  • ✅ All tests pass

Testing

Verified the script works correctly:

  • Successfully generates badges for all 42 workflows
  • Output format is identical to the previous version
  • All unit and integration tests pass
  • Linting passes

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/repos/githubnext/gh-aw/actions/runs/18710130246/jobs
    • Triggering command: curl -s REDACTED (http block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

Remove js-yml dependency in badge generator, use basic string parse + regex strategy.

See run https://github.com/githubnext/gh-aw/actions/runs/18710130246/job/53356355485#step:5:1


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

- Remove js-yaml import dependency
- Implement regex-based YAML name field parsing
- Support quoted and unquoted name values
- Tested with all 42 workflow lock files successfully

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
@pelikhan pelikhan marked this pull request as ready for review October 22, 2025 08:49
@github-actions
Copy link
Contributor

Agentic Changeset Generator triggered by this pull request.

Copilot AI changed the title [WIP] Remove js-yml dependency in badge generator Remove js-yaml dependency from badge generator, use regex-based parsing Oct 22, 2025
Copilot AI requested a review from pelikhan October 22, 2025 08:51
@pelikhan pelikhan merged commit dd2058a into main Oct 22, 2025
3 checks passed
@pelikhan pelikhan deleted the copilot/remove-js-yml-dependency branch October 22, 2025 08:53
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