diff --git a/.github/workflows/js-prs-issue.yml b/.github/workflows/js-prs-issue.yml index 35756a9..6639198 100644 --- a/.github/workflows/js-prs-issue.yml +++ b/.github/workflows/js-prs-issue.yml @@ -24,8 +24,7 @@ jobs: ALERTS_LIST='' # Get list of supported modules - # Assumes CMS 5 is the most recent stable version - curl -s -o __modules.json https://raw.githubusercontent.com/silverstripe/supported-modules/5/modules.json + curl -s -o __modules.json https://raw.githubusercontent.com/silverstripe/supported-modules/main/repositories.json # If we can't parse the JSON at all, $MODULES will be an empty string and that means we couldn't fetch the file. MODULES=$(jq -e '.' __modules.json) || true if [[ $MODULES == "" ]]; then @@ -35,37 +34,37 @@ jobs: # Instead of exiting, output an error instead of the dependabot alert list. # We don't have any reporting indicating if this workflow fails, so this is a good way to track that. ALERTS_LIST='Failed to parse supported-modules JSON. Please check the GitHub action log.' - fi + else + # Create a list of markdown links for supported module dependabot stuff + ALERTS_LIST=$(php -r ' + $json = json_decode(file_get_contents("__modules.json"), true); + foreach ($json["supportedModules"] as $module) { + # Assumes CMS 5 is the most recent stable version + if (!isset($module["majorVersionMapping"]["5"])) { + continue; + } + $githubRef = $module["github"]; + $branch = end($module["majorVersionMapping"]["5"]); + $packageJsonURL = "https://raw.githubusercontent.com/$githubRef/$branch/package.json"; + $headers = get_headers($packageJsonURL); + # $headers[0] includes the response code in a format like: "HTTP/1.1 404 Not Found" + $response = $headers[0]; + # Skip modules which do not have a package.json file + if (strpos($response, "404") !== false) { + continue; + } + # If we have something other than 404 (above) or 200, output an error string for the list + # and move on. + if (strpos($response, "200") === false) { + echo "- $githubRef: Unable to check package.json, response was $response.\\n"; + continue; + } - # Create a list of markdown links for supported module dependabot stuff - ALERTS_LIST=$(php -r ' - $json = json_decode(file_get_contents("__modules.json"), true); - foreach ($json as $module) { - # Skip non-github modules, if any listed - if (!$module["github"]) { - continue; - } - $githubRef = $module["github"]; - $branch = end($module["branches"]); - $packageJsonURL = "https://raw.githubusercontent.com/$githubRef/$branch/package.json"; - $headers = get_headers($packageJsonURL); - # $headers[0] includes the response code in a format like: "HTTP/1.1 404 Not Found" - $response = $headers[0]; - # Skip modules which do not have a package.json file - if (strpos($response, "404") !== false) { - continue; - } - # If we have something other than 404 (above) or 200, output an error string for the list - # and move on. - if (strpos($response, "200") === false) { - echo "- $githubRef: Unable to check package.json, response was $response.\\n"; - continue; + # If we get here, we have a package.json file so we should add a dependabot alerts URL to the list + echo "- [$githubRef](https://github.com/$githubRef/security/dependabot)\\n"; } - - # If we get here, we have a package.json file so we should add a dependabot alerts URL to the list - echo "- [$githubRef](https://github.com/$githubRef/security/dependabot)\\n"; - } - ') + ') + fi echo 'ALERTS_LIST is:' echo $ALERTS_LIST