Skip to content
Closed
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

- feat: Add deletion of stack after destroy (remove flag)

- feat: added support to install manually install plugins
[#810](https://github.com/pulumi/actions/pull/810)

--

## 3.20.0 (2022-11-10)
Expand Down
11 changes: 11 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,17 @@ inputs:
description: 'Colorize output. Choices are: always, never, raw, auto'
required: false
default: 'auto'
manual-plugins:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should name this config key plugins?

I'm not sure we can call them manual plugins. AFAIK, They are plugins that don't have an install script, we need to manually install them.

description: |
List of plugins to install using "pulumi.plugin.install" defined as an
YAML array. See the command help for all options
Example:
- kind: KIND
name: NAME
version: VERSION
flags:
server: URL to plugin
required: false
outputs:
output:
description: Output from running command
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"@types/dedent": "^0.7.0",
"@types/faker": "^6.6.9",
"@types/jest": "~27.5.0",
"@types/js-yaml": "^4.0.5",
"@types/node": "~17.0.41",
"@typescript-eslint/eslint-plugin": "~4.33.0",
"@typescript-eslint/parser": "~4.33.0",
Expand Down Expand Up @@ -51,6 +52,7 @@
"dedent": "^0.7.0",
"envalid": "^7.3.1",
"got": "^11.8.6",
"js-yaml": "^4.1.0",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have yaml installed; would it make sense to use yaml?

If you feel js-yaml is an improvement, feel free to open a separate PR on that 👍

"runtypes": "^6.6.0",
"semver": "^7.3.8",
"ts-invariant": "^0.10.3",
Expand Down
3 changes: 3 additions & 0 deletions src/__tests__/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ describe('config.ts', () => {
"configMap": undefined,
"githubToken": "n/a",
"isPullRequest": false,
"manualPlugins": Array [],
"options": Object {
"color": undefined,
"diff": undefined,
Expand Down Expand Up @@ -103,6 +104,7 @@ describe('config.ts', () => {
"configMap": undefined,
"githubToken": "n/a",
"isPullRequest": false,
"manualPlugins": Array [],
"options": Object {
"color": undefined,
"diff": undefined,
Expand Down Expand Up @@ -160,6 +162,7 @@ describe('config.ts', () => {
"configMap": undefined,
"githubToken": "n/a",
"isPullRequest": true,
"manualPlugins": Array [],
"options": Object {
"color": undefined,
"diff": undefined,
Expand Down
23 changes: 22 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getInput } from '@actions/core';
import { context } from '@actions/github';
import * as rt from 'runtypes';
import { parseArray, parseBoolean, parseNumber } from './libs/utils';
import { parseArray, parseBoolean, parseNumber, parseYAML } from './libs/utils';

export const command = rt.Union(
rt.Literal('up'),
Expand All @@ -28,6 +28,24 @@ export const options = rt.Partial({
pulumiVersion: rt.String,
});

export const manualPlugin = rt
.Record({
kind: rt.String,
name: rt.String,
})
.And(
rt.Partial({
version: rt.String,
flags: rt.Partial({
checksum: rt.String,
exact: rt.Boolean,
file: rt.String,
reinstall: rt.Boolean,
server: rt.String,
}),
}),
);

export const config = rt
.Record({
// Required options
Expand All @@ -38,6 +56,7 @@ export const config = rt
options: options,
// Information inferred from the environment that must be present
isPullRequest: rt.Boolean,
manualPlugins: rt.Array(manualPlugin),
})
.And(
rt.Partial({
Expand All @@ -54,6 +73,7 @@ export const config = rt
);

export type Config = rt.Static<typeof config>;
export type ManualPlugin = rt.Static<typeof manualPlugin>;

export async function makeConfig(): Promise<Config> {
return config.check({
Expand Down Expand Up @@ -85,5 +105,6 @@ export async function makeConfig(): Promise<Config> {
pulumiVersion: getInput('pulumi-version') || "^3",
color: getInput('color'),
},
manualPlugins: parseYAML(getInput('manual-plugins')) || [],
});
}
29 changes: 28 additions & 1 deletion src/libs/__tests__/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { parseArray, parseBoolean, parseNumber } from '../utils';
import { parseArray, parseBoolean, parseNumber, parseYAML } from '../utils';

describe('utils.ts', () => {
it('should parse input to array', () => {
Expand Down Expand Up @@ -37,4 +37,31 @@ describe('utils.ts', () => {
expect(parseNumber(falsy)).toBeNaN();
expect(parseNumber(undef)).toBeUndefined();
});

it('should parse YAML', () => {
const input = `
- key: first-key
value: first-value
- key: second-key
value: second-value
optionalValue: optional-value
`;
const parsed: {
key: string;
value: string;
optionalValue: string;
}[] = parseYAML(input);

expect(parsed).toStrictEqual([
{
key: 'first-key',
value: 'first-value',
},
{
key: 'second-key',
value: 'second-value',
optionalValue: 'optional-value',
},
]);
});
});
43 changes: 42 additions & 1 deletion src/libs/pulumi-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import * as path from 'path';
import * as core from '@actions/core';
import * as io from '@actions/io';
import * as tc from '@actions/tool-cache';
import * as semver from 'semver'
import * as semver from 'semver';
import { ManualPlugin } from '../config';
import * as exec from './exec';
import { getVersionObject } from './libs/get-version';

Expand Down Expand Up @@ -87,3 +88,43 @@ export async function downloadCli(range: string): Promise<void> {
const cachedPath = await tc.cacheDir(path.join(destination, 'bin'), 'pulumi', version);
core.addPath(cachedPath);
}

export async function installManualPlugins(
plugins: ManualPlugin[],
): Promise<void> {
if (plugins.length == 0) {
core.debug('No manual plugins defined');
return;
}
core.startGroup(`Installing ${plugins.length} manual plugins`);
for (const plugin of plugins) {
const params = ['plugin', 'install', plugin.kind, plugin.name];
if (plugin.version) {
params.push(plugin.version);
}
if (plugin.flags) {
const flags = plugin.flags;
if (flags.checksum) {
params.push('--checksum');
params.push(flags.checksum);
}
if (flags.exact) {
params.push('--exact');
}
if (flags.file) {
params.push('--file');
params.push(flags.file);
}
if (flags.reinstall) {
params.push('--reinstall');
}
if (flags.server) {
params.push('--server');
params.push(flags.server);
}
}
core.debug(`Installing plugin using: ${params.join(' ')}`);
await run(...params);
}
core.endGroup();
}
10 changes: 10 additions & 0 deletions src/libs/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import * as yaml from 'js-yaml';

export function parseArray(input: string): string[] {
return parseUndefined(input)
? input.split(/\r?\n/).reduce<string[]>(
Expand All @@ -22,3 +24,11 @@ export function parseBoolean(input: string): boolean | undefined {
export function parseNumber(input: string): number | undefined {
return parseUndefined(input) ? Number(input) : undefined;
}

export function parseYAML<T>(input: string): T | undefined {
const parsed = parseUndefined(input);
if (!parsed) {
return undefined;
}
return yaml.load(input) as T;
}
3 changes: 2 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const main = async () => {
core.debug('Configuration is loaded');

await pulumiCli.downloadCli(config.options.pulumiVersion);
await pulumiCli.installManualPlugins(config.manualPlugins);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
await pulumiCli.installManualPlugins(config.manualPlugins);
if (config.manualPlugins) {
await pulumiCli.installManualPlugins(config.manualPlugins);
}

await login(config.cloudUrl, environmentVariables.PULUMI_ACCESS_TOKEN);

const workDir = resolve(
Expand Down Expand Up @@ -100,7 +101,7 @@ const main = async () => {
}

if (config.remove && config.command === 'destroy') {
stack.workspace.removeStack(stack.name)
stack.workspace.removeStack(stack.name);
}

core.endGroup();
Expand Down
17 changes: 17 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -981,6 +981,11 @@
jest-matcher-utils "^27.0.0"
pretty-format "^27.0.0"

"@types/js-yaml@^4.0.5":
version "4.0.5"
resolved "https://registry.yarnpkg.com/@types/js-yaml/-/js-yaml-4.0.5.tgz#738dd390a6ecc5442f35e7f03fa1431353f7e138"
integrity sha512-FhpRzf927MNQdRZP0J5DLIdTXhjLYzeUTmLAu69mnVksLH9CJY3IuSeEgbKUki7GQZm0WqDkGzyxju2EZGD2wA==

"@types/json-buffer@~3.0.0":
version "3.0.0"
resolved "https://registry.yarnpkg.com/@types/json-buffer/-/json-buffer-3.0.0.tgz#85c1ff0f0948fc159810d4b5be35bf8c20875f64"
Expand Down Expand Up @@ -1305,6 +1310,11 @@ argparse@^1.0.7:
dependencies:
sprintf-js "~1.0.2"

argparse@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/argparse/-/argparse-2.0.1.tgz#246f50f3ca78a3240f6c997e8a9bd1eac49e4b38"
integrity sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==

arr-diff@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/arr-diff/-/arr-diff-4.0.0.tgz#d6461074febfec71e7e15235761a329a5dc7c520"
Expand Down Expand Up @@ -3662,6 +3672,13 @@ js-yaml@^3.13.1, js-yaml@^3.14.0:
argparse "^1.0.7"
esprima "^4.0.0"

js-yaml@^4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-4.1.0.tgz#c1fb65f8f5017901cdd2c951864ba18458a10602"
integrity sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==
dependencies:
argparse "^2.0.1"

jsdom@^16.4.0:
version "16.7.0"
resolved "https://registry.yarnpkg.com/jsdom/-/jsdom-16.7.0.tgz#918ae71965424b197c819f8183a754e18977b710"
Expand Down