diff --git a/README.md b/README.md index 7899633..817a293 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ A GitHub Action to setup [LocalStack](https://github.com/localstack/localstack) ```yml - name: Start LocalStack - uses: LocalStack/setup-localstack@v0.2.0 + uses: LocalStack/setup-localstack@v0.2.3 with: image-tag: 'latest' install-awslocal: 'true' @@ -31,7 +31,7 @@ If the key is not found LocalStack by default falls back to the CE edition and d ### Install only CLIs and startup later ```yml - name: Install LocalStack CLIs - uses: LocalStack/setup-localstack@v0.2.0 + uses: LocalStack/setup-localstack@v0.2.3 with: skip-startup: 'true' install-awslocal: 'true' @@ -39,7 +39,7 @@ If the key is not found LocalStack by default falls back to the CE edition and d ... - name: Start LocalStack - uses: LocalStack/setup-localstack@v0.2.0 + uses: LocalStack/setup-localstack@v0.2.3 with: image-tag: 'latest' env: @@ -49,7 +49,7 @@ If the key is not found LocalStack by default falls back to the CE edition and d ### Save a state later on in the pipeline ```yml - name: Save LocalStack State - uses: LocalStack/setup-localstack@v0.2.0 + uses: LocalStack/setup-localstack@v0.2.3 with: install-awslocal: 'true' state-backend: cloud-pods @@ -63,7 +63,7 @@ If the key is not found LocalStack by default falls back to the CE edition and d ### Load an already saved state ```yml - name: Start LocalStack and Load State - uses: LocalStack/setup-localstack@v0.2.0 + uses: LocalStack/setup-localstack@v0.2.3 with: install-awslocal: 'true' state-backend: cloud-pods @@ -78,7 +78,7 @@ If the key is not found LocalStack by default falls back to the CE edition and d ### Manage Application Previews (on an Ephemeral Instance) ```yml -uses: LocalStack/setup-localstack@$v0.2.0 +uses: LocalStack/setup-localstack@v0.2.3 with: github-token: ${{ secrets.GITHUB_TOKEN }} state-backend: ephemeral @@ -93,7 +93,7 @@ uses: LocalStack/setup-localstack@$v0.2.0 ... with: - uses: LocalStack/setup-localstack@${{ env.GH_ACTION_VERSION }} + uses: LocalStack/setup-localstack@v0.2.3 with: github-token: ${{ secrets.GITHUB_TOKEN }} state-backend: ephemeral @@ -137,7 +137,7 @@ jobs: - uses: actions/checkout@v3 - name: Start LocalStack - uses: LocalStack/setup-localstack@v0.2.0 + uses: LocalStack/setup-localstack@v0.2.3 with: image-tag: 'latest' install-awslocal: 'true' @@ -156,7 +156,7 @@ jobs: echo "Test Execution complete!" - name: Save LocalStack State - uses: LocalStack/setup-localstack@v0.2.0 + uses: LocalStack/setup-localstack@v0.2.3 with: state-backend: local state-action: save diff --git a/ephemeral/shutdown/action.yml b/ephemeral/shutdown/action.yml index a2169b4..8a1364c 100644 --- a/ephemeral/shutdown/action.yml +++ b/ephemeral/shutdown/action.yml @@ -22,18 +22,24 @@ runs: shell: bash run: echo "pr_id=$(> $GITHUB_OUTPUT - - name: Shutdown ephemeral instance + - name: Setup preview name shell: bash run: | prId=$(> $GITHUB_ENV + - name: Shutdown ephemeral instance + shell: bash + run: | response=$(curl -X DELETE \ + -s -o /dev/null -w "%{http_code}" \ -H "ls-api-key: ${LOCALSTACK_API_KEY:-${{ inputs.localstack-api-key }}}" \ -H "content-type: application/json" \ https://api.localstack.cloud/v1/compute/instances/$previewName) - if [[ "$response" != "{}" ]]; then + if [[ "$response" -ne 200 ]]; then # In case the deletion fails, e.g. if the instance cannot be found, we raise a proper error on the platform echo "Unable to delete preview environment. API response: $response" exit 1 diff --git a/ephemeral/startup/action.yml b/ephemeral/startup/action.yml index fd60ed0..3a4d999 100644 --- a/ephemeral/startup/action.yml +++ b/ephemeral/startup/action.yml @@ -55,17 +55,37 @@ runs: with: name: pr - - name: Create preview environment + - name: Setup preview name shell: bash run: | prId=$(> $GITHUB_ENV + - name: Create preview environment + shell: bash + id: create-instance + run: | autoLoadPod="${AUTO_LOAD_POD:-${{ inputs.auto-load-pod }}}" extensionAutoInstall="${EXTENSION_AUTO_INSTALL:-${{ inputs.extension-auto-install }}}" lifetime="${{ inputs.lifetime }}" + list_response=$(curl -X GET \ + -H "ls-api-key: ${LOCALSTACK_API_KEY:-${{ inputs.localstack-api-key }}}" \ + -H "content-type: application/json" \ + https://api.localstack.cloud/v1/compute/instances) + + instance_exists=$(echo "$list_response" | jq --arg NAME "$previewName" '.[] | select(.instance_name == $NAME)') + + if [ -n "$instance_exists" ]; then + del_response=$(curl -X DELETE \ + -H "ls-api-key: ${LOCALSTACK_API_KEY:-${{ inputs.localstack-api-key }}}" \ + -H "content-type: application/json" \ + https://api.localstack.cloud/v1/compute/instances/$previewName) + fi + response=$(curl -X POST -d "{\"instance_name\": \"${previewName}\", \"lifetime\": ${lifetime} ,\"env_vars\": {\"AUTO_LOAD_POD\": \"${autoLoadPod}\", \"EXTENSION_AUTO_INSTALL\": \"${extensionAutoInstall}\"}}"\ -H "ls-api-key: ${LOCALSTACK_API_KEY:-${{ inputs.localstack-api-key }}}" \ -H "content-type: application/json" \ @@ -92,3 +112,14 @@ runs: shell: bash run: ${{ inputs.preview-cmd }} + + - name: Print logs of ephemeral instance + if: ${{ !cancelled() && steps.create-instance.outcome == 'success' }} + shell: bash + run: | + log_response=$(curl -X GET \ + -H "ls-api-key: ${LOCALSTACK_API_KEY:-${{ inputs.localstack-api-key }}}" \ + -H "content-type: application/json" \ + https://api.localstack.cloud/v1/compute/instances/$previewName/logs) + + echo "$log_response" | jq -r '.[].content'