Skip to content

Commit c81db32

Browse files
committed
support reading plugin.json from alternative path
1 parent 4698961 commit c81db32

5 files changed

Lines changed: 33 additions & 5 deletions

File tree

e2e-version/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,19 @@ By default, this actions resolves an image for the latest build of the main bran
1212

1313
The maximum number of versions to resolve. Default is 6, 0 means no limit.
1414

15+
### `plugin-path`
16+
17+
Only applies when using `plugin-grafana-dependency` mode without a `grafana-dependency` override. Path to the plugin root directory — the directory that contains the `src/plugin.json` file. Defaults to the repository root. Use this when the plugin is in a subdirectory rather than at the root of the repository.
18+
19+
```yaml
20+
- name: Resolve Grafana E2E versions
21+
id: resolve-versions
22+
uses: grafana/plugin-actions/e2e-version@e2e-version/v1.2.1
23+
with:
24+
version-resolver-type: plugin-grafana-dependency
25+
plugin-path: plugin
26+
```
27+
1528
### `version-resolver-type`
1629

1730
The action supports two modes.

e2e-version/action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ inputs:
2626
required: false
2727
description: 'Optionally, use this input to pass a semver range of supported Grafana versions to test against. This is only used when version-resolver-type is plugin-grafana-dependency. If not provided, the action will try to read grafanaDependency from the plugin.json file.'
2828
type: string
29+
plugin-path:
30+
required: false
31+
description: 'Only applies when version-resolver-type is plugin-grafana-dependency and grafana-dependency is not set. Path to the plugin root directory containing src/plugin.json. Defaults to the repository root. Useful when the plugin is in a subdirectory (e.g. plugin).'
32+
type: string
2933
limit:
3034
required: false
3135
description: 'The maximum number of versions to resolve. Default is 6, 0 means no limit.'

e2e-version/dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

e2e-version/index.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const SkipGrafanaDevImageInput = 'skip-grafana-dev-image';
88
const SkipGrafanaReact19PreviewImageInput = 'skip-grafana-react-19-preview-image';
99
const VersionResolverTypeInput = 'version-resolver-type';
1010
const GrafanaDependencyInput = 'grafana-dependency';
11+
const PluginPathInput = 'plugin-path';
1112
const LimitInput = 'limit';
1213
const MatrixOutput = 'matrix';
1314

@@ -44,6 +45,7 @@ async function run() {
4445
}
4546

4647
const grafanaDependency = core.getInput(GrafanaDependencyInput);
48+
const pluginPath = core.getInput(PluginPathInput);
4749
const versionResolverType = core.getInput(VersionResolverTypeInput) || VersionResolverTypes.PluginGrafanaDependency;
4850
const limit = parseInt(core.getInput(LimitInput));
4951
const availableGrafanaVersions = await getGrafanaStableMinorVersions();
@@ -72,7 +74,7 @@ async function run() {
7274
break;
7375
default:
7476
const pluginDependency =
75-
grafanaDependency === '' ? await getPluginGrafanaDependencyFromPluginJson() : grafanaDependency;
77+
grafanaDependency === '' ? await getPluginGrafanaDependencyFromPluginJson(pluginPath) : grafanaDependency;
7678
console.log(`Found version requirement ${pluginDependency}`);
7779
for (const grafanaVersion of availableGrafanaVersions) {
7880
if (semver.satisfies(grafanaVersion.version, pluginDependency)) {
@@ -166,8 +168,9 @@ async function getGrafanaStableMinorVersions() {
166168
return Array.from(latestMinorVersions).map(([_, semver]) => semver);
167169
}
168170

169-
async function getPluginGrafanaDependencyFromPluginJson() {
170-
const file = await fs.readFile(path.resolve(path.join(process.cwd(), 'src'), 'plugin.json'), 'utf8');
171+
async function getPluginGrafanaDependencyFromPluginJson(pluginPath) {
172+
const basePath = pluginPath || process.cwd();
173+
const file = await fs.readFile(path.resolve(path.join(basePath, 'src'), 'plugin.json'), 'utf8');
171174
const json = JSON.parse(file);
172175
if (!json.dependencies.grafanaDependency) {
173176
throw new Error('Could not find plugin grafanaDependency');
@@ -182,4 +185,6 @@ module.exports = {
182185
VersionResolverTypeInput,
183186
VersionResolverTypes,
184187
GrafanaDependencyInput,
188+
PluginPathInput,
189+
LimitInput,
185190
};

e2e-version/index.test.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { run, VersionResolverTypeInput, VersionResolverTypes, GrafanaDependencyInput } = require('./index');
1+
const { run, VersionResolverTypeInput, VersionResolverTypes, GrafanaDependencyInput, PluginPathInput, LimitInput } = require('./index');
22
const mockVersions = require('./mocks/versions');
33
const { getInput, getBooleanInput } = require('@actions/core');
44

@@ -48,6 +48,12 @@ describe('plugin-grafana-dependency mode', () => {
4848
if (name === GrafanaDependencyInput) {
4949
return t.grafanaDependency;
5050
}
51+
if (name === PluginPathInput) {
52+
return '';
53+
}
54+
if (name === LimitInput) {
55+
return '6';
56+
}
5157
});
5258
getBooleanInput.mockReturnValue(true);
5359
const images = await run();

0 commit comments

Comments
 (0)