Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add initial action to create preview environments from PR builds #4

Merged
merged 8 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ inputs:
description: 'Github token used to create PR comments'
required: false
default: ''
preview-cmd:
description: 'Command(s) used to create a preview of the PR (can use $AWS_ENDPOINT_URL)'
required: false
default: ''

runs:
using: "composite"
Expand Down Expand Up @@ -70,3 +74,8 @@ runs:
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
# to enable/disable the "Start LocalStack" action above. This way we could make this action
whummer marked this conversation as resolved.
Show resolved Hide resolved
# the single entry point which then delegates to sub-actions in this repo, based on the
# user-provided configuration...
20 changes: 17 additions & 3 deletions finish/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ inputs:
description: 'Github token used to create PR comments'
required: true
ci-project:
description: 'Name of the CI project to track in LocalStack Cloud'
required: true
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'
type: boolean
default: false

runs:
using: composite
Expand All @@ -22,12 +26,22 @@ runs:
shell: bash
run: echo "pr_id=$(<pr-id.txt)" >> $GITHUB_OUTPUT

- name: Load the preview URL
shell: bash
whummer marked this conversation as resolved.
Show resolved Hide resolved
run: |
if [[ -e ls-preview-url.txt ]]; then
echo "LS_PREVIEW_URL=$(<ls-preview-url.txt)" >> $GITHUB_ENV
else
echo "LS_PREVIEW_URL=Unable to determine preview URL" >> $GITHUB_ENV
fi

- name: Update status comment
uses: actions-cool/maintain-one-comment@v3.1.1
with:
token: ${{ inputs.github-token }}
body: |
🚀 LocalStack Stack Insights and Cloud Pod state for this CI run: https://app.localstack.cloud/ci/${{ inputs.ci-project }}
${{ inputs.ci-project && format('{0}{1}', '🚀 LocalStack Stack Insights and Cloud Pod state for this CI run: https://app.localstack.cloud/ci/', inputs.ci-project) }}
${{ inputs.include-preview && format('{0}{1}', '🚀 Preview for this PR: ', env.LS_PREVIEW_URL) }}
<!-- Sticky Pull Request Comment -->
body-include: '<!-- Sticky Pull Request Comment -->'
number: ${{ steps.pr.outputs.pr_id }}
61 changes: 61 additions & 0 deletions preview/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Create PR Preview

inputs:
github-token:
description: 'Github token used to create PR comments'
required: true
localstack-api-key:
description: 'LocalStack API key used to create the preview environment'
required: true
preview-cmd:
description: 'Command(s) used to create a preview of the PR (can use $AWS_ENDPOINT_URL)'
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.github-token
with:
github-token: ${{ inputs.github-token }}

- name: Download PR artifact
uses: actions/download-artifact@v3
with:
name: pr

- name: Create preview environment
shell: bash
run: |
prId=$(<pr-id.txt)
# TODO: make preview name configurable!
previewName=preview-$prId

response=$(curl -X POST -d '{}' \
-H 'authorization: token ${{ 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
echo "Unable to create preview environment. API response: $response"
exit 1
fi
echo "Created preview environment with endpoint URL: $endpointUrl"

echo $endpointUrl > ./ls-preview-url.txt
echo "LS_PREVIEW_URL=$endpointUrl" >> $GITHUB_ENV
echo "AWS_ENDPOINT_URL=$endpointUrl" >> $GITHUB_ENV

- name: Upload preview instance URL
uses: actions/upload-artifact@v3
with:
name: pr
path: ./ls-preview-url.txt

- name: Run preview deployment
shell: bash
run:
${{ inputs.preview-cmd }}