-
Notifications
You must be signed in to change notification settings - Fork 4
94 lines (84 loc) · 3.16 KB
/
Copy pathpr-preview-publish.yml
File metadata and controls
94 lines (84 loc) · 3.16 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
name: Publish CA PR preview
on:
workflow_run:
workflows: [Build CA PR preview]
types: [completed]
permissions:
actions: read
contents: write
issues: write
concurrency:
group: ca-pr-preview-publish
jobs:
publish:
if: >-
github.event.workflow_run.conclusion == 'success' &&
github.event.workflow_run.event == 'pull_request'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
with:
ref: pr-previews
- uses: actions/download-artifact@v8
with:
name: ca-pr-preview
path: artifact
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Publish stable PR installer URL
id: publish
env:
HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
run: |
PR_NUMBER="$(jq -r '.pr' artifact/preview.json)"
ARTIFACT_SHA="$(jq -r '.sha' artifact/preview.json)"
[[ "$PR_NUMBER" =~ ^[0-9]+$ ]]
test "$ARTIFACT_SHA" = "$HEAD_SHA"
echo "pr_number=$PR_NUMBER" >> "$GITHUB_OUTPUT"
rm -rf "pr/$PR_NUMBER"
mkdir -p "pr/$PR_NUMBER"
cp artifact/* "pr/$PR_NUMBER/"
git config user.name github-actions[bot]
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
git add "pr/$PR_NUMBER"
git diff --cached --quiet && exit 0
git commit -m "preview: publish PR #$PR_NUMBER at ${HEAD_SHA:0:7}"
git push origin pr-previews
- name: Add installer link to pull request
uses: actions/github-script@v9
env:
PR_NUMBER: ${{ steps.publish.outputs.pr_number }}
with:
script: |
const issueNumber = Number(process.env.PR_NUMBER)
if (!Number.isInteger(issueNumber) || issueNumber < 1) {
throw new Error(`Invalid pull request number: ${process.env.PR_NUMBER}`)
}
const marker = '<!-- ca-pr-preview -->'
const installerUrl = `https://raw.githubusercontent.com/${context.repo.owner}/${context.repo.repo}/pr-previews/pr/${issueNumber}/community.applications.plg`
const body = `${marker}
### Community Applications preview
Install this PR build on a test server:
\`${installerUrl}\`
This is an unreleased test build. The same URL updates when new commits are pushed to this pull request.`
const comments = await github.paginate(github.rest.issues.listComments, {
...context.repo,
issue_number: issueNumber,
per_page: 100
})
const existing = comments.find(comment =>
comment.user?.type === 'Bot' && comment.body?.includes(marker)
)
if (existing) {
await github.rest.issues.updateComment({
...context.repo,
comment_id: existing.id,
body
})
} else {
await github.rest.issues.createComment({
...context.repo,
issue_number: issueNumber,
body
})
}