-
Notifications
You must be signed in to change notification settings - Fork 5
49 lines (45 loc) · 2.1 KB
/
documentation-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
name: Documentation Preview Generator
on:
workflow_run:
workflows: [Documentation Preview Request]
types:
- completed
env:
PREVIEW_PUBLISH_USERNAME: crc-org
PREVIEW_PUBLISH_REPOSITORY: crc-docs-gh-action-generated-preview
PREVIEW_PUBLISH_BRANCH: gh-pages
PREVIEW_PUBLISH_TOKEN: ${{ secrets.PREVIEW_PUBLISH_TOKEN }}
jobs:
documentation-preview:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-24.04
steps:
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: documentation
path: ./artifact
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ github.token }}
- name: Extract Pull Request ID from artifact
run: |
echo "PR_NUMBER=$(jq '.event.pull_request.number' ./artifact/github_context.json)" >> $GITHUB_ENV
echo "PR_SHA=$(jq -r '.event.pull_request.head.sha' ./artifact/github_context.json | cut -c 1-7)" >> $GITHUB_ENV
rm ./artifact/github_context.json
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v4
with:
personal_token: ${{ env.PREVIEW_PUBLISH_TOKEN }}
external_repository: ${{ env.PREVIEW_PUBLISH_USERNAME }}/${{ env.PREVIEW_PUBLISH_REPOSITORY }}
publish_dir: ./artifact
publish_branch: ${{ env.PREVIEW_PUBLISH_BRANCH }}
destination_dir: preview/pr/${{ env.PR_NUMBER }}/${{ env.PR_SHA}}
commit_message: "deploy documentation preview to GitHub Pages for PR #${{ env.PR_NUMBER }}"
- name: Comment PR with preview link
run: |
PREVIEW_URL="https://${PREVIEW_PUBLISH_USERNAME}.github.io/${PREVIEW_PUBLISH_REPOSITORY}/preview/pr/${PR_NUMBER}/${PR_SHA}/index.html"
curl -s --request POST \
--url "https://api.github.com/repos/${{ github.repository }}/issues/${PR_NUMBER}/comments" \
--header "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
--header "Content-Type: application/json" \
--data "{\"body\":\"🚀 Documentation preview: ${PREVIEW_URL}\"}"