forked from trustification/trustification
-
Notifications
You must be signed in to change notification settings - Fork 1
88 lines (83 loc) · 3.19 KB
/
pr-preview-deploy.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
name: PR Preview Deploy
on:
workflow_run:
workflows: ["PR Preview Build"]
types:
- completed
jobs:
deploy-pr-preview:
runs-on: ubuntu-latest
if: >
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success'
steps:
- name: Download dist
uses: actions/github-script@v6
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 == "dist"
})[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}}/dist.zip', Buffer.from(download.data));
- name: Download PR number
uses: actions/github-script@v6
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 dist.zip -d dist/
- run: unzip pr.zip
- name: Generate issue_number
uses: actions/github-script@v6
id: issue_number
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
var fs = require('fs');
return Number(fs.readFileSync('./NR'));
result-encoding: string
- name: Generate Surge URL
uses: actions/github-script@v6
id: surge-url
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const issue_number = ${{steps.issue_number.outputs.result}};
return `trustification-spog-pr-${issue_number}-preview.surge.sh`;
result-encoding: string
- name: Install Surge
run: npm install -g surge
- name: Deploy to Surge
run: surge ./dist/ "${{steps.surge-url.outputs.result}}" --token ${{ secrets.SURGE_TOKEN }}
- name: Post URL as PR comment
uses: mshick/add-pr-comment@v2
with:
message: "🚀 Deployed Preview: https://${{steps.surge-url.outputs.result}} ✨"
repo-token: ${{ secrets.PREVIEW_BOT_TOKEN }}
issue: ${{steps.issue_number.outputs.result}}