-
Notifications
You must be signed in to change notification settings - Fork 7
144 lines (127 loc) · 4.95 KB
/
deploy-frontend.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
name: Deploy frontend
env:
AWS_REGION: eu-west-2
# Deploy role & Artificate buckets are Logical id GitHubActionsRole & GitHubArtifactSourceBucket Value from Build Pipeline
on:
push:
branches:
- main
workflow_run:
workflows: ["Build frontend"]
types:
- completed
jobs:
pr-data:
name: Get data for merged PR
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: read
outputs:
data: ${{ steps.get_pr_data.outputs.result }}
steps:
- name: Get PR data
uses: actions/github-script@v7
id: get_pr_data
with:
script: |
const query = `query($owner: String!, $name: String!, $oid: GitObjectID!) {
repository(owner: $owner, name: $name) {
object(oid: $oid) {
... on Commit {
oid
message
associatedPullRequests(first: 1) {
nodes {
number
title
merged
mergedAt
mergeCommit {
oid
}
}
}
}
}
owner {
login
}
name
nameWithOwner
}
}`
const variables = {
owner: context.repo.owner,
name: context.repo.repo,
oid: context.sha,
shortSha: context.sha.slice(0, 7),
}
const result = await github.graphql(query, variables).then((response) => {
const firstLineOfCommitMessage = response.repository.object.message.slice(0, response.repository.object.message.indexOf("\n"));
const res = {
pr_number: null,
pr_title: null,
pr_merged_at: null,
pr_merge_commit_sha: null,
commit_message: firstLineOfCommitMessage,
repo_full_name: response.repository.nameWithOwner,
repo_owner: response.repository.owner.login,
repo_name: response.repository.name,
repository: response.repository.nameWithOwner,
commitsha: context.sha,
commitmessage: firstLineOfCommitMessage,
}
res["codepipeline-artifact-revision-summary"] = `${context.sha}: ${firstLineOfCommitMessage}`;
if (response.repository.object.associatedPullRequests.nodes.length > 0 && response.repository.object.associatedPullRequests.nodes[0].merged) {
const prData = response.repository.object.associatedPullRequests.nodes[0];
res.pr_number = prData.number.toString();
res.pr_title = prData.title;
res.pr_merged_at = prData.mergedAt;
res.pr_merge_commit_sha = prData.mergeCommit.oid;
res.commitmessage = prData.title;
res["codepipeline-artifact-revision-summary"] = `${prData.mergeCommit.oid}: ${response.repository.nameWithOwner}#${prData.number} ${prData.title}`;
}
if (res["codepipeline-artifact-revision-summary"].length > 2048) {
res["codepipeline-artifact-revision-summary"] = res["codepipeline-artifact-revision-summary"].slice(0, 2048);
}
return res;
}).catch((error) => {
throw error;
});
for (const key in result) {
if (result[key] == null) {
result[key] = "";
}
// strip non-ascii characters from all values
result[key] = result[key].replace(/[^\x20-\x7E]/g, '');
}
console.log(result);
return result;
deploy:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest
timeout-minutes: 60
needs: pr-data
permissions:
id-token: write
contents: read
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up AWS credentials
uses: aws-actions/configure-aws-credentials@v2
with:
role-to-assume: ${{ secrets.DEPLOY_ROLE }}
aws-region: ${{ env.AWS_REGION }}
- name: Upload frontend Terraform files
working-directory: ci/terraform
run: |
zip -r frontend.zip .
S3_RESPONSE=`aws s3api put-object \
--bucket ${{ secrets.ARTIFACT_BUCKET }} \
--key frontend.zip \
--body frontend.zip \
--metadata '${{ toJson(fromJson(needs.pr-data.outputs.data)) }}'`
VERSION=`echo $S3_RESPONSE | jq .VersionId -r`
echo "VERSION=$VERSION" >> $GITHUB_ENV