Skip to content

Deploy

Deploy #1225

Workflow file for this run

name: Deploy
on:
workflow_run:
workflows: ['Build']
types:
- completed
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
jobs:
deploy:
runs-on: ubuntu-latest
permissions:
id-token: write
actions: read
contents: read # This is required for actions/checkout
pull-requests: write # For actions/github-script
environment:
name: staging
env:
CLOUDFRONT_DISTRIBUTION_ID: ${{ secrets.CLOUDFRONT_DISTRIBUTION_ID }}
S3_BUCKET_NAME: ${{ secrets.S3_BUCKET_NAME }}
PR_NUMBER: ${{ github.event.workflow_run.pull_requests[0].number }}
HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
steps:
- name: Download artifact
id: download-artifact
uses: dawidd6/action-download-artifact@09f2f74827fd3a8607589e5ad7f9398816f540fe # v3.1.4
with:
workflow_conclusion: success
run_id: ${{ github.event.workflow_run.id }}
name: build
path: artifact
allow_forks: false
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 # v4.0.2
with:
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
role-session-name: github-actions-pr-nala-${{ github.event.workflow_run.id }}
aws-region: us-west-2
- name: Deploy
id: deploy-site
env:
AWS_REGION: us-west-2
run: |
shopt -s inherit_errexit
set -xeEo pipefail
# [ -z "$AWS_ACCESS_KEY_ID" ] && exit 1
echo "::group::Upload to AWS S3"
cd ./artifact/storybook-static
aws configure set default.s3.max_concurrent_requests 200
aws configure set default.s3.max_queue_size 10000
if [[ -z ${PR_NUMBER} ]]; then # non PR
aws s3 sync . "s3://${S3_BUCKET_NAME}/" --delete --exclude 'pr-*/*' --exclude '*.old.css' --exclude '*.diff'
else
aws s3 sync . "s3://${S3_BUCKET_NAME}/pr-${PR_NUMBER}/commit-${HEAD_SHA}/" --delete --exclude '*.old.css' --exclude '*.diff'
aws s3 sync . "s3://${S3_BUCKET_NAME}/pr-${PR_NUMBER}/" --delete --exclude 'commit-*/*' --exclude '*.old.css' --exclude '*.diff'
fi
echo "::endgroup::"
- name: Post GitHub comment
uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6.4.1
if: ${{ github.event.workflow_run.event == 'pull_request' }}
with:
script: |
const fs = require('fs/promises')
const path = require('path')
const cssDiffDir = './artifact/tokens/css'
const fileSizes = await fs.readFile(path.join(cssDiffDir, 'file-sizes.diff'), 'utf-8')
const diffFilePaths = (await fs.readdir(cssDiffDir)).filter(f => f.startsWith('variables') && f.endsWith('.diff'))
const diffs = await Promise.all(diffFilePaths.map(async f => {
return {
file: f,
diff: await fs.readFile(path.join(cssDiffDir, f), 'utf-8')
}
}))
await github.rest.issues.createComment({
issue_number: ${{ github.event.workflow_run.pull_requests[0].number }},
owner: context.repo.owner,
repo: context.repo.repo,
body: `👋 Thanks for Submitting! This PR is available for preview at the link below.
✅ PR tip preview: https://${{ github.event.workflow_run.pull_requests[0].number }}.pr.nala.bravesoftware.com/
✅ Commit preview: https://${{ github.event.workflow_run.pull_requests[0].number }}.pr.nala.bravesoftware.com/commit-${{ github.event.workflow_run.head_sha }}/
\`\`\`diff
${fileSizes}
\`\`\`
${diffs.map(({file, diff}) => `<details>
<summary>Variables Diff: ${file}</summary>
\`\`\`diff
${diff}
\`\`\`
</details>`).join('\n')}`
})