-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
43 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,26 @@ | ||
name: Surge PR Preview | ||
name: Preview Deployment | ||
|
||
on: [pull_request] | ||
on: | ||
pull_request: | ||
types: [opened, synchronize, reopened, closed] | ||
|
||
env: | ||
NODE: 18 | ||
WORKING_DIRECTORY: packages/web | ||
|
||
jobs: | ||
preview: | ||
build: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
pull-requests: write # allow surge-preview to create/update PR comments | ||
id-token: write | ||
contents: read | ||
|
||
steps: | ||
- name: Cancel Previous Runs | ||
uses: styfle/[email protected] | ||
with: | ||
access_token: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
|
@@ -30,12 +39,29 @@ jobs: | |
run: yarn lint | ||
working-directory: ${{ env.WORKING_DIRECTORY }} | ||
|
||
- uses: afc163/surge-preview@v1 | ||
id: preview_step | ||
- name: Configure AWS credentials using OIDC | ||
uses: aws-actions/configure-aws-credentials@v2 | ||
with: | ||
surge_token: ${{ secrets.SURGE_TOKEN }} | ||
dist: dist | ||
build: | | ||
vite build | ||
- name: Get the preview_url | ||
run: echo "url => ${{ steps.preview_step.outputs.preview_url }}" | ||
role-to-assume: arn:aws:iam::003081160852:role/osm-gradient-deploy-s3-role | ||
aws-region: us-east-1 | ||
|
||
- name: Build | ||
run: npx vite build | ||
working-directory: ${{ env.WORKING_DIRECTORY }} | ||
|
||
- name: Deploy to S3 (Preview) | ||
if: github.event.action != 'closed' | ||
run: | | ||
PR_NUMBER=${{ github.event.number }} | ||
BUCKET_NAME="osm-gradient-pr-${PR_NUMBER}" | ||
aws s3 mb s3://$BUCKET_NAME | ||
aws s3 sync ./dist s3://$BUCKET_NAME --delete | ||
aws s3 website s3://$BUCKET_NAME --index-document index.html --error-document index.html | ||
working-directory: ${{ env.WORKING_DIRECTORY }} | ||
|
||
- name: Cleanup S3 Bucket | ||
if: github.event.action == 'closed' | ||
run: | | ||
PR_NUMBER=${{ github.event.number }} | ||
BUCKET_NAME="osm-gradient-pr-${PR_NUMBER}" | ||
aws s3 rb s3://$BUCKET_NAME --force |