-
Notifications
You must be signed in to change notification settings - Fork 7
104 lines (90 loc) · 3.54 KB
/
Copy pathpr_deploy.yml
File metadata and controls
104 lines (90 loc) · 3.54 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
---
name: PR Deploy
on:
workflow_run:
workflows:
- "PR Build"
types:
- completed
concurrency:
group: preview-${{ github.ref }}
cancel-in-progress: true
jobs:
deploy-site-preview:
runs-on: ubuntu-latest
name: Deploy site preview
steps:
- name: Checkout sources
uses: actions/checkout@v3
with:
ssh-key: ${{ secrets.DEPLOY_KEY }}
ref: gh-pages
- name: Download site artifacts
uses: actions/github-script@v6.3.3
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 == "site-artifacts"
})[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}/site-artifacts.zip`, Buffer.from(download.data));
- name: Unzip site artifacts
run: unzip site-artifacts.zip
- name: Grab PR info
id: pr-info
run: |
number=$(cat pr_number)
echo "number=$number" >> $GITHUB_OUTPUT
- name: Configure git
run: |
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor }}@users.noreply.github.com"
- name: Create preview target
run: |
mkdir -p pr-previews/pr-${{ steps.pr-info.outputs.number }}
cp -rf _site/* pr-previews/pr-${{ steps.pr-info.outputs.number }}
- name: Remove robots.txt from preview
run: rm pr-previews/pr-${{ steps.pr-info.outputs.number }}/robots.txt
- name: Count changed
id: git_status
run: |
changedCount=$(git status pr-previews/pr-${{ steps.pr-info.outputs.number }} --porcelain=v1 --short --untracked-files=all | wc -l)
echo "changedCount=$changedCount" >> "$GITHUB_OUTPUT"
- name: Push preview target
if: steps.git_status.outputs.changedCount > 0
run: |
git add pr-previews/pr-${{ steps.pr-info.outputs.number }}
git commit -m "docs: deployed preview for pr #${{ steps.pr-info.outputs.number }}"
git push origin gh-pages
- name: Create a preview link
if: steps.git_status.outputs.changedCount > 0
id: pr_preview
run: |
cnameFile="CNAME"
if [ -f "$cnameFile" ]; then
cname=$(<$cnameFile)
echo "link=https://$cname/pr-previews/pr-${{ steps.pr-info.outputs.number }}/" >> "$GITHUB_OUTPUT"
else
owner="${{ github.event.repository.owner.login }}"
echo "link=https://$owner.github.io/pr-previews/pr-${{ steps.pr-info.outputs.number }}/" >> "$GITHUB_OUTPUT"
fi
- name: Comment with the preview link
if: steps.git_status.outputs.changedCount > 0
uses: marocchino/sticky-pull-request-comment@v2.2.0
with:
header: site-preview
number: ${{ steps.pr-info.outputs.number }}
message: |
:rocket: Deployed site preview ${{ steps.pr_preview.outputs.link }}
* will be up and ready in a couple of minutes.