Skip to content

Commit

Permalink
fix: modify types and add GH workflow test
Browse files Browse the repository at this point in the history
  • Loading branch information
SharaevN committed Dec 28, 2022
1 parent 68442af commit 00c493b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
10 changes: 9 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ on: # rebuild any PRs and main branch changes
- 'CHANGELOG.md'
- 'README.md'

env:
TEST_PLUGIN_NAME: "time"
TEST_PLUGIN_VERSION: "0.0.9"
TEST_PLUGIN_SERVER: "https://github.com/pulumiverse/pulumi-time/releases/download/v0.0.9"

jobs:
build-test: # make sure build/ci work properly
runs-on: ubuntu-latest
Expand Down Expand Up @@ -55,5 +60,8 @@ jobs:
upsert: true
work-dir: .github/test-stacks/golang
config-map: "{name: {value: test, secret: false}}"
plugins: "[{name: time, version: 0.0.9, kind: resource}]"
plugins: "[{name: ${{ env.TEST_PLUGIN_NAME }}, version: ${{ env.TEST_PLUGIN_VERSION }}, server: ${{ env.TEST_PLUGIN_SERVER }}}]"
- run: echo 'The random string is `${{ steps.pulumi.outputs.name }}`'
- run: |
pulumi plugin ls | grep ${{ env.TEST_PLUGIN_NAME }} | grep ${{ env.TEST_PLUGIN_VERSION }}
exit $?
6 changes: 3 additions & 3 deletions src/__tests__/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ describe('config.ts', () => {
"targetDependents": undefined,
"userAgent": "pulumi/actions@v3",
},
"plugins": Array [],
"refresh": undefined,
"remove": undefined,
"plugins": undefined,
"secretsProvider": undefined,
"stackName": "dev",
"upsert": undefined,
Expand Down Expand Up @@ -119,9 +119,9 @@ describe('config.ts', () => {
"targetDependents": undefined,
"userAgent": "pulumi/actions@v3",
},
"plugins": Array [],
"refresh": undefined,
"remove": undefined,
"plugins": undefined,
"secretsProvider": undefined,
"stackName": "dev",
"upsert": undefined,
Expand Down Expand Up @@ -177,9 +177,9 @@ describe('config.ts', () => {
"targetDependents": undefined,
"userAgent": "pulumi/actions@v3",
},
"plugins": Array [],
"refresh": undefined,
"remove": undefined,
"plugins": undefined,
"secretsProvider": undefined,
"stackName": "dev",
"upsert": undefined,
Expand Down
8 changes: 4 additions & 4 deletions 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, parsePlugins } from './libs/utils';

export const command = rt.Union(
rt.Literal('up'),
Expand All @@ -18,8 +18,8 @@ const plugin = rt.Partial({
server: rt.String,
kind: rt.String
});
type Plugin = rt.Static<typeof plugin>;
type Plugins = Plugin[];
export type Plugin = rt.Static<typeof plugin>;
export type Plugins = Plugin[];

export const options = rt.Partial({
parallel: rt.Number,
Expand Down Expand Up @@ -78,7 +78,7 @@ export async function makeConfig(): Promise<Config> {
remove: parseBoolean(getInput('remove')),
refresh: parseBoolean(getInput('refresh')),
configMap: getInput('config-map'),
plugins: JSON.parse(getInput('plugins')) as Plugins,
plugins: parsePlugins(getInput('plugins')),
isPullRequest: context?.payload?.pull_request !== undefined,
options: {
parallel: parseNumber(getInput('parallel')),
Expand Down
12 changes: 12 additions & 0 deletions src/libs/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import YAML from 'yaml';
import { Plugin, Plugins } from '../config';

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

export function parsePlugins(input: string): Plugins {
if (parseUndefined(input)) {
const plugins = YAML.parse(input);
return plugins.map(plugin => plugin as Plugin) as Plugins;
} else {
return [] as Plugins;
}
}

0 comments on commit 00c493b

Please sign in to comment.