-
Notifications
You must be signed in to change notification settings - Fork 83
182 lines (163 loc) · 7.03 KB
/
deploy-sanity-suite.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
name: Deploy Sanity Suite
on:
workflow_call:
inputs:
environment:
type: string
required: true
secrets:
AWS_STAGING_ACCOUNT_ID:
required: false
AWS_PROD_ACCOUNT_ID:
required: false
AWS_STAGING_S3_BUCKET_NAME:
required: false
AWS_PROD_S3_BUCKET_NAME:
required: false
AWS_STAGING_S3_SYNC_ROLE:
required: false
AWS_PROD_S3_SYNC_ROLE:
required: false
AWS_STAGING_CF_DISTRIBUTION_ID:
required: false
AWS_PROD_CF_DISTRIBUTION_ID:
required: false
SANITY_SUITE_STAGING_WRITE_KEY:
required: false
SANITY_SUITE_PROD_WRITE_KEY:
required: false
SANITY_SUITE_STAGING_DATAPLANE_URL:
required: false
SANITY_SUITE_PROD_DATAPLANE_URL:
required: false
SANITY_SUITE_STAGING_CONFIG_SERVER_HOST:
required: false
SANITY_SUITE_PROD_CONFIG_SERVER_HOST:
required: false
RS_STAGING_BUGSNAG_API_KEY:
required: false
RS_PROD_BUGSNAG_API_KEY:
required: false
SLACK_BOT_TOKEN:
required: true
SLACK_RELEASE_CHANNEL_ID:
required: true
permissions:
id-token: write # allows the JWT to be requested from GitHub's OIDC provider
contents: read # This is required for actions/checkout
env:
NODE_OPTIONS: '--no-warnings'
CACHE_CONTROL: "\"max-age=3600\""
jobs:
deploy:
name: Deploy Sanity Suite
runs-on: [self-hosted, Linux, X64]
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.sha }}
- name: Configure deployment options
id: deployment-options
run: |
current_version=$(jq -r .version packages/sanity-suite/package.json)
echo "CURRENT_VERSION_VALUE=$current_version" >> $GITHUB_ENV
echo "DATE=$(date)" >> $GITHUB_ENV
if [ "${{ inputs.environment }}" == "staging" ]; then
echo "AWS_ACCOUNT_ID=${{ secrets.AWS_STAGING_ACCOUNT_ID }}" >> $GITHUB_ENV
echo "AWS_S3_SYNC_ROLE=${{ secrets.AWS_STAGING_S3_SYNC_ROLE }}" >> $GITHUB_ENV
echo "AWS_S3_BUCKET_NAME=${{ secrets.AWS_STAGING_S3_BUCKET_NAME }}" >> $GITHUB_ENV
echo "AWS_CF_DISTRIBUTION_ID=${{ secrets.AWS_STAGING_CF_DISTRIBUTION_ID }}" >> $GITHUB_ENV
echo "WRITE_KEY=${{ secrets.SANITY_SUITE_STAGING_WRITE_KEY }}" >> $GITHUB_ENV
echo "DATAPLANE_URL=${{ secrets.SANITY_SUITE_STAGING_DATAPLANE_URL }}" >> $GITHUB_ENV
echo "CONFIG_SERVER_HOST=${{ secrets.SANITY_SUITE_STAGING_CONFIG_SERVER_HOST }}" >> $GITHUB_ENV
echo "BUGSNAG_API_KEY=${{ secrets.RS_STAGING_BUGSNAG_API_KEY }}" >> $GITHUB_ENV
echo "BUGSNAG_RELEASE_STAGE=staging" >> $GITHUB_ENV
echo "SDK_CDN_VERSION_PATH_PREFIX=staging/latest/" >> $GITHUB_ENV
echo "SUITE_CDN_PATH=/staging/" >> $GITHUB_ENV
elif [ "${{ inputs.environment }}" == "production" ]; then
echo "AWS_ACCOUNT_ID=${{ secrets.AWS_PROD_ACCOUNT_ID }}" >> $GITHUB_ENV
echo "AWS_S3_SYNC_ROLE=${{ secrets.AWS_PROD_S3_SYNC_ROLE }}" >> $GITHUB_ENV
echo "AWS_S3_BUCKET_NAME=${{ secrets.AWS_PROD_S3_BUCKET_NAME }}" >> $GITHUB_ENV
echo "AWS_CF_DISTRIBUTION_ID=${{ secrets.AWS_PROD_CF_DISTRIBUTION_ID }}" >> $GITHUB_ENV
echo "WRITE_KEY=${{ secrets.SANITY_SUITE_PROD_WRITE_KEY }}" >> $GITHUB_ENV
echo "DATAPLANE_URL=${{ secrets.SANITY_SUITE_PROD_DATAPLANE_URL }}" >> $GITHUB_ENV
echo "CONFIG_SERVER_HOST=${{ secrets.SANITY_SUITE_PROD_CONFIG_SERVER_HOST }}" >> $GITHUB_ENV
echo "BUGSNAG_API_KEY=${{ secrets.RS_PROD_BUGSNAG_API_KEY }}" >> $GITHUB_ENV
echo "BUGSNAG_RELEASE_STAGE=production" >> $GITHUB_ENV
echo "SDK_CDN_VERSION_PATH_PREFIX=" >> $GITHUB_ENV
echo "SUITE_CDN_PATH=/" >> $GITHUB_ENV
fi
- name: Install AWS CLI
uses: unfor19/install-aws-cli-action@master
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::${{ env.AWS_ACCOUNT_ID }}:role/${{ env.AWS_S3_SYNC_ROLE }}
aws-region: us-east-1
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: 'npm'
- name: Install dependencies
env:
HUSKY: 0
run: |
npm run setup:ci
- name: Build artifacts
env:
WRITE_KEY: ${{ env.WRITE_KEY }}
DATAPLANE_URL: ${{ env.DATAPLANE_URL }}
CONFIG_SERVER_HOST: ${{ env.CONFIG_SERVER_HOST }}
BUGSNAG_API_KEY: ${{ env.BUGSNAG_API_KEY }}
BUGSNAG_RELEASE_STAGE: ${{ env.BUGSNAG_RELEASE_STAGE }}
SDK_CDN_VERSION_PATH_PREFIX: ${{ env.SDK_CDN_VERSION_PATH_PREFIX }}
HUSKY: 0
run: |
npm run build:sanity
- name: Sync files to S3
run: |
aws s3 cp packages/sanity-suite/dist/ s3://${{ env.AWS_S3_BUCKET_NAME }}/sanity-suite${{ env.SUITE_CDN_PATH }} --recursive --cache-control ${{ env.CACHE_CONTROL }}
- name: Create Cloudfront invalidation
run: |
AWS_MAX_ATTEMPTS=10 aws cloudfront create-invalidation --distribution-id ${{ env.AWS_CF_DISTRIBUTION_ID }} --paths "/sanity-suite${{ env.SUITE_CDN_PATH }}*"
- name: Send message to Slack channel
id: slack
uses: slackapi/[email protected]
continue-on-error: true
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
PROJECT_NAME: 'Sanity suite - ${{ inputs.environment }}'
CDN_URL: 'https://cdn.rudderlabs.com/sanity-suite${{ env.SUITE_CDN_PATH }}v3/cdn/index.html'
LINK_TEXT: ${{ ((inputs.environment == 'staging' && format('v{0} - Staging', env.CURRENT_VERSION_VALUE)) || format('v{0}', env.CURRENT_VERSION_VALUE)) }}
with:
channel-id: ${{ secrets.SLACK_RELEASE_CHANNEL_ID }}
payload: |
{
"text": "*New Deployment: ${{ env.PROJECT_NAME }} - <${{ env.CDN_URL }}|${{ env.LINK_TEXT }}>*\n${{ env.DATE }}\nCC: <!subteam^S0555JBV36D> <!subteam^S03SHJ20350>",
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "New Deployment: ${{ env.PROJECT_NAME }}"
}
},
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*<${{ env.CDN_URL }}|${{ env.LINK_TEXT }}>*\n${{ env.DATE }}\nCC: <!subteam^S0555JBV36D> <!subteam^S03SHJ20350>"
},
"accessory": {
"type": "image",
"image_url": "https://cdn.jsdelivr.net/npm/programming-languages-logos/src/javascript/javascript.png",
"alt_text": "JavaScript Icon"
}
}
]
}