Skip to content
Open
Changes from 3 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
74 changes: 62 additions & 12 deletions .github/workflows/storybook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ on:
workflow_dispatch:

env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_AMPLIFY_APP_ID: ${{ secrets.AWS_AMPLIFY_APP_ID }}
AWS_REGION: ${{ secrets.AWS_REGION }}
AWS_ROLE_ARN: ${{ secrets.AWS_ROLE_ARN }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
Comment thread
jpzwarte marked this conversation as resolved.
Outdated
CHROMATIC_PROJECT_TOKEN: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
FONT_AWESOME_AUTH_TOKEN: ${{ secrets.FONT_AWESOME_AUTH_TOKEN }}
FIGMA_TOKEN: ${{ secrets.FIGMA_AUTH_TOKEN }}
Expand Down Expand Up @@ -45,15 +50,53 @@ jobs:

- run: yarn storybook

- uses: azure/static-web-apps-deploy@v1
id: deploy
- uses: aws-actions/configure-aws-credentials@v6
with:
azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN }}
action: upload
app_location: dist
production_branch: main
skip_api_build: true
skip_app_build: true
aws-access-key-id: ${{ env.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ env.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}
role-to-assume: ${{ env.AWS_ROLE_ARN }}

- name: Set branch name
id: branch
run: |
if [ "${{ github.event_name }}" == "pull_request" ]; then
echo "name=pr-${{ github.event.pull_request.number }}" >> "$GITHUB_OUTPUT"
else
echo "name=main" >> "$GITHUB_OUTPUT"
fi

- name: Ensure Amplify branch exists
if: github.event_name == 'pull_request'
run: |
aws amplify create-branch \
--app-id "${{ env.AWS_AMPLIFY_APP_ID }}" \
--branch-name "${{ steps.branch.outputs.name }}" 2>/dev/null || true
Comment thread
jpzwarte marked this conversation as resolved.
Outdated
Comment thread
jpzwarte marked this conversation as resolved.
Outdated

Comment thread
jpzwarte marked this conversation as resolved.
Outdated
- name: Deploy to AWS Amplify
id: deploy
run: |
DEPLOYMENT=$(aws amplify create-deployment \
--app-id "${{ env.AWS_AMPLIFY_APP_ID }}" \
--branch-name "${{ steps.branch.outputs.name }}" \
--output json)

JOB_ID=$(echo "$DEPLOYMENT" | jq -r '.jobId')
ZIP_URL=$(echo "$DEPLOYMENT" | jq -r '.zipUploadUrl')

cd dist && zip -qr ../deployment.zip . && cd ..
curl -sSf -T deployment.zip "$ZIP_URL"

aws amplify start-deployment \
--app-id "${{ env.AWS_AMPLIFY_APP_ID }}" \
--branch-name "${{ steps.branch.outputs.name }}" \
--job-id "$JOB_ID"

DEFAULT_DOMAIN=$(aws amplify get-app \
--app-id "${{ env.AWS_AMPLIFY_APP_ID }}" \
--query 'app.defaultDomain' \
--output text)
echo "preview_url=https://${{ steps.branch.outputs.name }}.${DEFAULT_DOMAIN}" >> "$GITHUB_OUTPUT"
Comment thread
jpzwarte marked this conversation as resolved.
Comment thread
jpzwarte marked this conversation as resolved.
Comment thread
jpzwarte marked this conversation as resolved.

- if: github.event_name == 'pull_request'
uses: peter-evans/find-comment@v3
Expand All @@ -70,15 +113,22 @@ jobs:
issue-number: ${{ github.event.pull_request.number }}
body: |
### 🕸 Storybook preview
You can view a preview [here](${{ steps.deploy.outputs.static_web_app_url }}) (commit [`${{ github.event.pull_request.head.sha }}`](https://github.com/sl-design-system/components/commit/${{ github.event.pull_request.head.sha }})).
You can view a preview [here](${{ steps.deploy.outputs.preview_url }}) (commit [`${{ github.event.pull_request.head.sha }}`](https://github.com/sl-design-system/components/commit/${{ github.event.pull_request.head.sha }})).
edit-mode: replace

cleanup:
if: github.event_name == 'pull_request' && github.event.action == 'closed'
runs-on: ubuntu-latest
name: Cleanup
steps:
- uses: azure/static-web-apps-deploy@v1
- uses: aws-actions/configure-aws-credentials@v4
with:
azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN }}
action: close
aws-access-key-id: ${{ env.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ env.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}
Comment thread
jpzwarte marked this conversation as resolved.
Outdated
Comment thread
jpzwarte marked this conversation as resolved.
Outdated

Comment thread
jpzwarte marked this conversation as resolved.
Outdated
- name: Delete PR branch from Amplify
run: |
aws amplify delete-branch \
--app-id "${{ env.AWS_AMPLIFY_APP_ID }}" \
--branch-name "pr-${{ github.event.pull_request.number }}"
Comment thread
jpzwarte marked this conversation as resolved.
Outdated
Comment thread
jpzwarte marked this conversation as resolved.
Outdated
Comment thread
jpzwarte marked this conversation as resolved.
Outdated
Comment thread
jpzwarte marked this conversation as resolved.
Outdated
Loading