forked from aws/karpenter-provider-aws
-
Notifications
You must be signed in to change notification settings - Fork 0
95 lines (91 loc) · 3.79 KB
/
Copy pathwebsite-preview.yaml
File metadata and controls
95 lines (91 loc) · 3.79 KB
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
name: Deploy Website Preview to Amplify
on:
workflow_run:
workflows: [ WebsitePreviewTrigger ]
types: [ completed ]
jobs:
preview:
permissions:
id-token: write
contents: read
pull-requests: write
statuses: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- uses: ./.github/actions/download-artifact
- id: website-metadata
run: |
pr_number="$(head -n 1 /tmp/artifacts/website-metadata.txt)"
pr_commit="$(tail -n 1 /tmp/artifacts/website-metadata.txt)"
{
echo PR_COMMIT="$pr_commit"
echo PR_NUMBER="$pr_number"
echo BRANCH_NAME="pr-$pr_number"
} >> "$GITHUB_ENV"
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
ref: ${{ env.PR_COMMIT }}
path: pr-content
- uses: ./.github/actions/commit-status/start
with:
name: "${{ github.workflow }} / ${{ github.job }} (pull_request_review)"
git_ref: ${{ env.PR_COMMIT }}
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@99214aa6889fcddfa57764031d71add364327e59 # v6.1.3
with:
role-to-assume: arn:aws:iam::${{ vars.RELEASE_PREVIEW_ACCOUNT_ID }}:role/${{ vars.WEBSITE_ROLE_NAME }}
aws-region: ${{ vars.AMPLIFY_REGION }}
- name: Get preview URL
run: |
APP_DOMAIN=$(aws amplify get-app --app-id ${{ vars.AMPLIFY_APP_ID_PREVIEW }} --query 'app.defaultDomain' --output text)
PREVIEW_URL="https://${{ env.BRANCH_NAME }}.$APP_DOMAIN"
echo PREVIEW_URL="$PREVIEW_URL" >> "$GITHUB_ENV"
- name: Deploy website
uses: ./.github/actions/deploy-website
with:
role: arn:aws:iam::${{ vars.RELEASE_PREVIEW_ACCOUNT_ID }}:role/${{ vars.WEBSITE_ROLE_NAME }}
region: ${{ vars.AMPLIFY_REGION }}
amplify-app-id: ${{ vars.AMPLIFY_APP_ID_PREVIEW }}
amplify-branch-name: ${{ env.BRANCH_NAME }}
s3-bucket: ${{ vars.AMPLIFY_S3_BUCKET_BETA }}
s3-prefix: pr-${{ env.PR_NUMBER }}/
hugo-base-url: ${{ env.PREVIEW_URL }}
content-path: pr-content
- uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
env:
PREVIEW_URL: ${{ env.PREVIEW_URL }}
PR_COMMIT: ${{ env.PR_COMMIT }}
with:
script: |
const commentBody = `**Preview deployment ready!**
**Preview URL:** ${process.env.PREVIEW_URL}
Built from commit \`${process.env.PR_COMMIT}\``;
const existingComment = (await github.rest.issues.listComments({
issue_number: process.env.PR_NUMBER,
owner: context.repo.owner,
repo: context.repo.repo,
})).data.find(comment =>
comment.user.login === 'github-actions[bot]' &&
comment.body.includes('**Preview deployment ready!**')
);
if (existingComment) {
await github.rest.issues.updateComment({
comment_id: existingComment.id,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentBody
});
} else {
await github.rest.issues.createComment({
issue_number: process.env.PR_NUMBER,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentBody
});
}
- if: always()
uses: ./.github/actions/commit-status/end
with:
name: "${{ github.workflow }} / ${{ github.job }} (pull_request_review)"
git_ref: ${{ env.PR_COMMIT }}