From 571f254aae8d2477ed8f3d4440cf8711da8d22ee Mon Sep 17 00:00:00 2001 From: lakkeger Date: Tue, 14 May 2024 15:37:52 +0200 Subject: [PATCH 01/29] feat: add dynamic startup --- action.yml | 50 +++++++++++----------------------- startup/action.yml | 67 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+), 34 deletions(-) create mode 100644 startup/action.yml diff --git a/action.yml b/action.yml index 462ef60..4561066 100644 --- a/action.yml +++ b/action.yml @@ -39,41 +39,23 @@ inputs: runs: using: "composite" steps: - - name: Initial PR comment - # TODO: potentially replace with Action version number over time - uses: LocalStack/setup-localstack/prepare@main - if: inputs.ci-project && inputs.github-token - with: - github-token: ${{ inputs.github-token }} - ci-project: ${{ inputs.ci-project }} - - - name: Start LocalStack - run: | - pip install pyopenssl -U - - if [ "$USE_PRO" = true ]; then - docker pull localstack/localstack-pro:"$IMAGE_TAG" & - CONFIGURATION="$CONFIGURATION DNS_ADDRESS=127.0.0.1" - else - docker pull localstack/localstack:"$IMAGE_TAG" & - fi - - pip install localstack - if [ "$INSTALL_AWSLOCAL" = true ]; then - pip install awscli-local[ver1] - fi - - export CI_PROJECT=${{ inputs.ci-project }} - eval "${CONFIGURATION} localstack start -d" - - localstack wait -t 30 - - shell: bash + # - name: Initial PR comment + # # TODO: potentially replace with Action version number over time + # uses: LocalStack/setup-localstack/prepare@main + # if: inputs.ci-project && inputs.github-token + # with: + # github-token: ${{ inputs.github-token }} + # ci-project: ${{ inputs.ci-project }} + + - name: Start Localstack + uses: jenseng/dynamic-uses@v1 env: - IMAGE_TAG: "${{ inputs.image-tag }}" - INSTALL_AWSLOCAL: "${{ inputs.install-awslocal }}" - USE_PRO: "${{ inputs.use-pro }}" - CONFIGURATION: "${{ inputs.configuration }}" + action-version: ${{ fromJSON(format('["{0}","{1}"]', github.ref_name, github.head_ref))[github.event_name == 'pull_request'] }} + with: + # now you can use expressions 🥳 + uses: LocalStack/setup-localstack/startup@${{ env.action-version }} + # the `with` needs to be converted to a valid json string + with: "${{ toJSON(inputs) }}" # TODO: potentially add an additional step here to create preview envs, and add a switch to # enable/disable the "Start LocalStack" action above. This way we could make this action diff --git a/startup/action.yml b/startup/action.yml new file mode 100644 index 0000000..861e806 --- /dev/null +++ b/startup/action.yml @@ -0,0 +1,67 @@ +name: 'Start up Localstack' + +inputs: + image-tag: + description: 'Tag of the LocalStack Docker image to use' + required: true + default: 'latest' + install-awslocal: + description: 'Whether to install the `awslocal` CLI into the environment' + required: true + default: 'true' + use-pro: + description: 'Whether to use LocalStack Pro (requires a valid API key)' + required: false + default: 'false' + configuration: + description: 'Configuration variables to use for LocalStack' + required: false + default: '' + ci-project: + description: 'Name of the CI project to track in LocalStack Cloud' + required: false + default: '' + +runs: + using: "composite" + steps: + # - name: Initial PR comment + # # TODO: potentially replace with Action version number over time + # uses: LocalStack/setup-localstack/prepare@main + # if: inputs.ci-project && inputs.github-token + # with: + # github-token: ${{ inputs.github-token }} + # ci-project: ${{ inputs.ci-project }} + + - name: Start LocalStack + run: | + pip install pyopenssl -U + + if [ "$USE_PRO" = true ]; then + docker pull localstack/localstack-pro:"$IMAGE_TAG" & + CONFIGURATION="$CONFIGURATION DNS_ADDRESS=127.0.0.1" + else + docker pull localstack/localstack:"$IMAGE_TAG" & + fi + + pip install localstack + if [ "$INSTALL_AWSLOCAL" = true ]; then + pip install awscli-local[ver1] + fi + + export CI_PROJECT=${{ inputs.ci-project }} + eval "${CONFIGURATION} localstack start -d" + + localstack wait -t 30 + + shell: bash + env: + IMAGE_TAG: "${{ inputs.image-tag }}" + INSTALL_AWSLOCAL: "${{ inputs.install-awslocal }}" + USE_PRO: "${{ inputs.use-pro }}" + CONFIGURATION: "${{ inputs.configuration }}" + + # TODO: potentially add an additional step here to create preview envs, and add a switch to + # enable/disable the "Start LocalStack" action above. This way we could make this action + # the single entry point which then delegates to sub-actions in this repo, based on the + # user-provided configuration... From 23c69e112f321f299c0932a6a5c9e75c9a94e8be Mon Sep 17 00:00:00 2001 From: lakkeger Date: Wed, 15 May 2024 13:07:36 +0200 Subject: [PATCH 02/29] feat: add new variables and logic --- .github/workflows/ci.yml | 7 +++-- action.yml | 60 ++++++++++++++++++++++++++++++---------- 2 files changed, 50 insertions(+), 17 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0cb422c..e0aa4a8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -51,9 +51,10 @@ jobs: awslocal sqs create-queue --queue-name test-queue - name: Save the Cloud Pod - uses: LocalStack/setup-localstack/cloud-pods@main + uses: ./ with: - name: cloud-pods-test - action: save + state-name: cloud-pods-test + state-action: save + no-startup: 'true' env: LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }} diff --git a/action.yml b/action.yml index 4561066..fc7a43b 100644 --- a/action.yml +++ b/action.yml @@ -35,29 +35,61 @@ inputs: description: 'Command(s) used to create a preview of the PR (can use $AWS_ENDPOINT_URL)' required: false default: '' + no-startup: + description: | + Explicitly prevent LocalStack start up. + Useful to manage state later on in the pipeline or start up ephemeral instance + required: true + default: 'false' + state-action: + description: | + Manage LocalStack state + Valid values are `load``, `save`, `` + Defaults to `` (empty) -> don't manage state + required: false + default: '' + state-local: + description: | + Either store the state of LocalStack locally or as a cloud pod. + Valid values are `cloud-pods` or `local`. + Use this option in unison with `state-action` to control behaviour. + required: false + default: 'cloud-pods' + state-name: + description: 'Name of the state artifact' + required: false runs: using: "composite" steps: - # - name: Initial PR comment - # # TODO: potentially replace with Action version number over time - # uses: LocalStack/setup-localstack/prepare@main - # if: inputs.ci-project && inputs.github-token - # with: - # github-token: ${{ inputs.github-token }} - # ci-project: ${{ inputs.ci-project }} - - name: Start Localstack uses: jenseng/dynamic-uses@v1 + if: ${{ inputs.no-startup != 'true' }} env: action-version: ${{ fromJSON(format('["{0}","{1}"]', github.ref_name, github.head_ref))[github.event_name == 'pull_request'] }} with: - # now you can use expressions 🥳 + # now we can dynamically determine sub-action versions 🥳 uses: LocalStack/setup-localstack/startup@${{ env.action-version }} # the `with` needs to be converted to a valid json string - with: "${{ toJSON(inputs) }}" + with: |- + { + "image-tag": "${{ inputs.image-tag }}", + "install-awslocal": "${{ inputs.install-awslocal }}", + "use-pro": "${{ inputs.use-pro }}", + "configuration": "${{ inputs.configuration }}", + "ci-project": "${{ inputs.ci-project }}" + } - # TODO: potentially add an additional step here to create preview envs, and add a switch to - # enable/disable the "Start LocalStack" action above. This way we could make this action - # the single entry point which then delegates to sub-actions in this repo, based on the - # user-provided configuration... + # Use different artifact from current workflow's by passing the workflow's id as WORKFLOW_ID env variable + - name: Manage state + if: ${{ (inputs.state-action == 'save' || inputs.state-action == 'load') }} + uses: jenseng/dynamic-uses@v1 + env: + action-version: ${{ fromJSON(format('["{0}","{1}"]', github.ref_name, github.head_ref))[github.event_name == 'pull_request'] }} + with: + uses: LocalStack/setup-localstack/${{ inputs.state-local }}@${{ env.action-version }} + with: |- + { + "name": "${{ inputs.state-name }}", + "action": "${{ inputs.state-action }}" + } From 4c796da5de5d9b9c4aaef51904b65901861c89af Mon Sep 17 00:00:00 2001 From: lakkeger Date: Wed, 15 May 2024 14:00:35 +0200 Subject: [PATCH 03/29] feat: Add local state management --- local/action.yml | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 local/action.yml diff --git a/local/action.yml b/local/action.yml new file mode 100644 index 0000000..3afd5b9 --- /dev/null +++ b/local/action.yml @@ -0,0 +1,46 @@ +name: 'Save/Load LocalStack state' + +inputs: + name: + description: 'Name of the artifact' + required: true + default: 'ls-state' + action: + description: 'Action to perform (save or load)' + required: true + default: 'save' + +runs: + using: "composite" + steps: + - name: Download PR artifact + uses: dawidd6/action-download-artifact@v2 + if: ${{ inputs.action == 'load' }} + env: + workflow_id: ${{ fromJSON(format('["{0}","{1}"]', env.WORKFLOW_ID, github.event.workflow_run.workflow_id))[env.WORKFLOW_ID == ''] }} + with: + workflow: + name: ${{ inputs.name }} + + - run: | + if [ "$ACTION" = "save" ]; then + echo "Saving State $NAME" + localstack state export $NAME + elif [ "$ACTION" = "load" ]; then + echo "Loading State $NAME" + localstack state import $NAME + else + echo "Invalid action: $ACTION" + exit 1 + fi + shell: bash + env: + NAME: "${{ inputs.name }}" + ACTION: "${{ inputs.action }}" + + - name: Upload LocalStack State + uses: actions/upload-artifact@v3 + if: ${{ inputs.action == 'save' }} + with: + name: ${{ inputs.name }} + path: ./${{ inputs.name }}.zip From 5f892cb807e1840ee9bcdcc7d0dd242084cef691 Mon Sep 17 00:00:00 2001 From: lakkeger Date: Wed, 15 May 2024 14:01:09 +0200 Subject: [PATCH 04/29] feat(startup): add warning if use-pro used but no key provided --- startup/action.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/startup/action.yml b/startup/action.yml index 861e806..182c21d 100644 --- a/startup/action.yml +++ b/startup/action.yml @@ -38,6 +38,9 @@ runs: pip install pyopenssl -U if [ "$USE_PRO" = true ]; then + if [ "x$LOCALSTACK_AUTH_TOKEN" = "x" || "x$LOCALSTACK_API_KEY" = "x" ]; then + echo "WARNING: LocalStack API key not detected, please verify your configuration..." + fi docker pull localstack/localstack-pro:"$IMAGE_TAG" & CONFIGURATION="$CONFIGURATION DNS_ADDRESS=127.0.0.1" else @@ -61,7 +64,3 @@ runs: USE_PRO: "${{ inputs.use-pro }}" CONFIGURATION: "${{ inputs.configuration }}" - # TODO: potentially add an additional step here to create preview envs, and add a switch to - # enable/disable the "Start LocalStack" action above. This way we could make this action - # the single entry point which then delegates to sub-actions in this repo, based on the - # user-provided configuration... From f97de5cbd5492f6bc6abd7a8d7e92730d923a90e Mon Sep 17 00:00:00 2001 From: lakkeger Date: Wed, 15 May 2024 15:51:05 +0200 Subject: [PATCH 05/29] feat(startup): add skip wait --- startup/action.yml | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/startup/action.yml b/startup/action.yml index 182c21d..b06211e 100644 --- a/startup/action.yml +++ b/startup/action.yml @@ -21,6 +21,10 @@ inputs: description: 'Name of the CI project to track in LocalStack Cloud' required: false default: '' + skip-wait: + description: 'Skip wait for LocalStack' + required: false + default: 'false' runs: using: "composite" @@ -55,12 +59,11 @@ runs: export CI_PROJECT=${{ inputs.ci-project }} eval "${CONFIGURATION} localstack start -d" - localstack wait -t 30 + if [ "$SKIP_WAIT" = false ]; then + localstack wait -t ${LS_WAIT_TIMEOUT:-30} # Let users configure the timeout via env variable + fi shell: bash env: - IMAGE_TAG: "${{ inputs.image-tag }}" - INSTALL_AWSLOCAL: "${{ inputs.install-awslocal }}" - USE_PRO: "${{ inputs.use-pro }}" - CONFIGURATION: "${{ inputs.configuration }}" + SKIP_WAIT: ${{ inputs.skip-wait }} From 39f4048cd15f8b2c1520725f40f9cd487202cf8d Mon Sep 17 00:00:00 2001 From: lakkeger Date: Wed, 15 May 2024 15:52:28 +0200 Subject: [PATCH 06/29] style(startup): remove unnecessary quotes --- startup/action.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/startup/action.yml b/startup/action.yml index b06211e..d4e8201 100644 --- a/startup/action.yml +++ b/startup/action.yml @@ -29,6 +29,7 @@ inputs: runs: using: "composite" steps: + # # NOTE: Thinking about this if we need it # - name: Initial PR comment # # TODO: potentially replace with Action version number over time # uses: LocalStack/setup-localstack/prepare@main @@ -65,5 +66,9 @@ runs: shell: bash env: + IMAGE_TAG: ${{ inputs.image-tag }} + INSTALL_AWSLOCAL: ${{ inputs.install-awslocal }} + USE_PRO: ${{ inputs.use-pro }} + CONFIGURATION: ${{ inputs.configuration }} SKIP_WAIT: ${{ inputs.skip-wait }} From 36ffc44e45391e0dda996d3b4da0cb172e63a446 Mon Sep 17 00:00:00 2001 From: lakkeger Date: Wed, 15 May 2024 15:55:27 +0200 Subject: [PATCH 07/29] feat: add skips --- action.yml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/action.yml b/action.yml index fc7a43b..01b8fe3 100644 --- a/action.yml +++ b/action.yml @@ -35,12 +35,16 @@ inputs: description: 'Command(s) used to create a preview of the PR (can use $AWS_ENDPOINT_URL)' required: false default: '' - no-startup: + skip-startup: description: | Explicitly prevent LocalStack start up. Useful to manage state later on in the pipeline or start up ephemeral instance required: true default: 'false' + skip-wait: + description: Skip wait for LocalStack + required: false + default: 'false' state-action: description: | Manage LocalStack state @@ -64,7 +68,7 @@ runs: steps: - name: Start Localstack uses: jenseng/dynamic-uses@v1 - if: ${{ inputs.no-startup != 'true' }} + if: ${{ inputs.skip-startup != 'true' }} env: action-version: ${{ fromJSON(format('["{0}","{1}"]', github.ref_name, github.head_ref))[github.event_name == 'pull_request'] }} with: @@ -77,7 +81,8 @@ runs: "install-awslocal": "${{ inputs.install-awslocal }}", "use-pro": "${{ inputs.use-pro }}", "configuration": "${{ inputs.configuration }}", - "ci-project": "${{ inputs.ci-project }}" + "ci-project": "${{ inputs.ci-project }}", + "skip-wait": "${{ inputs.skip-wait }}" } # Use different artifact from current workflow's by passing the workflow's id as WORKFLOW_ID env variable From b413119cadfe576576ad9f28d20e04e0dc314979 Mon Sep 17 00:00:00 2001 From: lakkeger Date: Wed, 15 May 2024 15:57:09 +0200 Subject: [PATCH 08/29] feat(tools): add action to install tools --- action.yml | 13 +++++++++++++ startup/action.yml | 21 ++++++++++++++------- tools/action.yml | 24 ++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 7 deletions(-) create mode 100644 tools/action.yml diff --git a/action.yml b/action.yml index 01b8fe3..26ab48d 100644 --- a/action.yml +++ b/action.yml @@ -66,6 +66,18 @@ inputs: runs: using: "composite" steps: + - name: Install tools + uses: jenseng/dynamic-uses@v1 + if: ${{ inputs.skip-startup == 'true' }} + env: + action-version: ${{ fromJSON(format('["{0}","{1}"]', github.ref_name, github.head_ref))[github.event_name == 'pull_request'] }} + with: + uses: LocalStack/setup-localstack/tools@${{ env.action-version }} + with: |- + { + "install-awslocal": "${{ inputs.install-awslocal }}", + } + - name: Start Localstack uses: jenseng/dynamic-uses@v1 if: ${{ inputs.skip-startup != 'true' }} @@ -75,6 +87,7 @@ runs: # now we can dynamically determine sub-action versions 🥳 uses: LocalStack/setup-localstack/startup@${{ env.action-version }} # the `with` needs to be converted to a valid json string + # keeping in there install-awslocal for backward compatibility with: |- { "image-tag": "${{ inputs.image-tag }}", diff --git a/startup/action.yml b/startup/action.yml index d4e8201..af3552c 100644 --- a/startup/action.yml +++ b/startup/action.yml @@ -38,10 +38,22 @@ runs: # github-token: ${{ inputs.github-token }} # ci-project: ${{ inputs.ci-project }} + - name: Install tools + uses: jenseng/dynamic-uses@v1 + env: + action-version: ${{ fromJSON(format('["{0}","{1}"]', github.ref_name, github.head_ref))[github.event_name == 'pull_request'] }} + with: + # now we can dynamically determine sub-action versions 🥳 + uses: LocalStack/setup-localstack/tools@${{ env.action-version }} + # the `with` needs to be converted to a valid json string + # keeping in there install-awslocal for backward compatibility + with: |- + { + "install-awslocal": "${{ inputs.install-awslocal }}", + } + - name: Start LocalStack run: | - pip install pyopenssl -U - if [ "$USE_PRO" = true ]; then if [ "x$LOCALSTACK_AUTH_TOKEN" = "x" || "x$LOCALSTACK_API_KEY" = "x" ]; then echo "WARNING: LocalStack API key not detected, please verify your configuration..." @@ -52,11 +64,6 @@ runs: docker pull localstack/localstack:"$IMAGE_TAG" & fi - pip install localstack - if [ "$INSTALL_AWSLOCAL" = true ]; then - pip install awscli-local[ver1] - fi - export CI_PROJECT=${{ inputs.ci-project }} eval "${CONFIGURATION} localstack start -d" diff --git a/tools/action.yml b/tools/action.yml new file mode 100644 index 0000000..f0ef8ee --- /dev/null +++ b/tools/action.yml @@ -0,0 +1,24 @@ +name: 'Install Localstack tools' + +inputs: + install-awslocal: + description: 'Whether to install the `awslocal` CLI into the environment' + required: true + default: 'true' + +runs: + using: "composite" + steps: + - name: Start LocalStack + run: | + pip install pyopenssl -U + + pip install localstack + if [ "$INSTALL_AWSLOCAL" = true ]; then + pip install awscli-local[ver1] + fi + + shell: bash + env: + INSTALL_AWSLOCAL: "${{ inputs.install-awslocal }}" + From 0fc578ee1f2c1ed21c57056aa4635b0927eda2aa Mon Sep 17 00:00:00 2001 From: lakkeger Date: Wed, 15 May 2024 16:08:28 +0200 Subject: [PATCH 09/29] feat(ci): add local state test --- .github/workflows/ci.yml | 33 ++++++++++++++++++++++++++++++++- action.yml | 4 ++-- local/action.yml | 4 ++-- tools/action.yml | 6 ++---- 4 files changed, 38 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e0aa4a8..d35bd8c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -55,6 +55,37 @@ jobs: with: state-name: cloud-pods-test state-action: save - no-startup: 'true' + skip-startup: 'true' env: LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }} + + local-state-test: + name: 'Test Local State Action' + runs-on: ubuntu-latest + steps: + - name: ⚡️ Checkout the repository + uses: actions/checkout@v3 + + - name: Start LocalStack + uses: ./ + with: + image-tag: 'latest' + install-awslocal: 'true' + use-pro: 'true' + env: + LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }} + + - name: Run AWS commands + run: | + awslocal s3 mb s3://test + awslocal sqs create-queue --queue-name test-queue + + - name: Save the State into Artifact + uses: ./ + with: + state-name: state-test + state-action: save + state-backend: local + skip-startup: 'true' + env: + LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }} \ No newline at end of file diff --git a/action.yml b/action.yml index 26ab48d..8968110 100644 --- a/action.yml +++ b/action.yml @@ -52,7 +52,7 @@ inputs: Defaults to `` (empty) -> don't manage state required: false default: '' - state-local: + state-backend: description: | Either store the state of LocalStack locally or as a cloud pod. Valid values are `cloud-pods` or `local`. @@ -105,7 +105,7 @@ runs: env: action-version: ${{ fromJSON(format('["{0}","{1}"]', github.ref_name, github.head_ref))[github.event_name == 'pull_request'] }} with: - uses: LocalStack/setup-localstack/${{ inputs.state-local }}@${{ env.action-version }} + uses: LocalStack/setup-localstack/${{ inputs.state-backend }}@${{ env.action-version }} with: |- { "name": "${{ inputs.state-name }}", diff --git a/local/action.yml b/local/action.yml index 3afd5b9..5984f34 100644 --- a/local/action.yml +++ b/local/action.yml @@ -25,10 +25,10 @@ runs: - run: | if [ "$ACTION" = "save" ]; then echo "Saving State $NAME" - localstack state export $NAME + localstack state export ${NAME}.zip elif [ "$ACTION" = "load" ]; then echo "Loading State $NAME" - localstack state import $NAME + localstack state import ${NAME}.zip else echo "Invalid action: $ACTION" exit 1 diff --git a/tools/action.yml b/tools/action.yml index f0ef8ee..65b59fd 100644 --- a/tools/action.yml +++ b/tools/action.yml @@ -11,11 +11,9 @@ runs: steps: - name: Start LocalStack run: | - pip install pyopenssl -U - - pip install localstack + which localstack > /dev/null || pip install localstack if [ "$INSTALL_AWSLOCAL" = true ]; then - pip install awscli-local[ver1] + which awslocal > /dev/null || pip install awscli-local[ver1] fi shell: bash From 98771bfba5e0f6970158c58cfe93c15817362b96 Mon Sep 17 00:00:00 2001 From: lakkeger Date: Thu, 16 May 2024 15:07:27 +0200 Subject: [PATCH 10/29] docs: Update README.md --- README.md | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 78 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 1d5240f..0ca84a8 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,9 @@ A GitHub Action to setup [LocalStack](https://github.com/localstack/localstack) - Pulling a specific version of the LocalStack Docker Image into the GitHub Action runner. - Configuring the [LocalStack CLI](https://docs.localstack.cloud/get-started/#localstack-cli) to launch the Docker container with an optional API token for pro usage. - Installing [LocalStack AWS CLI](https://github.com/localstack/awscli-local), a thin wrapper around the `aws` command line interface for use with LocalStack to run integration tests over AWS services. +- Export/import [LocalStack state](https://docs.localstack.cloud/user-guide/state-management/export-import-state/) as an artifact +- Save/load [LocalStack Cloud Pods](https://docs.localstack.cloud/user-guide/state-management/cloud-pods/) +- Start/stop a [LocalStack Ephemeral Instance](https://docs.localstack.cloud/user-guide/cloud-sandbox/application-previews/) _(EXPERIMENTAL)_ ## Usage @@ -15,13 +18,65 @@ To get started, you can use this minimal example: ```yml - name: Start LocalStack - uses: LocalStack/setup-localstack@v0.1.2 + uses: LocalStack/setup-localstack@v0.2.0 with: image-tag: 'latest' install-awslocal: 'true' env: LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }} ``` +> **NOTE**: The `LOCALSTACK_API_KEY` environment variable is required to be set if `use-pro` is set to `true`. +If the key is not found LocalStack by default falls back to the CE edition and displays a warning. + +To install only CLIs and startup later: +```yml +- name: Install LocalStack CLIs + uses: LocalStack/setup-localstack@v0.2.0 + with: + skip-startup: 'true' + install-awslocal: 'true' + +... + +- name: Start LocalStack + uses: LocalStack/setup-localstack@v0.2.0 + with: + image-tag: 'latest' + env: + LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }} +``` + +To save a state later on in the pipeline: +```yml +- name: Save LocalStack State + uses: LocalStack/setup-localstack@v0.2.0 + with: + install-awslocal: 'true' + skip-startup: 'true' + state-backend: cloud-pods + state-action: save + state-name: my-cloud-pod + env: + LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }} +``` +> **NOTE**: The `LOCALSTACK_API_KEY` environment variable is required to be set to save/load LocalStack's state either as a Cloud Pod or an artifact. + +To load an already saved state: +```yml +- name: Start LocalStack and Load State + uses: LocalStack/setup-localstack@v0.2.0 + with: + install-awslocal: 'true' + state-backend: cloud-pods + state-action: load + state-name: my-cloud-pod + env: + LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }} +``` +> **NOTE**: To load a **local state** from a different GitHub Actions workflow, one must set the `WORKFLOW_ID` environment variable. + +> **NOTE**: The `LOCALSTACK_API_KEY` environment variable is required to be set to **save/load** LocalStack's state either as a Cloud Pod or an artifact. + ### Inputs @@ -31,11 +86,13 @@ To get started, you can use this minimal example: | `install-awslocal` | Whether to install the `awslocal` CLI into the build environment | `true` | | `configuration` | Configuration variables to use while starting LocalStack container | `None` | | `use-pro` | Whether to use the Pro version of LocalStack (requires API key to be configured) | `false` | - -> **NOTE**: The `LOCALSTACK_API_KEY` environment variable is required to be set if `use-pro` is set to `true`. +| `skip-startup` | Explicitly prevent LocalStack start up, only installs CLI(s). Recommended to manage state later on in the pipeline or start up an ephemeral instance. | `false` | +| `skip-wait` | Skip wait for LocalStack to start up | `false` | +| `state-action` | Manage LocalStack state. Valid values are `load`, `save`, `` (empty, do not manage state). | `` | +| `state-backend` | Either store the state of LocalStack locally or as a cloud pod. Valid values are `cloud-pods` or `local`. Use this option in unison with `state-action` to control behaviour. | `cloud-pods` | +| `state-name` | Name of the state artifact (without extension) | `false` | ### Example workflow - ```yml name: LocalStack Test on: [ push, pull_request ] @@ -48,12 +105,15 @@ jobs: - uses: actions/checkout@v3 - name: Start LocalStack - uses: LocalStack/setup-localstack@v0.1.2 + uses: LocalStack/setup-localstack@v0.2.0 with: image-tag: 'latest' install-awslocal: 'true' configuration: DEBUG=1 use-pro: 'true' + state-backend: cloud-pods + state-action: load + state-name: my-cloud-pod env: LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }} @@ -61,7 +121,19 @@ jobs: run: | awslocal s3 mb s3://test awslocal s3 ls - echo "Test Execution complete!" + echo "Test Execution complete!" + + - name: Save LocalStack State + uses: LocalStack/setup-localstack@v0.2.0 + with: + skip-startup: 'true' + state-backend: local + state-action: save + state-name: my-ls-state-artifact + env: + LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }} + WORKFLOW_ID: ${{ env.MY_GOLDEN_LS_STATE }} + # Alternatively just configure a repo variable with the `WORKFLOW_ID` name ``` ## License From bb869238627d347203ca63c64599037800b486f1 Mon Sep 17 00:00:00 2001 From: lakkeger Date: Thu, 16 May 2024 15:11:54 +0200 Subject: [PATCH 11/29] fix(cloud-pods): ensure pod load not prompts for user input --- cloud-pods/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloud-pods/action.yml b/cloud-pods/action.yml index 80dccd6..8058c1c 100644 --- a/cloud-pods/action.yml +++ b/cloud-pods/action.yml @@ -20,7 +20,7 @@ runs: localstack pod save $NAME elif [ "$ACTION" = "load" ]; then echo "Loading Cloud Pod $NAME" - localstack pod load $NAME + localstack pod load --yes $NAME else echo "Invalid action: $ACTION" exit 1 From 0165a014bb69d0e0cc928051c6c3820fdecddf30 Mon Sep 17 00:00:00 2001 From: lakkeger Date: Thu, 16 May 2024 15:12:43 +0200 Subject: [PATCH 12/29] feat(preview): allow env variables to control pod load --- preview/action.yml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/preview/action.yml b/preview/action.yml index ad9a604..fcf137a 100644 --- a/preview/action.yml +++ b/preview/action.yml @@ -6,13 +6,13 @@ inputs: required: true localstack-api-key: description: 'LocalStack API key used to create the preview environment' - required: true + required: false preview-cmd: description: 'Command(s) used to create a preview of the PR (can use $AWS_ENDPOINT_URL)' required: false default: '' auto-load-pod: - description: 'The pod to load on startup of localstack, the env var AUTO_LOAD_POD' + description: 'The pod to load on startup of LocalStack, the env var AUTO_LOAD_POD' required: false default: '' @@ -38,9 +38,9 @@ runs: # TODO: make preview name configurable! previewName=preview-$prId - response=$(curl -X POST -d '{"auto_load_pod": "${{ inputs.auto-load-pod }}"}' \ - -H 'ls-api-key: ${{ inputs.localstack-api-key }}' \ - -H 'authorization: token ${{ inputs.localstack-api-key }}' \ + response=$(curl -X POST -d '{"auto_load_pod": "${AUTO_LOAD_POD:-${{ inputs.auto-load-pod }}}"}' \ + -H 'ls-api-key: ${LOCALSTACK_API_KEY:-${{ inputs.localstack-api-key }}}' \ + -H 'authorization: token ${LOCALSTACK_API_KEY:-${{ inputs.localstack-api-key }}}' \ -H 'content-type: application/json' \ https://api.localstack.cloud/v1/previews/$previewName) endpointUrl=$(echo "$response" | jq -r .endpoint_url) @@ -61,6 +61,7 @@ runs: path: ./ls-preview-url.txt - name: Run preview deployment + if: ${{ inputs.preview-cmd != '' }} shell: bash run: ${{ inputs.preview-cmd }} From 63a7484c4084554c7e5a9c730633342cad819868 Mon Sep 17 00:00:00 2001 From: lakkeger Date: Thu, 16 May 2024 15:13:18 +0200 Subject: [PATCH 13/29] chore(ci): exclude pipeline trigger for docs --- .github/workflows/ci.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d35bd8c..0f4ea53 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,7 +1,13 @@ name: LocalStack Test on: push: + paths-ignore: + - ./*.md + - LICENSE pull_request: + paths-ignore: + - ./*.md + - LICENSE workflow_dispatch: schedule: - cron: '48 23 * * 0' From e188543ce9d278d2b3f75284e90e2bf86ea7020c Mon Sep 17 00:00:00 2001 From: lakkeger Date: Thu, 16 May 2024 15:58:06 +0200 Subject: [PATCH 14/29] feat: add app preview management --- action.yml | 65 ++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 56 insertions(+), 9 deletions(-) diff --git a/action.yml b/action.yml index 8968110..53c4550 100644 --- a/action.yml +++ b/action.yml @@ -34,33 +34,39 @@ inputs: preview-cmd: description: 'Command(s) used to create a preview of the PR (can use $AWS_ENDPOINT_URL)' required: false - default: '' + include-preview: + description: 'Whether to include the created preview URL in the PR comment' + required: false skip-startup: description: | - Explicitly prevent LocalStack start up. - Useful to manage state later on in the pipeline or start up ephemeral instance + Explicitly prevent LocalStack start up, only installs CLI(s). + Recommended to manage state later on in the pipeline or start up an ephemeral instance required: true default: 'false' skip-wait: - description: Skip wait for LocalStack + description: 'Skip wait for LocalStack' + required: false + default: 'false' + skip-preview-stop: + description: 'Skip stopping LocalStack Ephemeral Instance' required: false default: 'false' state-action: description: | Manage LocalStack state - Valid values are `load``, `save`, `` - Defaults to `` (empty) -> don't manage state + Valid values are `load`, `save`, `start`, `stop`, `` (empty, don't manage state) + Values `start`/`stop` only usable with app previews. required: false default: '' state-backend: description: | Either store the state of LocalStack locally or as a cloud pod. - Valid values are `cloud-pods` or `local`. + Valid values are `cloud-pods`, `preview` or `local`. Use this option in unison with `state-action` to control behaviour. required: false default: 'cloud-pods' state-name: - description: 'Name of the state artifact' + description: 'Name of the state artifact (without extension)' required: false runs: @@ -100,7 +106,7 @@ runs: # Use different artifact from current workflow's by passing the workflow's id as WORKFLOW_ID env variable - name: Manage state - if: ${{ (inputs.state-action == 'save' || inputs.state-action == 'load') }} + if: ${{ inputs.state-action == 'save' || inputs.state-action == 'load' }} uses: jenseng/dynamic-uses@v1 env: action-version: ${{ fromJSON(format('["{0}","{1}"]', github.ref_name, github.head_ref))[github.event_name == 'pull_request'] }} @@ -111,3 +117,44 @@ runs: "name": "${{ inputs.state-name }}", "action": "${{ inputs.state-action }}" } + + - name: Create Ephemeral Instance + if: ${{ inputs.state-action == 'start' && inputs.state-backend == 'preview' }} + uses: jenseng/dynamic-uses@v1 + env: + action-version: ${{ fromJSON(format('["{0}","{1}"]', github.ref_name, github.head_ref))[github.event_name == 'pull_request'] }} + with: + uses: LocalStack/setup-localstack/preview@${{ env.action-version }} + with: |- + { + "github-token": "${{ inputs.github-token }}", + "preview-cmd": "${{ inputs.preview-cmd }}", + "auto-load-pod": "${{ inputs.state-name }}" + } + + - name: Display Ephemeral Instance URL + if: ${{ inputs.state-action == 'start' && inputs.state-backend == 'preview' }} + uses: jenseng/dynamic-uses@v1 + env: + action-version: ${{ fromJSON(format('["{0}","{1}"]', github.ref_name, github.head_ref))[github.event_name == 'pull_request'] }} + default-include-preview: ${{ fromJSON('["false","true"]')[github.event_name == 'pull_request'] }} + with: + uses: LocalStack/setup-localstack/finish@${{ env.action-version }} + with: |- + { + "github-token": "${{ inputs.github-token }}", + "ci-project": "${{ inputs.ci-project }}", + "include-preview": "${{ fromJSON('["{0}","{1}"]', env.include-preview, inputs.include-preview))[inputs.include-preview != ''] }}" + } + + - name: Stop Ephemeral Instance + if: ${{ !inputs.skip-preview-stop && (inputs.state-action == 'stop' && inputs.state-backend == 'preview' }} + uses: jenseng/dynamic-uses@v1 + env: + action-version: ${{ fromJSON(format('["{0}","{1}"]', github.ref_name, github.head_ref))[github.event_name == 'pull_request'] }} + with: + uses: LocalStack/setup-localstack/ephemeral/shutdown@${{ env.action-version }} + with: |- + { + "name": "${{ inputs.github-token }}", + } \ No newline at end of file From c5cab2f3db62a5ec17ce7418dce1c8ff3951022b Mon Sep 17 00:00:00 2001 From: lakkeger Date: Thu, 16 May 2024 16:07:36 +0200 Subject: [PATCH 15/29] docs: add app preview options --- README.md | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 0ca84a8..c6b1d11 100644 --- a/README.md +++ b/README.md @@ -82,15 +82,20 @@ To load an already saved state: | Input | Description | Default | | ------------------ | -------------------------------------------------------------------------------- | -------- | +| `ci-project` | Name of the CI project to track in LocalStack Cloud | | +| `configuration` | Configuration variables to use while starting LocalStack container | `None` | +| `github-token` | Github token used to create PR comments | | | `image-tag` | Tag of the LocalStack Docker image to use | `latest` | +| `include-preview` | Whether to include the created preview URL in the PR comment | | | `install-awslocal` | Whether to install the `awslocal` CLI into the build environment | `true` | -| `configuration` | Configuration variables to use while starting LocalStack container | `None` | -| `use-pro` | Whether to use the Pro version of LocalStack (requires API key to be configured) | `false` | +| `preview-cmd` | Command(s) used to create a preview of the PR (can use $AWS_ENDPOINT_URL) | | +| `skip-preview-stop` | Skip stopping LocalStack Ephemeral Instance | `false` | | `skip-startup` | Explicitly prevent LocalStack start up, only installs CLI(s). Recommended to manage state later on in the pipeline or start up an ephemeral instance. | `false` | | `skip-wait` | Skip wait for LocalStack to start up | `false` | -| `state-action` | Manage LocalStack state. Valid values are `load`, `save`, `` (empty, do not manage state). | `` | -| `state-backend` | Either store the state of LocalStack locally or as a cloud pod. Valid values are `cloud-pods` or `local`. Use this option in unison with `state-action` to control behaviour. | `cloud-pods` | +| `state-action` | Valid values are `load`, `save`, `start`, `stop`, `` (empty, don't manage state). Values `start`/`stop` only usable with app previews. | `` | +| `state-backend` | Either store the state of LocalStack locally or as a cloud pod. Valid values are `cloud-pods`, `preview` or `local`. Use this option in unison with `state-action` to control behaviour. | `cloud-pods` | | `state-name` | Name of the state artifact (without extension) | `false` | +| `use-pro` | Whether to use the Pro version of LocalStack (requires API key to be configured) | `false` | ### Example workflow ```yml @@ -133,7 +138,6 @@ jobs: env: LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }} WORKFLOW_ID: ${{ env.MY_GOLDEN_LS_STATE }} - # Alternatively just configure a repo variable with the `WORKFLOW_ID` name ``` ## License From da81a10a475a8ae790ed5daa617ae9432c9aba20 Mon Sep 17 00:00:00 2001 From: lakkeger Date: Thu, 16 May 2024 16:24:12 +0200 Subject: [PATCH 16/29] docs: add default value for include-preview --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c6b1d11..8f665aa 100644 --- a/README.md +++ b/README.md @@ -86,7 +86,7 @@ To load an already saved state: | `configuration` | Configuration variables to use while starting LocalStack container | `None` | | `github-token` | Github token used to create PR comments | | | `image-tag` | Tag of the LocalStack Docker image to use | `latest` | -| `include-preview` | Whether to include the created preview URL in the PR comment | | +| `include-preview` | Whether to include the created preview URL in the PR comment | `false` | | `install-awslocal` | Whether to install the `awslocal` CLI into the build environment | `true` | | `preview-cmd` | Command(s) used to create a preview of the PR (can use $AWS_ENDPOINT_URL) | | | `skip-preview-stop` | Skip stopping LocalStack Ephemeral Instance | `false` | From 4e0068aa7f7a362e3203829c8dc505991f313fce Mon Sep 17 00:00:00 2001 From: lakkeger Date: Thu, 16 May 2024 16:31:38 +0200 Subject: [PATCH 17/29] feat: tweak logic for preview ci --- .github/workflows/ephemeral.yml | 16 ++++++++++++---- action.yml | 10 +++++----- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ephemeral.yml b/.github/workflows/ephemeral.yml index 5feeaa2..e68902e 100644 --- a/.github/workflows/ephemeral.yml +++ b/.github/workflows/ephemeral.yml @@ -10,13 +10,21 @@ jobs: - uses: actions/checkout@v3 - name: Deploy Preview - uses: ./preview + uses: ./ with: - localstack-api-key: ${{ secrets.LOCALSTACK_API_KEY }} github-token: ${{ secrets.GITHUB_TOKEN }} + state-backend: preview + state-action: start + skip-preview-stop: 'true' + env: + LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }} + # We want explicit shutdown - name: Shutdown ephemeral instance - uses: ./ephemeral/shutdown + uses: ./ with: - localstack-api-key: ${{ secrets.LOCALSTACK_API_KEY }} github-token: ${{ secrets.GITHUB_TOKEN }} + state-backend: preview + state-action: stop + env: + LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }} diff --git a/action.yml b/action.yml index 53c4550..6c44a99 100644 --- a/action.yml +++ b/action.yml @@ -74,7 +74,7 @@ runs: steps: - name: Install tools uses: jenseng/dynamic-uses@v1 - if: ${{ inputs.skip-startup == 'true' }} + if: ${{ inputs.skip-startup == 'true' || inputs.state-backend == 'preview' }} env: action-version: ${{ fromJSON(format('["{0}","{1}"]', github.ref_name, github.head_ref))[github.event_name == 'pull_request'] }} with: @@ -86,7 +86,7 @@ runs: - name: Start Localstack uses: jenseng/dynamic-uses@v1 - if: ${{ inputs.skip-startup != 'true' }} + if: ${{ inputs.skip-startup != 'true' && inputs.state-backend != 'preview' }} env: action-version: ${{ fromJSON(format('["{0}","{1}"]', github.ref_name, github.head_ref))[github.event_name == 'pull_request'] }} with: @@ -133,7 +133,7 @@ runs: } - name: Display Ephemeral Instance URL - if: ${{ inputs.state-action == 'start' && inputs.state-backend == 'preview' }} + if: ${{ inputs.state-action == 'start' && inputs.state-backend == 'preview' && (inputs.include-preview == 'true' || inputs.ci-project != '') }} uses: jenseng/dynamic-uses@v1 env: action-version: ${{ fromJSON(format('["{0}","{1}"]', github.ref_name, github.head_ref))[github.event_name == 'pull_request'] }} @@ -144,11 +144,11 @@ runs: { "github-token": "${{ inputs.github-token }}", "ci-project": "${{ inputs.ci-project }}", - "include-preview": "${{ fromJSON('["{0}","{1}"]', env.include-preview, inputs.include-preview))[inputs.include-preview != ''] }}" + "include-preview": "${{ fromJSON(format('["{0}","{1}"]', env.include-preview, inputs.include-preview))[inputs.include-preview != ''] }}" } - name: Stop Ephemeral Instance - if: ${{ !inputs.skip-preview-stop && (inputs.state-action == 'stop' && inputs.state-backend == 'preview' }} + if: ${{ !inputs.skip-preview-stop && inputs.state-action == 'stop' && inputs.state-backend == 'preview' }} uses: jenseng/dynamic-uses@v1 env: action-version: ${{ fromJSON(format('["{0}","{1}"]', github.ref_name, github.head_ref))[github.event_name == 'pull_request'] }} From f046bca4d972771d777aace2e2e014b8aa29e7f6 Mon Sep 17 00:00:00 2001 From: lakkeger Date: Thu, 16 May 2024 18:57:36 +0200 Subject: [PATCH 18/29] fix: fix sub-action versions --- .github/workflows/ci.yml | 76 +++++++++++++++++++++++++++------------- action.yml | 28 ++++++--------- startup/action.yml | 9 ++--- 3 files changed, 65 insertions(+), 48 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0f4ea53..43ecd8a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,15 +19,21 @@ jobs: steps: - uses: actions/checkout@v3 + # We must hack the action call as remote to be able to use the relative paths - name: Start LocalStack - uses: ./ + uses: jenseng/dynamic-uses@v1 with: - image-tag: 'latest' - install-awslocal: 'true' - configuration: DEBUG=1 - use-pro: 'true' + uses: LocalStack/setup-localstack@${{ env.action-version }} + with: |- + { + "image-tag": "latest", + "install-awslocal": "true", + "configuration": "DEBUG=1", + "use-pro": "true", + } env: LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }} + action-version: ${{ fromJSON(format('["{0}","{1}"]', github.ref_name, github.head_ref))[github.event_name == 'pull_request'] }} - name: Run Tests against LocalStack run: | @@ -43,13 +49,19 @@ jobs: uses: actions/checkout@v3 - name: Start LocalStack - uses: ./ + uses: jenseng/dynamic-uses@v1 with: - image-tag: 'latest' - install-awslocal: 'true' - use-pro: 'true' + uses: LocalStack/setup-localstack@${{ env.action-version }} + with: |- + { + "image-tag": "latest", + "install-awslocal": "true", + "configuration": "DEBUG=1", + "use-pro": "true", + } env: LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }} + action-version: ${{ fromJSON(format('["{0}","{1}"]', github.ref_name, github.head_ref))[github.event_name == 'pull_request'] }} - name: Run AWS commands run: | @@ -57,13 +69,18 @@ jobs: awslocal sqs create-queue --queue-name test-queue - name: Save the Cloud Pod - uses: ./ + uses: jenseng/dynamic-uses@v1 with: - state-name: cloud-pods-test - state-action: save - skip-startup: 'true' + uses: LocalStack/setup-localstack@${{ env.action-version }} + with: |- + { + "state-name": "cloud-pods-test", + "state-action": "save", + "skip-startup": "true", + } env: LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }} + action-version: ${{ fromJSON(format('["{0}","{1}"]', github.ref_name, github.head_ref))[github.event_name == 'pull_request'] }} local-state-test: name: 'Test Local State Action' @@ -73,25 +90,36 @@ jobs: uses: actions/checkout@v3 - name: Start LocalStack - uses: ./ + uses: jenseng/dynamic-uses@v1 with: - image-tag: 'latest' - install-awslocal: 'true' - use-pro: 'true' + uses: LocalStack/setup-localstack@${{ env.action-version }} + with: |- + { + "image-tag": "latest", + "install-awslocal": "true", + "configuration": "DEBUG=1", + "use-pro": "true", + } env: LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }} + action-version: ${{ fromJSON(format('["{0}","{1}"]', github.ref_name, github.head_ref))[github.event_name == 'pull_request'] }} - name: Run AWS commands run: | awslocal s3 mb s3://test awslocal sqs create-queue --queue-name test-queue - - name: Save the State into Artifact - uses: ./ + - name: Save the Cloud Pod + uses: jenseng/dynamic-uses@v1 with: - state-name: state-test - state-action: save - state-backend: local - skip-startup: 'true' + uses: LocalStack/setup-localstack@${{ env.action-version }} + with: |- + { + "state-name": "cloud-pods-test", + "state-action": "save", + "state-backend": "local", + "skip-startup": "true", + } env: - LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }} \ No newline at end of file + LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }} + action-version: ${{ fromJSON(format('["{0}","{1}"]', github.ref_name, github.head_ref))[github.event_name == 'pull_request'] }} diff --git a/action.yml b/action.yml index 6c44a99..b0b2c1d 100644 --- a/action.yml +++ b/action.yml @@ -72,13 +72,14 @@ inputs: runs: using: "composite" steps: + - run: echo "action-root=$(ls -d ./../../_actions/LocalStack/setup-localstack/* | grep -v completed)" >> $GITHUB_ENV + shell: bash + - name: Install tools uses: jenseng/dynamic-uses@v1 if: ${{ inputs.skip-startup == 'true' || inputs.state-backend == 'preview' }} - env: - action-version: ${{ fromJSON(format('["{0}","{1}"]', github.ref_name, github.head_ref))[github.event_name == 'pull_request'] }} with: - uses: LocalStack/setup-localstack/tools@${{ env.action-version }} + uses: ${{ env.action-root }}/tools with: |- { "install-awslocal": "${{ inputs.install-awslocal }}", @@ -87,11 +88,9 @@ runs: - name: Start Localstack uses: jenseng/dynamic-uses@v1 if: ${{ inputs.skip-startup != 'true' && inputs.state-backend != 'preview' }} - env: - action-version: ${{ fromJSON(format('["{0}","{1}"]', github.ref_name, github.head_ref))[github.event_name == 'pull_request'] }} with: - # now we can dynamically determine sub-action versions 🥳 - uses: LocalStack/setup-localstack/startup@${{ env.action-version }} + # now we can dynamically determine sub-action path 🥳 + uses: ${{ env.action-root }}/startup # the `with` needs to be converted to a valid json string # keeping in there install-awslocal for backward compatibility with: |- @@ -108,10 +107,8 @@ runs: - name: Manage state if: ${{ inputs.state-action == 'save' || inputs.state-action == 'load' }} uses: jenseng/dynamic-uses@v1 - env: - action-version: ${{ fromJSON(format('["{0}","{1}"]', github.ref_name, github.head_ref))[github.event_name == 'pull_request'] }} with: - uses: LocalStack/setup-localstack/${{ inputs.state-backend }}@${{ env.action-version }} + uses: ${{ env.action-root }}/${{ inputs.state-backend }} with: |- { "name": "${{ inputs.state-name }}", @@ -121,10 +118,8 @@ runs: - name: Create Ephemeral Instance if: ${{ inputs.state-action == 'start' && inputs.state-backend == 'preview' }} uses: jenseng/dynamic-uses@v1 - env: - action-version: ${{ fromJSON(format('["{0}","{1}"]', github.ref_name, github.head_ref))[github.event_name == 'pull_request'] }} with: - uses: LocalStack/setup-localstack/preview@${{ env.action-version }} + uses: ${{ env.action-root }}/preview with: |- { "github-token": "${{ inputs.github-token }}", @@ -136,10 +131,9 @@ runs: if: ${{ inputs.state-action == 'start' && inputs.state-backend == 'preview' && (inputs.include-preview == 'true' || inputs.ci-project != '') }} uses: jenseng/dynamic-uses@v1 env: - action-version: ${{ fromJSON(format('["{0}","{1}"]', github.ref_name, github.head_ref))[github.event_name == 'pull_request'] }} default-include-preview: ${{ fromJSON('["false","true"]')[github.event_name == 'pull_request'] }} with: - uses: LocalStack/setup-localstack/finish@${{ env.action-version }} + uses: ${{ env.action-root }}/finish with: |- { "github-token": "${{ inputs.github-token }}", @@ -150,10 +144,8 @@ runs: - name: Stop Ephemeral Instance if: ${{ !inputs.skip-preview-stop && inputs.state-action == 'stop' && inputs.state-backend == 'preview' }} uses: jenseng/dynamic-uses@v1 - env: - action-version: ${{ fromJSON(format('["{0}","{1}"]', github.ref_name, github.head_ref))[github.event_name == 'pull_request'] }} with: - uses: LocalStack/setup-localstack/ephemeral/shutdown@${{ env.action-version }} + uses: ${{ env.action-root }}/ephemeral/shutdown with: |- { "name": "${{ inputs.github-token }}", diff --git a/startup/action.yml b/startup/action.yml index af3552c..530fe3b 100644 --- a/startup/action.yml +++ b/startup/action.yml @@ -37,16 +37,13 @@ runs: # with: # github-token: ${{ inputs.github-token }} # ci-project: ${{ inputs.ci-project }} + - run: echo "action-root=$(ls -d ./../../_actions/LocalStack/setup-localstack/* | grep -v completed)" >> $GITHUB_ENV + shell: bash - name: Install tools uses: jenseng/dynamic-uses@v1 - env: - action-version: ${{ fromJSON(format('["{0}","{1}"]', github.ref_name, github.head_ref))[github.event_name == 'pull_request'] }} with: - # now we can dynamically determine sub-action versions 🥳 - uses: LocalStack/setup-localstack/tools@${{ env.action-version }} - # the `with` needs to be converted to a valid json string - # keeping in there install-awslocal for backward compatibility + uses: ${{ env.action-root }}/tools with: |- { "install-awslocal": "${{ inputs.install-awslocal }}", From 8ef56997217ea0117ccc5b5b2c04736e0372b442 Mon Sep 17 00:00:00 2001 From: lakkeger Date: Thu, 16 May 2024 21:14:53 +0200 Subject: [PATCH 19/29] fix(startup): fix test condition syntax --- startup/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/startup/action.yml b/startup/action.yml index 530fe3b..9135d2a 100644 --- a/startup/action.yml +++ b/startup/action.yml @@ -52,7 +52,7 @@ runs: - name: Start LocalStack run: | if [ "$USE_PRO" = true ]; then - if [ "x$LOCALSTACK_AUTH_TOKEN" = "x" || "x$LOCALSTACK_API_KEY" = "x" ]; then + if [ "x$LOCALSTACK_AUTH_TOKEN" = "x" -o "x$LOCALSTACK_API_KEY" = "x" ]; then echo "WARNING: LocalStack API key not detected, please verify your configuration..." fi docker pull localstack/localstack-pro:"$IMAGE_TAG" & From a1b36daf4aef5b0e24bc42508ce4c94b0dd002a8 Mon Sep 17 00:00:00 2001 From: lakkeger Date: Fri, 17 May 2024 09:44:06 +0200 Subject: [PATCH 20/29] fix(preview): fix variable expansions --- ephemeral/shutdown/action.yml | 6 +++--- preview/action.yml | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/ephemeral/shutdown/action.yml b/ephemeral/shutdown/action.yml index 4e9463c..664e7f7 100644 --- a/ephemeral/shutdown/action.yml +++ b/ephemeral/shutdown/action.yml @@ -30,9 +30,9 @@ runs: previewName=preview-$prId response=$(curl -X DELETE \ - -H 'ls-api-key: ${{ inputs.localstack-api-key }}' \ - -H 'authorization: token ${{ inputs.localstack-api-key }}' \ - -H 'content-type: application/json' \ + -H "ls-api-key: ${LOCALSTACK_API_KEY:-${{ inputs.localstack-api-key }}}" \ + -H "authorization: token ${LOCALSTACK_API_KEY:-${{ inputs.localstack-api-key }}}" \ + -H "content-type: application/json" \ https://api.localstack.cloud/v1/previews/$previewName) if [[ "$response" != "{}" ]]; then # In case the deletion fails, e.g. if the instance cannot be found, we raise a proper error on the platform diff --git a/preview/action.yml b/preview/action.yml index fcf137a..f9fc9d8 100644 --- a/preview/action.yml +++ b/preview/action.yml @@ -38,10 +38,10 @@ runs: # TODO: make preview name configurable! previewName=preview-$prId - response=$(curl -X POST -d '{"auto_load_pod": "${AUTO_LOAD_POD:-${{ inputs.auto-load-pod }}}"}' \ - -H 'ls-api-key: ${LOCALSTACK_API_KEY:-${{ inputs.localstack-api-key }}}' \ - -H 'authorization: token ${LOCALSTACK_API_KEY:-${{ inputs.localstack-api-key }}}' \ - -H 'content-type: application/json' \ + response=$(curl -X POST -d "{\"auto_load_pod\": \"${AUTO_LOAD_POD:-${{ inputs.auto-load-pod }}}\"}" \ + -H "ls-api-key: ${LOCALSTACK_API_KEY:-${{ inputs.localstack-api-key }}}" \ + -H "authorization: token ${LOCALSTACK_API_KEY:-${{ inputs.localstack-api-key }}}" \ + -H "content-type: application/json" \ https://api.localstack.cloud/v1/previews/$previewName) endpointUrl=$(echo "$response" | jq -r .endpoint_url) if [ "$endpointUrl" = "null" ] || [ "$endpointUrl" = "" ]; then From 1a99576e2f8def7f99fa7252d13614c8cad5ee94 Mon Sep 17 00:00:00 2001 From: lakkeger Date: Fri, 17 May 2024 09:50:36 +0200 Subject: [PATCH 21/29] fix(ci): update ephemeral ci with version fix --- .github/workflows/ephemeral.yml | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ephemeral.yml b/.github/workflows/ephemeral.yml index e68902e..923f6c7 100644 --- a/.github/workflows/ephemeral.yml +++ b/.github/workflows/ephemeral.yml @@ -10,21 +10,29 @@ jobs: - uses: actions/checkout@v3 - name: Deploy Preview - uses: ./ + uses: jenseng/dynamic-uses@v1 with: - github-token: ${{ secrets.GITHUB_TOKEN }} - state-backend: preview - state-action: start - skip-preview-stop: 'true' + uses: LocalStack/setup-localstack@${{ env.action-version }} + with: |- + { + "github-token": "${{ secrets.GITHUB_TOKEN }}", + "state-backend": "preview", + "state-action": "start", + "skip-preview-stop": "true" + } env: LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }} # We want explicit shutdown - name: Shutdown ephemeral instance - uses: ./ + uses: jenseng/dynamic-uses@v1 with: - github-token: ${{ secrets.GITHUB_TOKEN }} - state-backend: preview - state-action: stop + uses: LocalStack/setup-localstack@${{ env.action-version }} + with: |- + { + "github-token": "${{ secrets.GITHUB_TOKEN }}", + "state-backend": "preview", + "state-action": "stop" + } env: LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }} From 0f2479b527f6346803f183f03c21da8fd817e816 Mon Sep 17 00:00:00 2001 From: lakkeger Date: Fri, 17 May 2024 09:50:36 +0200 Subject: [PATCH 22/29] fix(ci): update ephemeral ci with version fix --- .github/workflows/ephemeral.yml | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ephemeral.yml b/.github/workflows/ephemeral.yml index e68902e..9b0c98a 100644 --- a/.github/workflows/ephemeral.yml +++ b/.github/workflows/ephemeral.yml @@ -10,21 +10,31 @@ jobs: - uses: actions/checkout@v3 - name: Deploy Preview - uses: ./ + uses: jenseng/dynamic-uses@v1 with: - github-token: ${{ secrets.GITHUB_TOKEN }} - state-backend: preview - state-action: start - skip-preview-stop: 'true' + uses: LocalStack/setup-localstack@${{ env.action-version }} + with: |- + { + "github-token": "${{ secrets.GITHUB_TOKEN }}", + "state-backend": "preview", + "state-action": "start", + "skip-preview-stop": "true" + } env: LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }} + action-version: ${{ fromJSON(format('["{0}","{1}"]', github.ref_name, github.head_ref))[github.event_name == 'pull_request'] }} # We want explicit shutdown - name: Shutdown ephemeral instance - uses: ./ + uses: jenseng/dynamic-uses@v1 with: - github-token: ${{ secrets.GITHUB_TOKEN }} - state-backend: preview - state-action: stop + uses: LocalStack/setup-localstack@${{ env.action-version }} + with: |- + { + "github-token": "${{ secrets.GITHUB_TOKEN }}", + "state-backend": "preview", + "state-action": "stop" + } env: LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }} + action-version: ${{ fromJSON(format('["{0}","{1}"]', github.ref_name, github.head_ref))[github.event_name == 'pull_request'] }} From 28455d4366a00914b2ad0151751e43f0419bd49c Mon Sep 17 00:00:00 2001 From: lakkeger Date: Fri, 17 May 2024 11:00:26 +0200 Subject: [PATCH 23/29] docs: add ephemeral examples --- .github/workflows/ci.yml | 1 + README.md | 34 ++++++++++++++++++++++++++++------ 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 43ecd8a..af3269b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,6 +20,7 @@ jobs: - uses: actions/checkout@v3 # We must hack the action call as remote to be able to use the relative paths + # Could it break with different CWD? 🤔 - name: Start LocalStack uses: jenseng/dynamic-uses@v1 with: diff --git a/README.md b/README.md index 8f665aa..98babf8 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ A GitHub Action to setup [LocalStack](https://github.com/localstack/localstack) ## Usage -To get started, you can use this minimal example: +### Get started minimal example ```yml - name: Start LocalStack @@ -28,7 +28,7 @@ To get started, you can use this minimal example: > **NOTE**: The `LOCALSTACK_API_KEY` environment variable is required to be set if `use-pro` is set to `true`. If the key is not found LocalStack by default falls back to the CE edition and displays a warning. -To install only CLIs and startup later: +### Install only CLIs and startup later ```yml - name: Install LocalStack CLIs uses: LocalStack/setup-localstack@v0.2.0 @@ -46,7 +46,7 @@ To install only CLIs and startup later: LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }} ``` -To save a state later on in the pipeline: +### Save a state later on in the pipeline ```yml - name: Save LocalStack State uses: LocalStack/setup-localstack@v0.2.0 @@ -61,7 +61,7 @@ To save a state later on in the pipeline: ``` > **NOTE**: The `LOCALSTACK_API_KEY` environment variable is required to be set to save/load LocalStack's state either as a Cloud Pod or an artifact. -To load an already saved state: +### Load an already saved state ```yml - name: Start LocalStack and Load State uses: LocalStack/setup-localstack@v0.2.0 @@ -77,8 +77,30 @@ To load an already saved state: > **NOTE**: The `LOCALSTACK_API_KEY` environment variable is required to be set to **save/load** LocalStack's state either as a Cloud Pod or an artifact. +### Manage App Preview +```yml +uses: LocalStack/setup-localstack@$v0.2.0 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + state-backend: preview + state-action: start + skip-preview-stop: 'true' # Adding this option prevents + env: + LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }} + +... + +with: + uses: LocalStack/setup-localstack@${{ env.action-version }} + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + state-backend: preview + state-action: stop + env: + LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }} +``` -### Inputs +## Inputs | Input | Description | Default | | ------------------ | -------------------------------------------------------------------------------- | -------- | @@ -97,7 +119,7 @@ To load an already saved state: | `state-name` | Name of the state artifact (without extension) | `false` | | `use-pro` | Whether to use the Pro version of LocalStack (requires API key to be configured) | `false` | -### Example workflow +## Example workflow ```yml name: LocalStack Test on: [ push, pull_request ] From 2c432c9649769ea5e6f4568b3b8a06eddd36c999 Mon Sep 17 00:00:00 2001 From: lakkeger Date: Wed, 29 May 2024 10:55:09 +0200 Subject: [PATCH 24/29] docs: fix nits for docs, add preview-cmd to preview for better understanding --- README.md | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 98babf8..3a50fc3 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ A GitHub Action to setup [LocalStack](https://github.com/localstack/localstack) ## Usage -### Get started minimal example +### Get started with a minimal example ```yml - name: Start LocalStack @@ -59,7 +59,7 @@ If the key is not found LocalStack by default falls back to the CE edition and d env: LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }} ``` -> **NOTE**: The `LOCALSTACK_API_KEY` environment variable is required to be set to save/load LocalStack's state either as a Cloud Pod or an artifact. +> **NOTE**: The `LOCALSTACK_API_KEY` environment variable is required to be set to save/load LocalStack's state either as a Cloud Pod or as a file artifact. ### Load an already saved state ```yml @@ -75,7 +75,7 @@ If the key is not found LocalStack by default falls back to the CE edition and d ``` > **NOTE**: To load a **local state** from a different GitHub Actions workflow, one must set the `WORKFLOW_ID` environment variable. -> **NOTE**: The `LOCALSTACK_API_KEY` environment variable is required to be set to **save/load** LocalStack's state either as a Cloud Pod or an artifact. +> **NOTE**: The `LOCALSTACK_API_KEY` environment variable is required to be set to **save/load** LocalStack's state either as a Cloud Pod or as a file artifact. ### Manage App Preview ```yml @@ -84,7 +84,10 @@ uses: LocalStack/setup-localstack@$v0.2.0 github-token: ${{ secrets.GITHUB_TOKEN }} state-backend: preview state-action: start - skip-preview-stop: 'true' # Adding this option prevents + # Adding this option prevents Ephemeral Instance to be stopped after the `preview-cmd` run + skip-preview-stop: 'true' + # Optional script/command to run + preview-cmd: deploy.sh env: LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }} @@ -110,10 +113,10 @@ with: | `image-tag` | Tag of the LocalStack Docker image to use | `latest` | | `include-preview` | Whether to include the created preview URL in the PR comment | `false` | | `install-awslocal` | Whether to install the `awslocal` CLI into the build environment | `true` | -| `preview-cmd` | Command(s) used to create a preview of the PR (can use $AWS_ENDPOINT_URL) | | +| `preview-cmd` | Command(s) used to create a preview of the PR (can use `$AWS_ENDPOINT_URL`) | | | `skip-preview-stop` | Skip stopping LocalStack Ephemeral Instance | `false` | | `skip-startup` | Explicitly prevent LocalStack start up, only installs CLI(s). Recommended to manage state later on in the pipeline or start up an ephemeral instance. | `false` | -| `skip-wait` | Skip wait for LocalStack to start up | `false` | +| `skip-wait` | Skip waiting for LocalStack to start up | `false` | | `state-action` | Valid values are `load`, `save`, `start`, `stop`, `` (empty, don't manage state). Values `start`/`stop` only usable with app previews. | `` | | `state-backend` | Either store the state of LocalStack locally or as a cloud pod. Valid values are `cloud-pods`, `preview` or `local`. Use this option in unison with `state-action` to control behaviour. | `cloud-pods` | | `state-name` | Name of the state artifact (without extension) | `false` | From 100e48bd0aff86649b9b58d70cc984d8098035f7 Mon Sep 17 00:00:00 2001 From: lakkeger Date: Wed, 29 May 2024 10:56:42 +0200 Subject: [PATCH 25/29] feat: change order of preview and state management for possible state load/save --- action.yml | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/action.yml b/action.yml index d5e4f49..b0b0f51 100644 --- a/action.yml +++ b/action.yml @@ -106,18 +106,6 @@ runs: "skip-wait": "${{ inputs.skip-wait }}" } - # Use different artifact from current workflow's by passing the workflow's id as WORKFLOW_ID env variable - - name: Manage state - if: ${{ inputs.state-action == 'save' || inputs.state-action == 'load' }} - uses: jenseng/dynamic-uses@v1 - with: - uses: ${{ env.action-root }}/${{ inputs.state-backend }} - with: |- - { - "name": "${{ inputs.state-name }}", - "action": "${{ inputs.state-action }}" - } - - name: Create Ephemeral Instance if: ${{ inputs.state-action == 'start' && inputs.state-backend == 'preview' }} uses: jenseng/dynamic-uses@v1 @@ -130,6 +118,18 @@ runs: "auto-load-pod": "${{ inputs.state-name }}" } + # Use different artifact from current workflow's by passing the workflow's id as WORKFLOW_ID env variable + - name: Manage state + if: ${{ inputs.state-action == 'save' || inputs.state-action == 'load' }} + uses: jenseng/dynamic-uses@v1 + with: + uses: ${{ env.action-root }}/${{ inputs.state-backend }} + with: |- + { + "name": "${{ inputs.state-name }}", + "action": "${{ inputs.state-action }}" + } + - name: Display Ephemeral Instance URL if: ${{ inputs.state-action == 'start' && inputs.state-backend == 'preview' && (inputs.include-preview == 'true' || inputs.ci-project != '') }} uses: jenseng/dynamic-uses@v1 From 2a0c82fea7d9599137bc2dbc3ee6eff00c0235a5 Mon Sep 17 00:00:00 2001 From: lakkeger Date: Wed, 29 May 2024 12:33:04 +0200 Subject: [PATCH 26/29] refactor: change env variable names --- .github/workflows/ci.yml | 20 ++++++++++---------- .github/workflows/ephemeral.yml | 8 ++++---- README.md | 2 +- action.yml | 14 +++++++------- preview/action.yml | 4 ++-- startup/action.yml | 4 ++-- 6 files changed, 26 insertions(+), 26 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index af3269b..cfbbc5a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,7 +24,7 @@ jobs: - name: Start LocalStack uses: jenseng/dynamic-uses@v1 with: - uses: LocalStack/setup-localstack@${{ env.action-version }} + uses: LocalStack/setup-localstack@${{ env.GH_ACTION_VERSION }} with: |- { "image-tag": "latest", @@ -34,7 +34,7 @@ jobs: } env: LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }} - action-version: ${{ fromJSON(format('["{0}","{1}"]', github.ref_name, github.head_ref))[github.event_name == 'pull_request'] }} + GH_ACTION_VERSION: ${{ github.event_name == 'pull_request' ? github.ref_name : github.head_ref }} - name: Run Tests against LocalStack run: | @@ -52,7 +52,7 @@ jobs: - name: Start LocalStack uses: jenseng/dynamic-uses@v1 with: - uses: LocalStack/setup-localstack@${{ env.action-version }} + uses: LocalStack/setup-localstack@${{ env.GH_ACTION_VERSION }} with: |- { "image-tag": "latest", @@ -62,7 +62,7 @@ jobs: } env: LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }} - action-version: ${{ fromJSON(format('["{0}","{1}"]', github.ref_name, github.head_ref))[github.event_name == 'pull_request'] }} + GH_ACTION_VERSION: ${{ fromJSON(format('["{0}","{1}"]', github.ref_name, github.head_ref))[github.event_name == 'pull_request'] }} - name: Run AWS commands run: | @@ -72,7 +72,7 @@ jobs: - name: Save the Cloud Pod uses: jenseng/dynamic-uses@v1 with: - uses: LocalStack/setup-localstack@${{ env.action-version }} + uses: LocalStack/setup-localstack@${{ env.GH_ACTION_VERSION }} with: |- { "state-name": "cloud-pods-test", @@ -81,7 +81,7 @@ jobs: } env: LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }} - action-version: ${{ fromJSON(format('["{0}","{1}"]', github.ref_name, github.head_ref))[github.event_name == 'pull_request'] }} + GH_ACTION_VERSION: ${{ fromJSON(format('["{0}","{1}"]', github.ref_name, github.head_ref))[github.event_name == 'pull_request'] }} local-state-test: name: 'Test Local State Action' @@ -93,7 +93,7 @@ jobs: - name: Start LocalStack uses: jenseng/dynamic-uses@v1 with: - uses: LocalStack/setup-localstack@${{ env.action-version }} + uses: LocalStack/setup-localstack@${{ env.GH_ACTION_VERSION }} with: |- { "image-tag": "latest", @@ -103,7 +103,7 @@ jobs: } env: LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }} - action-version: ${{ fromJSON(format('["{0}","{1}"]', github.ref_name, github.head_ref))[github.event_name == 'pull_request'] }} + GH_ACTION_VERSION: ${{ fromJSON(format('["{0}","{1}"]', github.ref_name, github.head_ref))[github.event_name == 'pull_request'] }} - name: Run AWS commands run: | @@ -113,7 +113,7 @@ jobs: - name: Save the Cloud Pod uses: jenseng/dynamic-uses@v1 with: - uses: LocalStack/setup-localstack@${{ env.action-version }} + uses: LocalStack/setup-localstack@${{ env.GH_ACTION_VERSION }} with: |- { "state-name": "cloud-pods-test", @@ -123,4 +123,4 @@ jobs: } env: LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }} - action-version: ${{ fromJSON(format('["{0}","{1}"]', github.ref_name, github.head_ref))[github.event_name == 'pull_request'] }} + GH_ACTION_VERSION: ${{ fromJSON(format('["{0}","{1}"]', github.ref_name, github.head_ref))[github.event_name == 'pull_request'] }} diff --git a/.github/workflows/ephemeral.yml b/.github/workflows/ephemeral.yml index 9b0c98a..972639c 100644 --- a/.github/workflows/ephemeral.yml +++ b/.github/workflows/ephemeral.yml @@ -12,7 +12,7 @@ jobs: - name: Deploy Preview uses: jenseng/dynamic-uses@v1 with: - uses: LocalStack/setup-localstack@${{ env.action-version }} + uses: LocalStack/setup-localstack@${{ env.GH_ACTION_VERSION }} with: |- { "github-token": "${{ secrets.GITHUB_TOKEN }}", @@ -22,13 +22,13 @@ jobs: } env: LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }} - action-version: ${{ fromJSON(format('["{0}","{1}"]', github.ref_name, github.head_ref))[github.event_name == 'pull_request'] }} + GH_ACTION_VERSION: ${{ fromJSON(format('["{0}","{1}"]', github.ref_name, github.head_ref))[github.event_name == 'pull_request'] }} # We want explicit shutdown - name: Shutdown ephemeral instance uses: jenseng/dynamic-uses@v1 with: - uses: LocalStack/setup-localstack@${{ env.action-version }} + uses: LocalStack/setup-localstack@${{ env.GH_ACTION_VERSION }} with: |- { "github-token": "${{ secrets.GITHUB_TOKEN }}", @@ -37,4 +37,4 @@ jobs: } env: LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }} - action-version: ${{ fromJSON(format('["{0}","{1}"]', github.ref_name, github.head_ref))[github.event_name == 'pull_request'] }} + GH_ACTION_VERSION: ${{ fromJSON(format('["{0}","{1}"]', github.ref_name, github.head_ref))[github.event_name == 'pull_request'] }} diff --git a/README.md b/README.md index 3a50fc3..824091a 100644 --- a/README.md +++ b/README.md @@ -94,7 +94,7 @@ uses: LocalStack/setup-localstack@$v0.2.0 ... with: - uses: LocalStack/setup-localstack@${{ env.action-version }} + uses: LocalStack/setup-localstack@${{ env.GH_ACTION_VERSION }} with: github-token: ${{ secrets.GITHUB_TOKEN }} state-backend: preview diff --git a/action.yml b/action.yml index b0b0f51..a24c9c6 100644 --- a/action.yml +++ b/action.yml @@ -75,14 +75,14 @@ runs: - run: echo "$(ls -d ./../../_actions/LocalStack/setup-localstack/* | grep -v completed)" shell: bash - - run: echo "action-root=$(ls -d ./../../_actions/LocalStack/setup-localstack/* | grep -v completed)" >> $GITHUB_ENV + - run: echo "GH_ACTION_ROOT=$(ls -d ./../../_actions/LocalStack/setup-localstack/* | grep -v completed)" >> $GITHUB_ENV shell: bash - name: Install tools uses: jenseng/dynamic-uses@v1 if: ${{ inputs.skip-startup == 'true' || inputs.state-backend == 'preview' }} with: - uses: ${{ env.action-root }}/tools + uses: ${{ env.GH_ACTION_ROOT }}/tools with: |- { "install-awslocal": "${{ inputs.install-awslocal }}", @@ -93,7 +93,7 @@ runs: if: ${{ inputs.skip-startup != 'true' && inputs.state-backend != 'preview' }} with: # now we can dynamically determine sub-action path 🥳 - uses: ${{ env.action-root }}/startup + uses: ${{ env.GH_ACTION_ROOT }}/startup # the `with` needs to be converted to a valid json string # keeping in there install-awslocal for backward compatibility with: |- @@ -110,7 +110,7 @@ runs: if: ${{ inputs.state-action == 'start' && inputs.state-backend == 'preview' }} uses: jenseng/dynamic-uses@v1 with: - uses: ${{ env.action-root }}/preview + uses: ${{ env.GH_ACTION_ROOT }}/preview with: |- { "github-token": "${{ inputs.github-token }}", @@ -123,7 +123,7 @@ runs: if: ${{ inputs.state-action == 'save' || inputs.state-action == 'load' }} uses: jenseng/dynamic-uses@v1 with: - uses: ${{ env.action-root }}/${{ inputs.state-backend }} + uses: ${{ env.GH_ACTION_ROOT }}/${{ inputs.state-backend }} with: |- { "name": "${{ inputs.state-name }}", @@ -136,7 +136,7 @@ runs: env: default-include-preview: ${{ fromJSON('["false","true"]')[github.event_name == 'pull_request'] }} with: - uses: ${{ env.action-root }}/finish + uses: ${{ env.GH_ACTION_ROOT }}/finish with: |- { "github-token": "${{ inputs.github-token }}", @@ -148,7 +148,7 @@ runs: if: ${{ !inputs.skip-preview-stop && inputs.state-action == 'stop' && inputs.state-backend == 'preview' }} uses: jenseng/dynamic-uses@v1 with: - uses: ${{ env.action-root }}/ephemeral/shutdown + uses: ${{ env.GH_ACTION_ROOT }}/ephemeral/shutdown with: |- { "name": "${{ inputs.github-token }}", diff --git a/preview/action.yml b/preview/action.yml index ac0fa85..a3c0981 100644 --- a/preview/action.yml +++ b/preview/action.yml @@ -19,14 +19,14 @@ inputs: runs: using: composite steps: - - run: echo "action-root=$(ls -d ./../../_actions/LocalStack/setup-localstack/* | grep -v completed)" >> $GITHUB_ENV + - run: echo "GH_ACTION_ROOT=$(ls -d ./../../_actions/LocalStack/setup-localstack/* | grep -v completed)" >> $GITHUB_ENV shell: bash - name: Initial PR comment if: inputs.github-token uses: jenseng/dynamic-uses@v1 with: - uses: ${{ env.action-root }}/prepare + uses: ${{ env.GH_ACTION_ROOT }}/prepare with: |- { "github-token": "${{ inputs.github-token }}" diff --git a/startup/action.yml b/startup/action.yml index 9135d2a..bd8b760 100644 --- a/startup/action.yml +++ b/startup/action.yml @@ -37,13 +37,13 @@ runs: # with: # github-token: ${{ inputs.github-token }} # ci-project: ${{ inputs.ci-project }} - - run: echo "action-root=$(ls -d ./../../_actions/LocalStack/setup-localstack/* | grep -v completed)" >> $GITHUB_ENV + - run: echo "GH_ACTION_ROOT=$(ls -d ./../../_actions/LocalStack/setup-localstack/* | grep -v completed)" >> $GITHUB_ENV shell: bash - name: Install tools uses: jenseng/dynamic-uses@v1 with: - uses: ${{ env.action-root }}/tools + uses: ${{ env.GH_ACTION_ROOT }}/tools with: |- { "install-awslocal": "${{ inputs.install-awslocal }}", From 5b47bdaebb60ade5971b4298747e682019ba631f Mon Sep 17 00:00:00 2001 From: lakkeger Date: Wed, 29 May 2024 12:56:48 +0200 Subject: [PATCH 27/29] refactor(ci): refactor ternary logic --- .github/workflows/ci.yml | 10 +++++----- .github/workflows/ephemeral.yml | 4 ++-- local/action.yml | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cfbbc5a..902d6ff 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -34,7 +34,7 @@ jobs: } env: LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }} - GH_ACTION_VERSION: ${{ github.event_name == 'pull_request' ? github.ref_name : github.head_ref }} + GH_ACTION_VERSION: ${{ github.event_name == 'pull_request' && github.head_ref || github.ref_name }} - name: Run Tests against LocalStack run: | @@ -62,7 +62,7 @@ jobs: } env: LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }} - GH_ACTION_VERSION: ${{ fromJSON(format('["{0}","{1}"]', github.ref_name, github.head_ref))[github.event_name == 'pull_request'] }} + GH_ACTION_VERSION: ${{ github.event_name == 'pull_request' && github.head_ref || github.ref_name }} - name: Run AWS commands run: | @@ -81,7 +81,7 @@ jobs: } env: LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }} - GH_ACTION_VERSION: ${{ fromJSON(format('["{0}","{1}"]', github.ref_name, github.head_ref))[github.event_name == 'pull_request'] }} + GH_ACTION_VERSION: ${{ github.event_name == 'pull_request' && github.head_ref || github.ref_name }} local-state-test: name: 'Test Local State Action' @@ -103,7 +103,7 @@ jobs: } env: LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }} - GH_ACTION_VERSION: ${{ fromJSON(format('["{0}","{1}"]', github.ref_name, github.head_ref))[github.event_name == 'pull_request'] }} + GH_ACTION_VERSION: ${{ github.event_name == 'pull_request' && github.head_ref || github.ref_name }} - name: Run AWS commands run: | @@ -123,4 +123,4 @@ jobs: } env: LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }} - GH_ACTION_VERSION: ${{ fromJSON(format('["{0}","{1}"]', github.ref_name, github.head_ref))[github.event_name == 'pull_request'] }} + GH_ACTION_VERSION: ${{ github.event_name == 'pull_request' && github.head_ref || github.ref_name }} diff --git a/.github/workflows/ephemeral.yml b/.github/workflows/ephemeral.yml index 972639c..8b564d4 100644 --- a/.github/workflows/ephemeral.yml +++ b/.github/workflows/ephemeral.yml @@ -22,7 +22,7 @@ jobs: } env: LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }} - GH_ACTION_VERSION: ${{ fromJSON(format('["{0}","{1}"]', github.ref_name, github.head_ref))[github.event_name == 'pull_request'] }} + GH_ACTION_VERSION: ${{ github.event_name == 'pull_request' && github.head_ref || github.ref_name }} # We want explicit shutdown - name: Shutdown ephemeral instance @@ -37,4 +37,4 @@ jobs: } env: LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }} - GH_ACTION_VERSION: ${{ fromJSON(format('["{0}","{1}"]', github.ref_name, github.head_ref))[github.event_name == 'pull_request'] }} + GH_ACTION_VERSION: ${{ github.event_name == 'pull_request' && github.head_ref || github.ref_name }} diff --git a/local/action.yml b/local/action.yml index 5984f34..9f56139 100644 --- a/local/action.yml +++ b/local/action.yml @@ -17,7 +17,7 @@ runs: uses: dawidd6/action-download-artifact@v2 if: ${{ inputs.action == 'load' }} env: - workflow_id: ${{ fromJSON(format('["{0}","{1}"]', env.WORKFLOW_ID, github.event.workflow_run.workflow_id))[env.WORKFLOW_ID == ''] }} + workflow_id: ${{ env.WORKFLOW_ID == '' && github.event.workflow_run.workflow_id || env.WORKFLOW_ID }} with: workflow: name: ${{ inputs.name }} From a835bebabe94ebd1a54e7bb5b00d275f4559ad25 Mon Sep 17 00:00:00 2001 From: lakkeger Date: Thu, 30 May 2024 09:13:21 +0200 Subject: [PATCH 28/29] fix: save state without skip-start switch --- .github/workflows/ci.yml | 2 -- README.md | 2 -- action.yml | 26 +++++++++++++------------- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 902d6ff..11c7413 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -77,7 +77,6 @@ jobs: { "state-name": "cloud-pods-test", "state-action": "save", - "skip-startup": "true", } env: LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }} @@ -119,7 +118,6 @@ jobs: "state-name": "cloud-pods-test", "state-action": "save", "state-backend": "local", - "skip-startup": "true", } env: LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }} diff --git a/README.md b/README.md index 824091a..c5a3039 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,6 @@ If the key is not found LocalStack by default falls back to the CE edition and d uses: LocalStack/setup-localstack@v0.2.0 with: install-awslocal: 'true' - skip-startup: 'true' state-backend: cloud-pods state-action: save state-name: my-cloud-pod @@ -156,7 +155,6 @@ jobs: - name: Save LocalStack State uses: LocalStack/setup-localstack@v0.2.0 with: - skip-startup: 'true' state-backend: local state-action: save state-name: my-ls-state-artifact diff --git a/action.yml b/action.yml index a24c9c6..ccc68e1 100644 --- a/action.yml +++ b/action.yml @@ -32,10 +32,10 @@ inputs: required: false default: '' preview-cmd: - description: 'Command(s) used to create a preview of the PR (can use $AWS_ENDPOINT_URL)' + description: 'Command(s) used to create an Ephemeral Instance of the PR (can use $AWS_ENDPOINT_URL)' required: false include-preview: - description: 'Whether to include the created preview URL in the PR comment' + description: 'Whether to include the created Ephemeral Instance URL in the PR comment' required: false skip-startup: description: | @@ -47,7 +47,7 @@ inputs: description: 'Skip wait for LocalStack' required: false default: 'false' - skip-preview-stop: + skip-ephemeral-stop: description: 'Skip stopping LocalStack Ephemeral Instance' required: false default: 'false' @@ -55,13 +55,13 @@ inputs: description: | Manage LocalStack state Valid values are `load`, `save`, `start`, `stop`, `` (empty, don't manage state) - Values `start`/`stop` only usable with app previews. + Values `start`/`stop` only usable with Ephemeral Instances. required: false default: '' state-backend: description: | - Either store the state of LocalStack locally or as a cloud pod. - Valid values are `cloud-pods`, `preview` or `local`. + Either store the state of LocalStack locally, as a cloud pod or start up an ephemeral instance. + Valid values are `cloud-pods`, `ephemeral` or `local`. Use this option in unison with `state-action` to control behaviour. required: false default: 'cloud-pods' @@ -80,7 +80,7 @@ runs: - name: Install tools uses: jenseng/dynamic-uses@v1 - if: ${{ inputs.skip-startup == 'true' || inputs.state-backend == 'preview' }} + if: ${{ inputs.skip-startup == 'true' || inputs.state-backend == 'preview' || inputs.state-action == 'save' }} with: uses: ${{ env.GH_ACTION_ROOT }}/tools with: |- @@ -90,7 +90,7 @@ runs: - name: Start Localstack uses: jenseng/dynamic-uses@v1 - if: ${{ inputs.skip-startup != 'true' && inputs.state-backend != 'preview' }} + if: ${{ inputs.skip-startup != 'true' && inputs.state-backend != 'preview' && inputs.state-action != 'save' }} with: # now we can dynamically determine sub-action path 🥳 uses: ${{ env.GH_ACTION_ROOT }}/startup @@ -107,10 +107,10 @@ runs: } - name: Create Ephemeral Instance - if: ${{ inputs.state-action == 'start' && inputs.state-backend == 'preview' }} + if: ${{ inputs.state-action == 'start' && inputs.state-backend == 'ephemeral' }} uses: jenseng/dynamic-uses@v1 with: - uses: ${{ env.GH_ACTION_ROOT }}/preview + uses: ${{ env.GH_ACTION_ROOT }}/ephemeral/startup with: |- { "github-token": "${{ inputs.github-token }}", @@ -131,7 +131,7 @@ runs: } - name: Display Ephemeral Instance URL - if: ${{ inputs.state-action == 'start' && inputs.state-backend == 'preview' && (inputs.include-preview == 'true' || inputs.ci-project != '') }} + if: ${{ inputs.state-action == 'start' && inputs.state-backend == 'ephemeral' && (inputs.include-preview == 'true' || inputs.ci-project != '') }} uses: jenseng/dynamic-uses@v1 env: default-include-preview: ${{ fromJSON('["false","true"]')[github.event_name == 'pull_request'] }} @@ -141,11 +141,11 @@ runs: { "github-token": "${{ inputs.github-token }}", "ci-project": "${{ inputs.ci-project }}", - "include-preview": "${{ fromJSON(format('["{0}","{1}"]', env.include-preview, inputs.include-preview))[inputs.include-preview != ''] }}" + "include-preview": "${{ inputs.include-preview != '' && inputs.include-preview || env.include-preview }}" } - name: Stop Ephemeral Instance - if: ${{ !inputs.skip-preview-stop && inputs.state-action == 'stop' && inputs.state-backend == 'preview' }} + if: ${{ !inputs.skip-ephemeral-stop && inputs.state-action == 'stop' && inputs.state-backend == 'ephemeral' }} uses: jenseng/dynamic-uses@v1 with: uses: ${{ env.GH_ACTION_ROOT }}/ephemeral/shutdown From 6b8e9913c78e8cb31f49dc55e17fb34ac0385c33 Mon Sep 17 00:00:00 2001 From: lakkeger Date: Thu, 30 May 2024 09:20:29 +0200 Subject: [PATCH 29/29] refactor: rename preview to ephemeral/startup, rename related options --- .github/workflows/ci.yml | 6 +++--- .github/workflows/ephemeral.yml | 8 ++++---- README.md | 16 ++++++++-------- action.yml | 4 ++-- {preview => ephemeral/startup}/action.yml | 0 finish/action.yml | 6 +++--- 6 files changed, 20 insertions(+), 20 deletions(-) rename {preview => ephemeral/startup}/action.yml (100%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 11c7413..a850319 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -36,7 +36,7 @@ jobs: LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }} GH_ACTION_VERSION: ${{ github.event_name == 'pull_request' && github.head_ref || github.ref_name }} - - name: Run Tests against LocalStack + - name: Run Tests Against LocalStack run: | awslocal s3 mb s3://test awslocal s3 ls @@ -104,12 +104,12 @@ jobs: LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }} GH_ACTION_VERSION: ${{ github.event_name == 'pull_request' && github.head_ref || github.ref_name }} - - name: Run AWS commands + - name: Run AWS Commands run: | awslocal s3 mb s3://test awslocal sqs create-queue --queue-name test-queue - - name: Save the Cloud Pod + - name: Save the State Artifact uses: jenseng/dynamic-uses@v1 with: uses: LocalStack/setup-localstack@${{ env.GH_ACTION_VERSION }} diff --git a/.github/workflows/ephemeral.yml b/.github/workflows/ephemeral.yml index 8b564d4..cb378fb 100644 --- a/.github/workflows/ephemeral.yml +++ b/.github/workflows/ephemeral.yml @@ -9,16 +9,16 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Deploy Preview + - name: Deploy Ephemeral Instance uses: jenseng/dynamic-uses@v1 with: uses: LocalStack/setup-localstack@${{ env.GH_ACTION_VERSION }} with: |- { "github-token": "${{ secrets.GITHUB_TOKEN }}", - "state-backend": "preview", + "state-backend": "ephemeral", "state-action": "start", - "skip-preview-stop": "true" + "skip-ephemeral-stop": "true" } env: LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }} @@ -32,7 +32,7 @@ jobs: with: |- { "github-token": "${{ secrets.GITHUB_TOKEN }}", - "state-backend": "preview", + "state-backend": "ephemeral", "state-action": "stop" } env: diff --git a/README.md b/README.md index c5a3039..17fc5be 100644 --- a/README.md +++ b/README.md @@ -76,15 +76,15 @@ If the key is not found LocalStack by default falls back to the CE edition and d > **NOTE**: The `LOCALSTACK_API_KEY` environment variable is required to be set to **save/load** LocalStack's state either as a Cloud Pod or as a file artifact. -### Manage App Preview +### Manage App Preview (Ephemeral Instance) ```yml uses: LocalStack/setup-localstack@$v0.2.0 with: github-token: ${{ secrets.GITHUB_TOKEN }} - state-backend: preview + state-backend: ephemeral state-action: start # Adding this option prevents Ephemeral Instance to be stopped after the `preview-cmd` run - skip-preview-stop: 'true' + skip-ephemeral-stop: 'true' # Optional script/command to run preview-cmd: deploy.sh env: @@ -96,7 +96,7 @@ with: uses: LocalStack/setup-localstack@${{ env.GH_ACTION_VERSION }} with: github-token: ${{ secrets.GITHUB_TOKEN }} - state-backend: preview + state-backend: ephemeral state-action: stop env: LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }} @@ -110,14 +110,14 @@ with: | `configuration` | Configuration variables to use while starting LocalStack container | `None` | | `github-token` | Github token used to create PR comments | | | `image-tag` | Tag of the LocalStack Docker image to use | `latest` | -| `include-preview` | Whether to include the created preview URL in the PR comment | `false` | +| `include-preview` | Whether to include the created Ephemeral Instance URL in the PR comment | `false` | | `install-awslocal` | Whether to install the `awslocal` CLI into the build environment | `true` | -| `preview-cmd` | Command(s) used to create a preview of the PR (can use `$AWS_ENDPOINT_URL`) | | -| `skip-preview-stop` | Skip stopping LocalStack Ephemeral Instance | `false` | +| `preview-cmd` | Command(s) used to create a Ephemeral Instance of the PR (can use `$AWS_ENDPOINT_URL`) | | +| `skip-ephemeral-stop` | Skip stopping LocalStack Ephemeral Instance | `false` | | `skip-startup` | Explicitly prevent LocalStack start up, only installs CLI(s). Recommended to manage state later on in the pipeline or start up an ephemeral instance. | `false` | | `skip-wait` | Skip waiting for LocalStack to start up | `false` | | `state-action` | Valid values are `load`, `save`, `start`, `stop`, `` (empty, don't manage state). Values `start`/`stop` only usable with app previews. | `` | -| `state-backend` | Either store the state of LocalStack locally or as a cloud pod. Valid values are `cloud-pods`, `preview` or `local`. Use this option in unison with `state-action` to control behaviour. | `cloud-pods` | +| `state-backend` | Either store the state of LocalStack locally, as a Cloud Pod or start an Ephemeral Instance. Valid values are `cloud-pods`, `ephemeral` or `local`. Use this option in unison with `state-action` to control behaviour. | `cloud-pods` | | `state-name` | Name of the state artifact (without extension) | `false` | | `use-pro` | Whether to use the Pro version of LocalStack (requires API key to be configured) | `false` | diff --git a/action.yml b/action.yml index ccc68e1..efdea09 100644 --- a/action.yml +++ b/action.yml @@ -80,7 +80,7 @@ runs: - name: Install tools uses: jenseng/dynamic-uses@v1 - if: ${{ inputs.skip-startup == 'true' || inputs.state-backend == 'preview' || inputs.state-action == 'save' }} + if: ${{ inputs.skip-startup == 'true' || inputs.state-backend == 'ephemeral' || inputs.state-action == 'save' }} with: uses: ${{ env.GH_ACTION_ROOT }}/tools with: |- @@ -90,7 +90,7 @@ runs: - name: Start Localstack uses: jenseng/dynamic-uses@v1 - if: ${{ inputs.skip-startup != 'true' && inputs.state-backend != 'preview' && inputs.state-action != 'save' }} + if: ${{ inputs.skip-startup != 'true' && inputs.state-backend != 'ephemeral' && inputs.state-action != 'save' }} with: # now we can dynamically determine sub-action path 🥳 uses: ${{ env.GH_ACTION_ROOT }}/startup diff --git a/preview/action.yml b/ephemeral/startup/action.yml similarity index 100% rename from preview/action.yml rename to ephemeral/startup/action.yml diff --git a/finish/action.yml b/finish/action.yml index 14b48f6..eb8c95f 100644 --- a/finish/action.yml +++ b/finish/action.yml @@ -8,10 +8,10 @@ inputs: description: 'Name of the CI project tracked in LocalStack Cloud' required: false include-preview: - description: 'Whether to include the created preview URL in the PR comment' + description: 'Whether to include the created Ephemeral Instance URL in the PR comment' required: false preview-url: - description: 'The preview url to include in the PR comment' + description: 'The Ephmeral Instance URL to include in the PR comment' required: false runs: @@ -28,7 +28,7 @@ runs: shell: bash run: echo "pr_id=$(> $GITHUB_OUTPUT - - name: Load the preview URL + - name: Load the Ephemeral Instance URL shell: bash if: inputs.include-preview run: |