mirror of
https://github.com/grafana/grafana.git
synced 2025-08-01 18:44:54 +08:00
Toolkit: create manifest files for plugins (#22056)
This commit is contained in:
@ -5,6 +5,7 @@ import chalk from 'chalk';
|
||||
import { startTask } from './tasks/core.start';
|
||||
import { changelogTask } from './tasks/changelog';
|
||||
import { cherryPickTask } from './tasks/cherrypick';
|
||||
import { manifestTask } from './tasks/manifest';
|
||||
import { precommitTask } from './tasks/precommit';
|
||||
import { templateTask } from './tasks/template';
|
||||
import { pluginBuildTask } from './tasks/plugin.build';
|
||||
@ -213,6 +214,14 @@ export const run = (includeInternalScripts = false) => {
|
||||
});
|
||||
});
|
||||
|
||||
// Test the manifest creation
|
||||
program
|
||||
.command('manifest')
|
||||
.description('create a manifest file in the cwd')
|
||||
.action(async cmd => {
|
||||
await execTask(manifestTask)({ folder: process.cwd() });
|
||||
});
|
||||
|
||||
program.on('command:*', () => {
|
||||
console.error('Invalid command: %s\nSee --help for a list of available commands.', program.args.join(' '));
|
||||
process.exit(1);
|
||||
|
32
packages/grafana-toolkit/src/cli/tasks/manifest.test.ts
Normal file
32
packages/grafana-toolkit/src/cli/tasks/manifest.test.ts
Normal file
@ -0,0 +1,32 @@
|
||||
import { getFilePaths } from './manifest';
|
||||
|
||||
describe('Manifest', () => {
|
||||
it('should collect file paths', () => {
|
||||
const info = getFilePaths(__dirname);
|
||||
expect(info).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
"changelog.ts",
|
||||
"cherrypick.ts",
|
||||
"closeMilestone.ts",
|
||||
"core.start.ts",
|
||||
"manifest.test.ts",
|
||||
"manifest.ts",
|
||||
"nodeVersionChecker.ts",
|
||||
"package.build.ts",
|
||||
"plugin/bundle.ts",
|
||||
"plugin/create.ts",
|
||||
"plugin/tests.ts",
|
||||
"plugin.build.ts",
|
||||
"plugin.ci.ts",
|
||||
"plugin.create.ts",
|
||||
"plugin.dev.ts",
|
||||
"plugin.tests.ts",
|
||||
"precommit.ts",
|
||||
"searchTestDataSetup.ts",
|
||||
"task.ts",
|
||||
"template.ts",
|
||||
"toolkit.build.ts",
|
||||
]
|
||||
`);
|
||||
});
|
||||
});
|
47
packages/grafana-toolkit/src/cli/tasks/manifest.ts
Normal file
47
packages/grafana-toolkit/src/cli/tasks/manifest.ts
Normal file
@ -0,0 +1,47 @@
|
||||
import { Task, TaskRunner } from './task';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import execa from 'execa';
|
||||
|
||||
interface ManifestOptions {
|
||||
folder: string;
|
||||
}
|
||||
|
||||
export function getFilePaths(root: string, work?: string, acc?: string[]): string[] {
|
||||
if (!acc) {
|
||||
acc = [];
|
||||
}
|
||||
let abs = work ?? root;
|
||||
const files = fs.readdirSync(abs);
|
||||
files.forEach(file => {
|
||||
const f = path.join(abs, file);
|
||||
const stat = fs.statSync(f);
|
||||
if (stat.isDirectory()) {
|
||||
acc = getFilePaths(root, f, acc);
|
||||
} else {
|
||||
acc!.push(f.substring(root.length + 1).replace('\\', '/'));
|
||||
}
|
||||
});
|
||||
return acc;
|
||||
}
|
||||
|
||||
const manifestRunner: TaskRunner<ManifestOptions> = async ({ folder }) => {
|
||||
const filename = 'MANIFEST.txt';
|
||||
const files = getFilePaths(folder).filter(f => f !== filename);
|
||||
|
||||
const originalDir = __dirname;
|
||||
process.chdir(folder);
|
||||
const out = await execa('sha1sum', files);
|
||||
|
||||
// Write the process output
|
||||
fs.writeFileSync(path.join(folder, filename), out.stdout);
|
||||
|
||||
// TODO:
|
||||
// gpg --output doc.sig --sign doc
|
||||
|
||||
// Go back to where you were
|
||||
process.chdir(originalDir);
|
||||
console.log('Wrote manifest: ', filename);
|
||||
};
|
||||
|
||||
export const manifestTask = new Task<ManifestOptions>('Build Manifest', manifestRunner);
|
@ -23,6 +23,8 @@ import { agregateWorkflowInfo, agregateCoverageInfo, agregateTestInfo } from '..
|
||||
import { PluginPackageDetails, PluginBuildReport, TestResultsInfo } from '../../plugins/types';
|
||||
import { runEndToEndTests } from '../../plugins/e2e/launcher';
|
||||
import { getEndToEndSettings } from '../../plugins/index';
|
||||
import { manifestTask } from './manifest';
|
||||
import { execTask } from '../utils/execTask';
|
||||
|
||||
export interface PluginCIOptions {
|
||||
backend?: boolean;
|
||||
@ -162,6 +164,9 @@ const packagePluginRunner: TaskRunner<PluginCIOptions> = async () => {
|
||||
}
|
||||
});
|
||||
|
||||
// Write a manifest.txt file in the dist folder
|
||||
await execTask(manifestTask)({ folder: distContentDir });
|
||||
|
||||
console.log('Building ZIP');
|
||||
let zipName = pluginInfo.id + '-' + pluginInfo.info.version + '.zip';
|
||||
let zipFile = path.resolve(packagesDir, zipName);
|
||||
|
Reference in New Issue
Block a user