-
Notifications
You must be signed in to change notification settings - Fork 63
102 lines (81 loc) · 2.92 KB
/
preview.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
name: Preview
on:
pull_request:
jobs:
preview:
name: Run preview
runs-on: ubuntu-latest
env:
PREVIEW_HOSTNAME: ep-preview.click
GITHUB_BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set timestamp for build/deploy
run: echo "TIMESTAMP=$(date +%Y%m%d%H%M%S)" >> $GITHUB_ENV
- name: Set up pnpm
uses: pnpm/action-setup@v4
with:
run_install: false
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: "pnpm"
- name: Install dependencies
run: make install
- name: Build the website
run: make build
- name: Set up SSH key
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.DEPLOY_SSH_KEY }}
- name: Get current branch name
run: |
BRANCH_NAME=$(make safe_branch BRANCH=$GITHUB_BRANCH_NAME)
echo "BRANCH_NAME=${BRANCH_NAME}" >> $GITHUB_ENV
- name: ssh keyscan
run: ssh-keyscan "static.europython.eu" > ~/.ssh/known_hosts
- name: Upload preview
run: make preview BRANCH=$GITHUB_BRANCH_NAME
- name: Update PR Comment
uses: actions/github-script@v6
if: github.event_name == 'pull_request'
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
console.log("Hello world!");
const pr_id = ${{ github.event.number }};
console.log("PR Id %d", pr_id);
comments = await github.paginate(github.rest.issues.listComments, {
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: Number(pr_id)
})
const preview_identifier = "# Preview available"
let comment_id = null;
comments.forEach(comment => {
if(comment.body.indexOf(preview_identifier) >= 0) {
comment_id = comment.id;
}
});
const branch_name = process.env.BRANCH_NAME;
const url = "https://" + branch_name + "." + process.env.PREVIEW_HOSTNAME;
const timestamp = new Date().toISOString();
const header = "\n|Key|Value|\n|---|---|\n"
const body = preview_identifier + header + "|url|" + url + "|\n|last update|" + timestamp + "|";
if(comment_id > 0) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: comment_id,
body: body
});
} else {
await github.rest.issues.createComment({
issue_number: Number(pr_id),
owner: context.repo.owner,
repo: context.repo.repo,
body: body
});
}