Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions e2e-version/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@ By default, this actions resolves an image for the latest build of the main bran

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

### `plugin-path`

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.

```yaml
- name: Resolve Grafana E2E versions
id: resolve-versions
uses: grafana/plugin-actions/e2e-version@e2e-version/v1.2.1
with:
version-resolver-type: plugin-grafana-dependency
plugin-path: plugin
```

### `version-resolver-type`

The action supports two modes.
Expand Down
4 changes: 4 additions & 0 deletions e2e-version/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ inputs:
required: false
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.'
type: string
plugin-path:
required: false
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).'
type: string
limit:
required: false
description: 'The maximum number of versions to resolve. Default is 6, 0 means no limit.'
Expand Down
2 changes: 1 addition & 1 deletion e2e-version/dist/index.js

Large diffs are not rendered by default.

11 changes: 8 additions & 3 deletions e2e-version/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const SkipGrafanaDevImageInput = 'skip-grafana-dev-image';
const SkipGrafanaReact19PreviewImageInput = 'skip-grafana-react-19-preview-image';
const VersionResolverTypeInput = 'version-resolver-type';
const GrafanaDependencyInput = 'grafana-dependency';
const PluginPathInput = 'plugin-path';
const LimitInput = 'limit';
const MatrixOutput = 'matrix';

Expand Down Expand Up @@ -44,6 +45,7 @@ async function run() {
}

const grafanaDependency = core.getInput(GrafanaDependencyInput);
const pluginPath = core.getInput(PluginPathInput);
const versionResolverType = core.getInput(VersionResolverTypeInput) || VersionResolverTypes.PluginGrafanaDependency;
const limit = parseInt(core.getInput(LimitInput));
const availableGrafanaVersions = await getGrafanaStableMinorVersions();
Expand Down Expand Up @@ -72,7 +74,7 @@ async function run() {
break;
default:
const pluginDependency =
grafanaDependency === '' ? await getPluginGrafanaDependencyFromPluginJson() : grafanaDependency;
grafanaDependency === '' ? await getPluginGrafanaDependencyFromPluginJson(pluginPath) : grafanaDependency;
console.log(`Found version requirement ${pluginDependency}`);
for (const grafanaVersion of availableGrafanaVersions) {
if (semver.satisfies(grafanaVersion.version, pluginDependency)) {
Expand Down Expand Up @@ -166,8 +168,9 @@ async function getGrafanaStableMinorVersions() {
return Array.from(latestMinorVersions).map(([_, semver]) => semver);
}

async function getPluginGrafanaDependencyFromPluginJson() {
const file = await fs.readFile(path.resolve(path.join(process.cwd(), 'src'), 'plugin.json'), 'utf8');
async function getPluginGrafanaDependencyFromPluginJson(pluginPath) {
const basePath = pluginPath || process.cwd();
const file = await fs.readFile(path.resolve(path.join(basePath, 'src'), 'plugin.json'), 'utf8');
const json = JSON.parse(file);
if (!json.dependencies.grafanaDependency) {
throw new Error('Could not find plugin grafanaDependency');
Expand All @@ -182,4 +185,6 @@ module.exports = {
VersionResolverTypeInput,
VersionResolverTypes,
GrafanaDependencyInput,
PluginPathInput,
LimitInput,
};
8 changes: 7 additions & 1 deletion e2e-version/index.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { run, VersionResolverTypeInput, VersionResolverTypes, GrafanaDependencyInput } = require('./index');
const { run, VersionResolverTypeInput, VersionResolverTypes, GrafanaDependencyInput, PluginPathInput, LimitInput } = require('./index');
const mockVersions = require('./mocks/versions');
const { getInput, getBooleanInput } = require('@actions/core');

Expand Down Expand Up @@ -48,6 +48,12 @@ describe('plugin-grafana-dependency mode', () => {
if (name === GrafanaDependencyInput) {
return t.grafanaDependency;
}
if (name === PluginPathInput) {
return '';
}
if (name === LimitInput) {
return '6';
}
});
getBooleanInput.mockReturnValue(true);
const images = await run();
Expand Down
Loading