diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5a17bc8e..c7425957 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -41,4 +41,4 @@ jobs: cloud-url: file://~ stack-name: dev work-dir: .github/test-stacks/golang - - run: echo "The random string is ${{ steps.pulumi.outputs.name }}" + - run: echo "The random string is `${{ steps.pulumi.outputs.name }}`" diff --git a/.github/workflows/workflow_options.yml b/.github/workflows/workflow_options.yml index 39dd1267..355066b0 100644 --- a/.github/workflows/workflow_options.yml +++ b/.github/workflows/workflow_options.yml @@ -9,7 +9,7 @@ on: jobs: test-workflow: runs-on: ${{ matrix.os }} - name: Testing Pulumi ${{ matrix.command }} on ${{ matrix.os }} + name: Testing arguments - ${{ matrix.command }} on ${{ matrix.os }} strategy: matrix: command: [ up, refresh, destroy, preview ] @@ -43,3 +43,36 @@ jobs: message: this-is-just-a-test expect-no-changes: false diff: true + test-refresh-and-upsert: + runs-on: ${{ matrix.os }} + name: Testing refresh/upsert – ${{ matrix.command }} on ${{ matrix.os }} + strategy: + matrix: + command: [ up, refresh, destroy, preview ] + os: [ubuntu-latest, macos-latest, windows-latest] + fail-fast: false + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v1 + with: + node-version: 14.x + - name: Install pulumi + uses: pulumi/action-install-pulumi-cli@v1.0.1 + - name: Create local stack + run: | + pulumi login --local + working-directory: .github/test-stacks/nodejs + env: + PULUMI_CONFIG_PASSPHRASE: not-a-secret + - run: npm install + working-directory: .github/test-stacks/nodejs + - uses: ./ + env: + PULUMI_CONFIG_PASSPHRASE: not-a-secret + with: + command: ${{ matrix.command }} + cloud-url: file://~ + stack-name: dev + work-dir: .github/test-stacks/nodejs + upsert: true + refresh: true diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ec2120f..4afc177c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,8 @@ ## HEAD (Unreleased) -_(none)_ +- Add ability to refresh a stack by passing `refresh: true` + [#128](https://github.com/pulumi/actions/pull/128) --- diff --git a/README.md b/README.md index acfb58cc..3bb5f2a2 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ The action can be configured with the following arguments: - `command` (required) - The command to pass to the Pulumi CLI. Accepted values are `up` (update), `refresh`, `destroy` and `preview`. This command is the - equivalent of running `pulumi ` if your terminal. + equivalent of running `pulumi ` if your terminal. - `stack-name` (required) - The name of the stack that Pulumi will be operating on @@ -60,6 +60,9 @@ The action can be configured with the following arguments: - `github-token` - (required if comment-on-pr) A GitHub token that has access levels to allow the Action to comment on a PR. +- `refresh` - (optional) If `true`, stack is refreshed before running the + `command`. + ### Extra options - `parallel` - (optional) Allow P resource operations to run in parallel at once @@ -81,6 +84,11 @@ The action can be configured with the following arguments: - `target-dependents` - (optional) Allows updating of dependent targets discovered but not specified in target. +- `upsert` - (optiona) Allows the creation of the specified stack if it + currently doesn't exist. + **PLEASE NOTE:** This will create a Pulumi..yaml file that you + will need to add back to source control as part of the action if you wish to + perform any further tasks with that stack. By default, this action will try to authenticate Pulumi with the [Pulumi SaaS](https://app.pulumi.com/). If you have not specified a diff --git a/action.yml b/action.yml index cfd70898..5269b5ba 100644 --- a/action.yml +++ b/action.yml @@ -51,6 +51,14 @@ inputs: description: 'Allows updating of dependent targets discovered but not specified in target.' required: false default: 'false' + refresh: + description: 'Perform a stack refresh as part of the operation' + required: false + default: 'false' + upsert: + description: 'Create the stack if it currently does not exist' + required: false + default: 'false' outputs: output: description: Output from running command diff --git a/src/config.ts b/src/config.ts index f22132e6..181fa1e4 100644 --- a/src/config.ts +++ b/src/config.ts @@ -37,6 +37,7 @@ export const config = rt cloudUrl: rt.String, githubToken: rt.String, upsert: rt.Boolean, + refresh: rt.Boolean, }), ); @@ -51,6 +52,7 @@ export async function makeConfig(): Promise { githubToken: getInput('github-token'), commentOnPr: parseBoolean(getInput('comment-on-pr')), upsert: parseBoolean(getInput('upsert')), + refresh: parseBoolean(getInput('refresh')), options: { parallel: parseNumber(getInput('parallel')), message: getInput('message'), diff --git a/src/main.ts b/src/main.ts index 151bc259..81582cd0 100644 --- a/src/main.ts +++ b/src/main.ts @@ -37,13 +37,19 @@ const main = async () => { ? LocalWorkspace.createOrSelectStack(stackArgs) : LocalWorkspace.selectStack(stackArgs)); - core.startGroup(`pulumi ${config.command} on ${config.stackName}`); - const onOutput = (msg: string) => { core.debug(msg); core.info(msg); }; + if (config.refresh) { + core.startGroup(`Refresh stack on ${config.stackName}`); + await stack.refresh({ onOutput }); + core.endGroup(); + } + + core.startGroup(`pulumi ${config.command} on ${config.stackName}`); + const actions: Record Promise> = { up: () => stack.up({ onOutput, ...config.options }).then((r) => r.stdout), update: () =>