-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirebase-hosting-pull-request-deploy.yml
More file actions
233 lines (217 loc) · 9.21 KB
/
Copy pathfirebase-hosting-pull-request-deploy.yml
File metadata and controls
233 lines (217 loc) · 9.21 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
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
name: Deploy to Firebase Hosting on pull request
on: workflow_dispatch
jobs:
depoloy_storybook_to_firebase:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
checks: write
actions: read
steps:
- name: Checkout
uses: actions/checkout@v6
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: "Download pr artifact"
uses: actions/github-script@v8
with:
script: |
var artifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{github.event.workflow_run.id }},
});
var matchArtifact = artifacts.data.artifacts.filter((artifact) => {
return artifact.name == "pr"
})[0];
var download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
var fs = require('fs');
fs.writeFileSync('${{github.workspace}}/pr.zip', Buffer.from(download.data));
- run: unzip pr.zip
- name: "Store github pr number and title"
uses: actions/github-script@v8
id: store_pr_number_and_title
with:
script: |
let fs = require('fs');
var prNumber = fs.readFileSync('${{github.workspace}}/NR', 'utf8');
var pr = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber
});
var prTitle = pr.data.title;
core.setOutput('prNumber', prNumber);
core.setOutput('prTitle', prTitle);
- name: "Download artifact"
uses: actions/github-script@v8
with:
script: |
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.payload.workflow_run.id,
});
let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
return artifact.name == "storybook"
})[0];
let download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
let fs = require('fs');
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/packages/openbridge-webcomponents/storybook.zip`, Buffer.from(download.data));
- name: "Unzip artifact"
run: cd packages/openbridge-webcomponents/ && mkdir -p storybook-static && unzip storybook.zip -d storybook-static
- uses: FirebaseExtended/action-hosting-deploy@v0
id: firebase
with:
repoToken: "${{ secrets.GITHUB_TOKEN }}"
firebaseServiceAccount: "${{ secrets.FIREBASE_SERVICE_ACCOUNT_OPENBRIDGE_DEMO }}"
projectId: openbridge-demo
entrypoint: "packages/openbridge-webcomponents"
channelId: "${{ steps.store_pr_number_and_title.outputs.prNumber }}-${{ steps.store_pr_number_and_title.outputs.prTitle }}"
- name: "Comment on PR"
uses: actions/github-script@v8
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
var fs = require('fs');
var issue_number = ${{ steps.store_pr_number_and_title.outputs.prNumber }}
// check if comment already exists
var comments = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue_number
});
var commentExists = comments.data.some(comment => comment.body.includes('The storybook can be viewed at'));
if (commentExists) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: comments.data.find(comment => comment.body.includes('The storybook can be viewed at')).id,
body: 'The storybook can be viewed at ${{ steps.firebase.outputs.details_url }}'
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue_number,
body: 'The storybook can be viewed at ${{ steps.firebase.outputs.details_url }}'
});
}
deploy_demo_to_firebase:
runs-on: ubuntu-latest
permissions:
pull-requests: write
checks: write
contents: read
actions: read
steps:
- name: Checkout
uses: actions/checkout@v6
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: "Download pr artifact"
uses: actions/github-script@v8
with:
script: |
var artifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{github.event.workflow_run.id }},
});
var matchArtifact = artifacts.data.artifacts.filter((artifact) => {
return artifact.name == "pr"
})[0];
var download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
var fs = require('fs');
fs.writeFileSync('${{github.workspace}}/pr.zip', Buffer.from(download.data));
- run: unzip pr.zip
- name: "Store github pr number and title"
uses: actions/github-script@v8
id: store_pr_number_and_title
with:
script: |
let fs = require('fs');
var prNumber = fs.readFileSync('${{github.workspace}}/NR', 'utf8');
var pr = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber
});
var prTitle = pr.data.title;
core.setOutput('prNumber', prNumber);
core.setOutput('prTitle', prTitle);
- name: "Download artifact"
uses: actions/github-script@v8
with:
script: |
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.payload.workflow_run.id,
});
let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
return artifact.name == "vue-demo"
})[0];
let download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
let fs = require('fs');
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/packages/vue-demo/vue-demo.zip`, Buffer.from(download.data));
- name: "Unzip artifact"
run: cd packages/vue-demo/ && mkdir -p dist && unzip vue-demo.zip -d dist
- uses: FirebaseExtended/action-hosting-deploy@v0
id: firebase
with:
repoToken: "${{ secrets.GITHUB_TOKEN }}"
firebaseServiceAccount: "${{ secrets.FIREBASE_SERVICE_ACCOUNT_OPENBRIDGE_DEMO }}"
projectId: openbridge-demo
entrypoint: "packages/vue-demo"
channelId: "${{ steps.store_pr_number_and_title.outputs.prNumber }}-${{ steps.store_pr_number_and_title.outputs.prTitle }}"
- name: "Comment on PR"
uses: actions/github-script@v8
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
var fs = require('fs');
var issue_number = ${{ steps.store_pr_number_and_title.outputs.prNumber }}
// check if comment already exists
var comments = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue_number
});
var commentExists = comments.data.some(comment => comment.body.includes('The demo can be viewed at'));
if (commentExists) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: comments.data.find(comment => comment.body.includes('The demo can be viewed at')).id,
body: 'The demo can be viewed at ${{ steps.firebase.outputs.details_url }}'
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue_number,
body: 'The demo can be viewed at ${{ steps.firebase.outputs.details_url }}'
});
}