diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a850319..6e45678 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -42,6 +42,34 @@ jobs: awslocal s3 ls echo "Test Execution complete!" + localstack-action-version-test: + name: 'Test LocalStack Version with Github Actions' + runs-on: ubuntu-latest + steps: + - 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: + uses: LocalStack/setup-localstack@${{ env.GH_ACTION_VERSION }} + with: |- + { + "image-tag": "3.2.0", + "install-awslocal": "true", + "configuration": "DEBUG=1", + "use-pro": "true", + } + env: + LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }} + GH_ACTION_VERSION: ${{ github.event_name == 'pull_request' && github.head_ref || github.ref_name }} + + - name: Run Version Test Against LocalStack + run: | + LS_VERSION=$(docker ps | grep localstack | cut -d " " -f4 | cut -d ":" -f2) + exit $(test "x${LS_VERSION}" = "x3.2.0") + cloud-pods-test: name: 'Test Cloud Pods Action' runs-on: ubuntu-latest @@ -99,6 +127,9 @@ jobs: "install-awslocal": "true", "configuration": "DEBUG=1", "use-pro": "true", + "state-name": "cloud-pods-test", + "state-action": "load", + "state-backend": "local", } env: LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }} @@ -106,7 +137,9 @@ jobs: - name: Run AWS Commands run: | + awslocal s3 rb s3://test awslocal s3 mb s3://test + awslocal sqs delete-queue --queue-url $(awslocal sqs get-queue-url --queue-name test-queue --output text) awslocal sqs create-queue --queue-name test-queue - name: Save the State Artifact diff --git a/.github/workflows/ephemeral.yml b/.github/workflows/ephemeral.yml index cb378fb..0c46669 100644 --- a/.github/workflows/ephemeral.yml +++ b/.github/workflows/ephemeral.yml @@ -15,14 +15,19 @@ jobs: uses: LocalStack/setup-localstack@${{ env.GH_ACTION_VERSION }} with: |- { - "github-token": "${{ secrets.GITHUB_TOKEN }}", + "github-token": ${{ toJSON(secrets.GITHUB_TOKEN) }}, "state-backend": "ephemeral", "state-action": "start", - "skip-ephemeral-stop": "true" + "skip-ephemeral-stop": "true", + "preview-cmd": ${{ toJSON(env.PREVIEW_CMD) }} } env: LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }} GH_ACTION_VERSION: ${{ github.event_name == 'pull_request' && github.head_ref || github.ref_name }} + PREVIEW_CMD: |- + awslocal s3 mb s3://test-bucket + awslocal sqs create-queue --queue-name=test-queue + echo "Deploy is done." # We want explicit shutdown - name: Shutdown ephemeral instance @@ -31,7 +36,7 @@ jobs: uses: LocalStack/setup-localstack@${{ env.GH_ACTION_VERSION }} with: |- { - "github-token": "${{ secrets.GITHUB_TOKEN }}", + "github-token": ${{ toJSON(secrets.GITHUB_TOKEN) }}, "state-backend": "ephemeral", "state-action": "stop" } diff --git a/action.yml b/action.yml index efdea09..b0c4bad 100644 --- a/action.yml +++ b/action.yml @@ -50,7 +50,7 @@ inputs: skip-ephemeral-stop: description: 'Skip stopping LocalStack Ephemeral Instance' required: false - default: 'false' + default: 'true' state-action: description: | Manage LocalStack state @@ -72,12 +72,18 @@ inputs: runs: using: "composite" steps: - - run: echo "$(ls -d ./../../_actions/LocalStack/setup-localstack/* | grep -v completed)" + - run: > + echo "GH_ACTION_ROOT=$( + ls -d $( + ls -d ./../../_actions/* | + grep -i localstack | + tail -n1 + )/setup-localstack/* | + grep -v completed | + tail -n1 + )" >> $GITHUB_ENV shell: bash - - 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 == 'ephemeral' || inputs.state-action == 'save' }} @@ -85,7 +91,7 @@ runs: uses: ${{ env.GH_ACTION_ROOT }}/tools with: |- { - "install-awslocal": "${{ inputs.install-awslocal }}", + "install-awslocal": ${{ toJSON(inputs.install-awslocal) }}, } - name: Start Localstack @@ -98,12 +104,12 @@ runs: # keeping in there install-awslocal for backward compatibility with: |- { - "image-tag": "${{ inputs.image-tag }}", - "install-awslocal": "${{ inputs.install-awslocal }}", - "use-pro": "${{ inputs.use-pro }}", - "configuration": "${{ inputs.configuration }}", - "ci-project": "${{ inputs.ci-project }}", - "skip-wait": "${{ inputs.skip-wait }}" + "image-tag": ${{ toJSON(inputs.image-tag) }}, + "install-awslocal": ${{ toJSON(inputs.install-awslocal) }}, + "use-pro": ${{ toJSON(inputs.use-pro) }}, + "configuration": ${{ toJSON(inputs.configuration) }}, + "ci-project": ${{ toJSON(inputs.ci-project) }}, + "skip-wait": ${{ toJSON(inputs.skip-wait) }} } - name: Create Ephemeral Instance @@ -113,9 +119,9 @@ runs: uses: ${{ env.GH_ACTION_ROOT }}/ephemeral/startup with: |- { - "github-token": "${{ inputs.github-token }}", - "preview-cmd": "${{ inputs.preview-cmd }}", - "auto-load-pod": "${{ inputs.state-name }}" + "github-token": ${{ toJSON(inputs.github-token) }}, + "preview-cmd": ${{ toJSON(inputs.preview-cmd) }}, + "auto-load-pod": ${{ toJSON(inputs.state-name) }} } # Use different artifact from current workflow's by passing the workflow's id as WORKFLOW_ID env variable @@ -126,30 +132,28 @@ runs: uses: ${{ env.GH_ACTION_ROOT }}/${{ inputs.state-backend }} with: |- { - "name": "${{ inputs.state-name }}", - "action": "${{ inputs.state-action }}" + "name": ${{ toJSON(inputs.state-name) }}, + "action": ${{ toJSON(inputs.state-action) }} } - name: Display Ephemeral Instance URL 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'] }} with: uses: ${{ env.GH_ACTION_ROOT }}/finish with: |- { - "github-token": "${{ inputs.github-token }}", - "ci-project": "${{ inputs.ci-project }}", - "include-preview": "${{ inputs.include-preview != '' && inputs.include-preview || env.include-preview }}" + "github-token": ${{ toJSON(inputs.github-token) }}, + "ci-project": ${{ toJSON(inputs.ci-project) }}, + "include-preview": ${{ inputs.include-preview != '' && toJSON(inputs.include-preview) || toJSON(env.include-preview) }} } - name: Stop Ephemeral Instance - if: ${{ !inputs.skip-ephemeral-stop && inputs.state-action == 'stop' && inputs.state-backend == 'ephemeral' }} + if: ${{ (inputs.skip-ephemeral-stop == 'false' || inputs.state-action == 'stop') && inputs.state-backend == 'ephemeral' }} uses: jenseng/dynamic-uses@v1 with: uses: ${{ env.GH_ACTION_ROOT }}/ephemeral/shutdown with: |- { - "name": "${{ inputs.github-token }}", + "github-token": ${{ toJSON(inputs.github-token) }}, } \ No newline at end of file diff --git a/ephemeral/startup/action.yml b/ephemeral/startup/action.yml index a3c0981..326a788 100644 --- a/ephemeral/startup/action.yml +++ b/ephemeral/startup/action.yml @@ -19,7 +19,16 @@ inputs: runs: using: composite steps: - - run: echo "GH_ACTION_ROOT=$(ls -d ./../../_actions/LocalStack/setup-localstack/* | grep -v completed)" >> $GITHUB_ENV + - run: > + echo "GH_ACTION_ROOT=$( + ls -d $( + ls -d ./../../_actions/* | + grep -i localstack | + tail -n1 + )/setup-localstack/* | + grep -v completed | + tail -n1 + )" >> $GITHUB_ENV shell: bash - name: Initial PR comment @@ -29,7 +38,7 @@ runs: uses: ${{ env.GH_ACTION_ROOT }}/prepare with: |- { - "github-token": "${{ inputs.github-token }}" + "github-token": ${{ toJSON(inputs.github-token) }} } - name: Download PR artifact diff --git a/finish/action.yml b/finish/action.yml index eb8c95f..c5e2e09 100644 --- a/finish/action.yml +++ b/finish/action.yml @@ -17,12 +17,24 @@ inputs: runs: using: composite steps: - - name: Download PR artifact - uses: dawidd6/action-download-artifact@v2 + # Try to get pr artifact from current workflow + - name: Download current PR artifact + id: get-pr-artifact + uses: actions/download-artifact@v3 + continue-on-error: true with: - workflow: ${{ github.event.workflow_run.workflow_id }} name: pr + # If the above fails, try to get the latest pr artifact from the PR related workflows + - name: Download latest PR artifact + uses: dawidd6/action-download-artifact@v6 + if: ${{ steps.get-pr-artifact.outcome == 'failure' }} + with: + name: pr + pr: ${{ github.event.pull_request.number }} + # Can be ID or workflow file name, if empty falls back to the latest successful run of the current workflow + workflow: ${{ env.PR_ARTIFACT_WORKFLOW }} + - name: Load the PR ID id: pr shell: bash @@ -32,8 +44,8 @@ runs: shell: bash if: inputs.include-preview run: | - if [[ -n "${{ inputs.preview-url }}" ]]; then - echo "LS_PREVIEW_URL=${{ inputs.preview-url }}" >> $GITHUB_ENV + if [[ -n "${LS_PREVIEW_URL:-${{ inputs.preview-url }}}" ]]; then + echo "LS_PREVIEW_URL=${LS_PREVIEW_URL:-${{ inputs.preview-url }}}" >> $GITHUB_ENV elif [[ -e ls-preview-url.txt ]]; then echo "LS_PREVIEW_URL=$(> $GITHUB_ENV else diff --git a/local/action.yml b/local/action.yml index 9f56139..1705300 100644 --- a/local/action.yml +++ b/local/action.yml @@ -13,14 +13,23 @@ inputs: runs: using: "composite" steps: - - name: Download PR artifact - uses: dawidd6/action-download-artifact@v2 + # Try to get pr artifact from current workflow + - name: Download current workflow's Local State artifact + id: get-state-artifact if: ${{ inputs.action == 'load' }} - env: - workflow_id: ${{ env.WORKFLOW_ID == '' && github.event.workflow_run.workflow_id || env.WORKFLOW_ID }} + uses: actions/download-artifact@v3 + continue-on-error: true + with: + name: ${{ inputs.name }} + + # If the above fails, try to get the latest artifact from given workflow + - name: Download latest Local State artifact + uses: dawidd6/action-download-artifact@v6 + if: ${{ inputs.action == 'load' && steps.get-state-artifact.outcome == 'failure' }} with: - workflow: name: ${{ inputs.name }} + workflow: ${{ env.LS_STATE_ARTIFACT_WORKFLOW }} # Can be ID or workflow file name, if empty falls back to the latest successful run of the current workflow + if_no_artifact_found: warn - run: | if [ "$ACTION" = "save" ]; then diff --git a/startup/action.yml b/startup/action.yml index bd8b760..ec88fd5 100644 --- a/startup/action.yml +++ b/startup/action.yml @@ -37,7 +37,16 @@ runs: # with: # github-token: ${{ inputs.github-token }} # ci-project: ${{ inputs.ci-project }} - - run: echo "GH_ACTION_ROOT=$(ls -d ./../../_actions/LocalStack/setup-localstack/* | grep -v completed)" >> $GITHUB_ENV + - run: > + echo "GH_ACTION_ROOT=$( + ls -d $( + ls -d ./../../_actions/* | + grep -i localstack | + tail -n1 + )/setup-localstack/* | + grep -v completed | + tail -n1 + )" >> $GITHUB_ENV shell: bash - name: Install tools @@ -46,7 +55,7 @@ runs: uses: ${{ env.GH_ACTION_ROOT }}/tools with: |- { - "install-awslocal": "${{ inputs.install-awslocal }}", + "install-awslocal": ${{ toJSON(inputs.install-awslocal) }}, } - name: Start LocalStack @@ -55,12 +64,14 @@ runs: 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" & - CONFIGURATION="$CONFIGURATION DNS_ADDRESS=127.0.0.1" + CONFIGURATION="DNS_ADDRESS=127.0.0.1 ${CONFIGURATION}" + IMAGE_NAME="${IMAGE_NAME:-localstack/localstack-pro:${IMAGE_TAG}}" else - docker pull localstack/localstack:"$IMAGE_TAG" & + IMAGE_NAME="${IMAGE_NAME:-localstack/localstack:${IMAGE_TAG}}" fi + CONFIGURATION="IMAGE_NAME=${IMAGE_NAME} ${CONFIGURATION}" + docker pull ${IMAGE_NAME} & export CI_PROJECT=${{ inputs.ci-project }} eval "${CONFIGURATION} localstack start -d" diff --git a/tools/action.yml b/tools/action.yml index 65b59fd..ee90f84 100644 --- a/tools/action.yml +++ b/tools/action.yml @@ -11,11 +11,11 @@ runs: steps: - name: Start LocalStack run: | + pip install --upgrade pip which localstack > /dev/null || pip install localstack if [ "$INSTALL_AWSLOCAL" = true ]; then which awslocal > /dev/null || pip install awscli-local[ver1] fi - shell: bash env: INSTALL_AWSLOCAL: "${{ inputs.install-awslocal }}"