-
Notifications
You must be signed in to change notification settings - Fork 26
101 lines (91 loc) · 3.94 KB
/
deploy.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
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')}`
})