Files
b353dfa42f chore: add initial ecosystem plugin tests workflow (#19643)
* chore: add initial ecosystem plugin tests workflow

* Apply suggestions from code review

Co-authored-by: Nicholas C. Zakas <[email protected]>

* Comments and structure

* Switch to nano-spawn, with plugins.json

* Revert unintentional docs/src/_data/further_reading_links.json changes

* Tweaked docs text for runCommand

* Added a script to update data

* Fix: errororing on error for unknown plugin

* Add weekly cron to update data

* Add comments to match index.mjs

* fix: .json files are formatted with two spaces

* Apply suggestions from code review

Co-authored-by: fisker Cheung <[email protected]>

* Added the once-a-week comment

* Default to all

* Mention the default of all

* npm run test:ecosystem:update

* rm duplicate .json

* DISCORD_CONTRIBUTORS_WEBHOOK

* Correct error message for all plugins

* Apply suggestions from code review

Co-authored-by: Percy Ma <[email protected]>

* Apply suggestions from code review

Co-authored-by: 루밀LuMir <[email protected]>
Co-authored-by: Percy Ma <[email protected]>

* Apply suggestions from code review

Co-authored-by: 루밀LuMir <[email protected]>

* Continue bumping to latest

* chore: formatting

* Finish migration off of chalk

* Remove nano-spawn

* Added typescript-eslint and docs

* Apply suggestions from code review

Co-authored-by: 루밀LuMir <[email protected]>

* More docs, and use prettier

* JSDoc correction

* Import sorting, while I'm in the area

* fix: proper cross-OS file path/URLs to package.json

* nit: proper comment placement

* 'local' ESLint, not 'built'

* further 'local'

* Add debug()

* NI_AUTO_INSTALL

* Update package.json

Co-authored-by: 唯然 <[email protected]>

* NI_DEFAULT_AGENT

* { NI_DEFAULT_AGENT: "npm" }

* Switch to hardcoded commands

* feat: granular failing

* fix: remove erroneous build scripts

* Bump to latest commits, and add quick summaries

* remove antfu/ni now

* remove markdown, typescript-eslint

* Apply suggestions from code review

Co-authored-by: Francesco Trotta <[email protected]>
Co-authored-by: 루밀LuMir <[email protected]>

* recursive

* correction: result(s); add to ignores

---------

Co-authored-by: Nicholas C. Zakas <[email protected]>
Co-authored-by: fisker Cheung <[email protected]>
Co-authored-by: Percy Ma <[email protected]>
Co-authored-by: 루밀LuMir <[email protected]>
Co-authored-by: 唯然 <[email protected]>
Co-authored-by: Francesco Trotta <[email protected]>
2026-04-27 20:14:39 +09:00

95 lines
2.3 KiB
JavaScript

/**
* @fileoverview Updates commit hashes in the ecosystem test plugins-data.json.
* @author Josh Goldberg
*/
//-----------------------------------------------------------------------------
// Requirements
//-----------------------------------------------------------------------------
import fs from "node:fs/promises";
import { styleText } from "node:util";
import prettier from "prettier";
import { getPlugins, pluginDataFilePath } from "./data.mjs";
//-----------------------------------------------------------------------------
// Functions
//-----------------------------------------------------------------------------
/**
* @param {string} pluginKey
* @param {PluginSettings} pluginSettings
*/
async function getLatestRepositoryCommit(pluginKey, pluginSettings) {
const response = await fetch(
pluginSettings.repository.replace(
"github.com",
"api.github.com/repos",
) + "/commits?per_page=1",
);
if (!response.ok) {
throw new Error(
`Failed to fetch latest commit for ${pluginKey}: ${response.statusText}`,
);
}
const [{ sha }] = await response.json();
if (sha === pluginSettings.commit) {
console.log(
styleText(
"gray",
`[${pluginKey}] Already at latest commit: ${sha}`,
),
);
} else {
console.log(
styleText(
["bold", "gray"],
`[${pluginKey}] Found new commit hash: ${sha}`,
),
);
}
return sha;
}
//-----------------------------------------------------------------------------
// Main
//-----------------------------------------------------------------------------
const { pluginsData, pluginsSelected } = await getPlugins("update");
// For each requested plugin, fetch the latest commit from its repository API URL
const pluginsUpdated = Object.fromEntries(
await Promise.all(
pluginsSelected.map(async ([pluginKey, pluginSettings]) => [
pluginKey,
{
...pluginSettings,
commit: await getLatestRepositoryCommit(
pluginKey,
pluginSettings,
),
},
]),
),
);
// Write the updated plugins data to the plugins-data.json file
await fs.writeFile(
pluginDataFilePath,
await prettier.format(
JSON.stringify({
...pluginsData,
...pluginsUpdated,
}),
{
...(await prettier.resolveConfig(pluginDataFilePath.toString())),
filepath: pluginDataFilePath.toString(),
},
),
);