-
Notifications
You must be signed in to change notification settings - Fork 0
147 lines (131 loc) · 4.92 KB
/
build-and-release.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
on:
workflow_call:
inputs:
environment:
required: true
type: string
commit_hash:
required: true
type: string
destination_bucket:
required: true
type: string
jobs:
set-vars:
runs-on: ubuntu-latest
outputs:
app-name: ${{ steps.export.outputs.app-name }}
ec2-instance-type: ${{ steps.export.outputs.ec2-instance-type }}
version: ${{ steps.export.outputs.version }}
runner-size: ${{ steps.export.outputs.runner-size }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
path: main
- id: export
run: |
cd main
. ./.github/.github.env
echo "ec2-instance-type=${EC2_INSTANCE_TYPE}" >> $GITHUB_OUTPUT
echo "app-name=${APP_NAME}" >> $GITHUB_OUTPUT
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "runner-size=${RUNNER_SIZE}" >> $GITHUB_OUTPUT
start-runner:
uses: i-dot-ai/i-dot-ai-core-github-actions/.github/workflows/start-runner.yml@main
needs: set-vars
with:
EC2_INSTANCE_TYPE: ${{ needs.set-vars.outputs.ec2-instance-type }}
RUNNER_SIZE: ${{ needs.set-vars.outputs.runner-size }}
ENVIRONMENT: ${{ inputs.environment }}
secrets:
AWS_GITHUBRUNNER_USER_ACCESS_KEY: ${{ secrets.AWS_GITHUBRUNNER_USER_ACCESS_KEY }}
AWS_GITHUBRUNNER_USER_SECRET_ID: ${{ secrets.AWS_GITHUBRUNNER_USER_SECRET_ID }}
AWS_GITHUBRUNNER_PAT: ${{ secrets.AWS_GITHUBRUNNER_PAT }}
AWS_REGION: ${{ secrets.AWS_REGION }}
AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }}
publish-website:
runs-on: ${{ needs.start-runner.outputs.label }}
needs:
- set-vars
- start-runner
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ inputs.commit_hash }}
- name: Install NPM
uses: actions/setup-node@v4
with:
node-version: latest
- name: Create .env
run: |
echo CONTENTFUL_SPACE="${{ secrets.CONTENTFUL_SPACE }}" >> .env
echo CONTENTFUL_ACCESS_TOKEN="${{ secrets.CONTENTFUL_ACCESS_TOKEN }}" >> .env
echo CMS_REPO_TOKEN="${{ secrets.CMS_REPO_TOKEN }}" >> .env
if [[ ${{ inputs.environment }} != "prod" ]]; then
echo PREVIEW_ACCESS_TOKEN="${{ secrets.PREVIEW_ACCESS_TOKEN }}" >> .env
fi
- name: NPM clean install
run: npm ci
- name: NPM build
run: npm run build --if-present
- name: Install Playwright Browsers
run: npx playwright install --with-deps
- name: NPM run tests
run: |
npx playwright test
- name: Copy built _site folder to s3
run: |
cd _site
aws s3 cp . s3://${{ secrets[inputs.destination_bucket] }}/ --recursive
determine-success:
needs:
- set-vars
- start-runner
- publish-website
runs-on: ${{ needs.start-runner.outputs.label }}
if: always()
outputs:
success: ${{ steps.success.outputs.success }}
steps:
- id: success
run: |
if [[ "${{ needs.publish-website.result }}" == "success" ]]; then
echo "success=true" >> $GITHUB_OUTPUT
else
echo "success=false" >> $GITHUB_OUTPUT
fi
notify-slack:
uses: i-dot-ai/i-dot-ai-core-github-actions/.github/workflows/slack-notify.yml@main
needs:
- set-vars
- start-runner
- publish-website
- determine-success
with:
RUNNER_LABEL: ${{ needs.start-runner.outputs.label }}
WORKFLOW_PASSED: ${{ needs.determine-success.outputs.success == 'true' }}
SUCCESS_PAYLOAD: "{\"text\": \"Deployment succeeded to ${{ inputs.environment }} :airplane:\", \"blocks\": [{\"type\": \"header\",\"text\": {\"type\": \"plain_text\",\"text\": \"Deployed main to ai gov uk website :hype-elmo:\"}}]}"
FAILURE_PAYLOAD: "{\"text\": \"Failed to deploy to ${{ inputs.environment }}\",\"blocks\": [{\"type\": \"header\",\"text\": {\"type\": \"plain_text\",\"text\": \"Failed to deploy main to the ai gov uk website :aaaaaaaaaa:\"}}]}"
secrets:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
stop-runner:
uses: i-dot-ai/i-dot-ai-core-github-actions/.github/workflows/stop-runner.yml@main
if: needs.start-runner.outputs.use-persisted == 0 && always()
needs:
- set-vars
- start-runner
- publish-website
- determine-success
- notify-slack
with:
RUNNER_LABEL: ${{ needs.start-runner.outputs.label }}
EC2_INSTANCE_ID: ${{ needs.start-runner.outputs.ec2-instance-id }}
secrets:
AWS_GITHUBRUNNER_USER_ACCESS_KEY: ${{ secrets.AWS_GITHUBRUNNER_USER_ACCESS_KEY }}
AWS_GITHUBRUNNER_USER_SECRET_ID: ${{ secrets.AWS_GITHUBRUNNER_USER_SECRET_ID }}
AWS_GITHUBRUNNER_PAT: ${{ secrets.AWS_GITHUBRUNNER_PAT}}
AWS_REGION: ${{ secrets.AWS_REGION }}
AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }}