|
| 1 | +name: Create PR Preview |
| 2 | + |
| 3 | +inputs: |
| 4 | + github-token: |
| 5 | + description: 'Github token used to create PR comments' |
| 6 | + required: true |
| 7 | + localstack-api-key: |
| 8 | + description: 'LocalStack API key used to create the preview environment' |
| 9 | + required: true |
| 10 | + preview-cmd: |
| 11 | + description: 'Command(s) used to create a preview of the PR (can use $AWS_ENDPOINT_URL)' |
| 12 | + required: false |
| 13 | + default: '' |
| 14 | + |
| 15 | +runs: |
| 16 | + using: composite |
| 17 | + steps: |
| 18 | + - name: Initial PR comment |
| 19 | + # TODO: potentially replace with Action version number over time |
| 20 | + uses: LocalStack/setup-localstack/prepare@main |
| 21 | + if: inputs.github-token |
| 22 | + with: |
| 23 | + github-token: ${{ inputs.github-token }} |
| 24 | + |
| 25 | + - name: Download PR artifact |
| 26 | + uses: actions/download-artifact@v3 |
| 27 | + with: |
| 28 | + name: pr |
| 29 | + |
| 30 | + - name: Create preview environment |
| 31 | + shell: bash |
| 32 | + run: | |
| 33 | + prId=$(<pr-id.txt) |
| 34 | + # TODO: make preview name configurable! |
| 35 | + previewName=preview-$prId |
| 36 | +
|
| 37 | + response=$(curl -X POST -d '{}' \ |
| 38 | + -H 'authorization: token ${{ inputs.localstack-api-key }}' \ |
| 39 | + -H 'content-type: application/json' \ |
| 40 | + https://api.localstack.cloud/v1/previews/$previewName) |
| 41 | + endpointUrl=$(echo "$response" | jq -r .endpoint_url) |
| 42 | + if [ "$endpointUrl" = "null" ] || [ "$endpointUrl" = "" ]; then |
| 43 | + echo "Unable to create preview environment. API response: $response" |
| 44 | + exit 1 |
| 45 | + fi |
| 46 | + echo "Created preview environment with endpoint URL: $endpointUrl" |
| 47 | +
|
| 48 | + echo $endpointUrl > ./ls-preview-url.txt |
| 49 | + echo "LS_PREVIEW_URL=$endpointUrl" >> $GITHUB_ENV |
| 50 | + echo "AWS_ENDPOINT_URL=$endpointUrl" >> $GITHUB_ENV |
| 51 | +
|
| 52 | + - name: Upload preview instance URL |
| 53 | + uses: actions/upload-artifact@v3 |
| 54 | + with: |
| 55 | + name: pr |
| 56 | + path: ./ls-preview-url.txt |
| 57 | + |
| 58 | + - name: Run preview deployment |
| 59 | + shell: bash |
| 60 | + run: |
| 61 | + ${{ inputs.preview-cmd }} |
0 commit comments