-
Notifications
You must be signed in to change notification settings - Fork 73
84 lines (68 loc) · 2.41 KB
/
preview.yml
File metadata and controls
84 lines (68 loc) · 2.41 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
name: Preview
on:
pull_request:
jobs:
preview:
name: Run preview
runs-on: ubuntu-latest
env:
PREVIEW_HOSTNAME: ep-preview.click
steps:
- name: Checkout
uses: actions/checkout@v4
with:
sparse-checkout: |
build
- name: Set up SSH key
uses: webfactory/ssh-agent@v0.9.0
with:
ssh-private-key: ${{ secrets.DEPLOY_SSH_KEY }}
- name: Get current branch name
run: |
BRANCH_NAME=$(make safe_branch)
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
- 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
});
}