Skip to content

Commit

Permalink
Preview app (#296)
Browse files Browse the repository at this point in the history
* add previews

* Add preview app

* link files

* Fix lint

* Downgrade sst due to this issue https://github.com/sst/ion/issues/774

* Update readme

* Add destroy workflow when pr is closed

* Fix destroy deployed preview app workflow name

* Add script to retrieve the app url

* Set the right branch name for deployment
Share preview app url as comment on PR

* Deploy preview regardless of outcome of other steps

* Sanitize branch name

* Fix sst url after deploy

* fix share preview url

* use $GITHUB_HEAD_REF to get branch name when sharing preivew

* Support deployment when pr is reopened

* use sanitized branch name for preview url sharing

* Remove pr reopened from workflow

* resolve package-lock

* enh: full-stack preview app enhancements (#317)

* refactor: change `SS_STAGE` to `SST_STAGE`

* deps: use latest stable release of sst

sst v3 is now a stable release. this removes the need for the go binary
install step. npm wins, yet again

* fix: fix lint, prettier issues

* refactor: remove redundant `default_app` directory

---------

Co-authored-by: Barnabas A Nsoh <[email protected]>

* Fix lint

* add npm to run deploy preview

* add sst script

---------

Co-authored-by: tams sokari <[email protected]>
  • Loading branch information
ayinloya and tamssokari authored Oct 22, 2024
1 parent 980387b commit c6950bb
Show file tree
Hide file tree
Showing 23 changed files with 15,043 additions and 104 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/deploy-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,43 @@ jobs:
- name: deploy preview to s3
run: |
aws s3 sync --follow-symlinks --delete dist s3://${{ secrets.AWS_S3_BUCKET }}/${{ env.DEST_DIR_EMBED }}
full-stack:
needs: [embed]
if: always()
defaults:
run:
working-directory: ./previews
runs-on: ubuntu-latest
steps:
- name: checkout code
uses: actions/checkout@v4
- name: configure aws credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_GITHUB_ACTIONS_ROLE }}
aws-region: ${{ secrets.AWS_REGION }}
- name: set sst stage
id: get_branch_name
run: |
BRANCH_NAME=${{ github.event.pull_request.head.ref }}
SANITIZED_BRANCH_NAME=$(echo "$BRANCH_NAME" | sed 's/[^a-zA-Z0-9]/-/g')
echo "SST_STAGE=$SANITIZED_BRANCH_NAME" >> $GITHUB_OUTPUT
- name: install dependencies
run: npm install
- name: build application
run: npm run build
- name: configure sst secrets
run: |
npm run sst secret set PartnerId ${{ secrets.PREVIEW_PARTNER_ID }} --stage ${{ steps.get_branch_name.outputs.SST_STAGE }} &&
npm run sst secret set CallbackUrl ${{ secrets.PREVIEW_CALLBACK_URL }} --stage ${{ steps.get_branch_name.outputs.SST_STAGE }} &&
npm run sst secret set SmileIdApiKey ${{ secrets.PREVIEW_SMILEID_API_KEY }} --stage ${{ steps.get_branch_name.outputs.SST_STAGE }} &&
npm run sst secret set SmileIdEnvironment ${{ secrets.PREVIEW_SMILEID_ENVIRONMENT }} --stage ${{ steps.get_branch_name.outputs.SST_STAGE }}
- name: deploy sst app
if: github.event.pull_request.merged != true
id: deploy_sst_app
run: |
npm run sst deploy --stage=${{ steps.get_branch_name.outputs.SST_STAGE }}
- name: remove sst app
if: github.event.pull_request.merged == true
run: |
npm run sst remove --stage=${{ steps.get_branch_name.outputs.SST_STAGE }}
43 changes: 43 additions & 0 deletions .github/workflows/destroy-preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: destroy-preview
on:
workflow_call:
pull_request:
types:
- closed
permissions:
id-token: write
contents: read
jobs:
full-stack:
defaults:
run:
working-directory: ./previews
runs-on: ubuntu-latest
steps:
- name: checkout code
uses: actions/checkout@v4
- name: configure aws credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_GITHUB_ACTIONS_ROLE }}
aws-region: ${{ secrets.AWS_REGION }}
- name: install sst
run: |
curl -fsSL https://ion.sst.dev/install | VERSION=0.1.51 bash
- name: set sst stage
id: get_branch_name
run: |
BRANCH_NAME=${{ github.event.pull_request.head.ref }}
SANITIZED_BRANCH_NAME=$(echo "$BRANCH_NAME" | sed 's/[^a-zA-Z0-9]/-/g')
echo "SS_STAGE=$SANITIZED_BRANCH_NAME" >> $GITHUB_OUTPUT
- name: install dependencies
run: npm install
- name: configure sst secrets
run: |
sst secret set PartnerId ${{ secrets.PREVIEW_PARTNER_ID }} --stage=${{ steps.get_branch_name.outputs.SS_STAGE }} &&
sst secret set CallbackUrl ${{ secrets.PREVIEW_CALLBACK_URL }} --stage=${{ steps.get_branch_name.outputs.SS_STAGE }} &&
sst secret set SmileIdApiKey ${{ secrets.PREVIEW_SMILEID_API_KEY }} --stage=${{ steps.get_branch_name.outputs.SS_STAGE }} &&
sst secret set SmileIdEnvironment ${{ secrets.PREVIEW_SMILEID_ENVIRONMENT }} --stage=${{ steps.get_branch_name.outputs.SS_STAGE }}
- name: remove sst app
run: |
sst remove --stage=${{ steps.get_branch_name.outputs.SS_STAGE }}
19 changes: 19 additions & 0 deletions .github/workflows/share-preview-url.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,21 @@ jobs:
steps:
- name: checkout code
uses: actions/checkout@v4
- name: configure aws credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_GITHUB_ACTIONS_ROLE }}
aws-region: ${{ secrets.AWS_REGION }}
- name: install sst
run: |
curl -fsSL https://ion.sst.dev/install | VERSION=0.1.51 bash
- name: retrieve sst app url
id: get_app_url
working-directory: ./previews
run: |
BRANCH_NAME=${{ github.event.pull_request.head.ref }}
SANITIZED_BRANCH_NAME=$(echo "$BRANCH_NAME" | sed 's/[^a-zA-Z0-9]/-/g')
echo "SS_STAGE=$SANITIZED_BRANCH_NAME" >> $GITHUB_OUTPUT
- name: get dest dir for web smart-camera-web
id: get_dest_dir_smart_camera_web
working-directory: ./packages/smart-camera-web
Expand All @@ -37,3 +52,7 @@ jobs:
✅ Preview URL for Embed:
https://cdn.smileidentity.com/${{ env.DEST_DIR_EMBED }}/js/script.min.js
✅ Preview URL for Web Client:
${{ steps.get_app_url.outputs.PREVIEW_APP_URL }}
Loading

0 comments on commit c6950bb

Please sign in to comment.