-
Notifications
You must be signed in to change notification settings - Fork 129
Expand file tree
/
Copy pathdocumentation-deploy-preview.yml
More file actions
126 lines (98 loc) · 4 KB
/
Copy pathdocumentation-deploy-preview.yml
File metadata and controls
126 lines (98 loc) · 4 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
name: documentation-deploy-preview
on:
workflow_run:
workflows: ["documentation"]
types: [completed]
concurrency:
group: gh-pages-deploy
cancel-in-progress: false
jobs:
prepare:
if: ${{ github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-24.04
name: Prepare deploy
outputs:
pr_number: ${{ steps.metadata.outputs.pr_number }}
build_environments: ${{ steps.metadata.outputs.build_environments }}
steps:
- name: Download PR metadata
uses: actions/download-artifact@v4
with:
name: pr-metadata
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Parse metadata
id: metadata
run: |
echo "pr_number=$(jq -r '.pr_number' pr-metadata.json)" >> $GITHUB_OUTPUT
echo "build_environments=$(jq -c '.build_environments' pr-metadata.json)" >> $GITHUB_OUTPUT
shell: bash
deploy-preview:
if: ${{ needs.prepare.outputs.build_environments != '[]' }}
needs: [prepare]
runs-on: ubuntu-24.04
name: Deploy preview to GitHub Pages
permissions:
contents: write
steps:
- name: Checkout sources
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
pattern: docusaurus-build-*
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Deploy to gh-pages
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git fetch origin gh-pages:gh-pages 2>/dev/null || true
DEPLOY_DIR=$(mktemp -d)
if git show-ref --verify --quiet refs/heads/gh-pages; then
git worktree add "$DEPLOY_DIR" gh-pages
else
git worktree add --orphan -b gh-pages "$DEPLOY_DIR"
fi
touch "$DEPLOY_DIR/.nojekyll"
PR_NUMBER="${{ needs.prepare.outputs.pr_number }}"
for env in $(echo '${{ needs.prepare.outputs.build_environments }}' | jq -r '.[]'); do
rm -rf "$DEPLOY_DIR/previews/pr-${PR_NUMBER}/${env}"
mkdir -p "$DEPLOY_DIR/previews/pr-${PR_NUMBER}/${env}"
cp -r "docusaurus-build-${env}/." "$DEPLOY_DIR/previews/pr-${PR_NUMBER}/${env}/"
done
cd "$DEPLOY_DIR"
git add .
git diff --cached --quiet || git commit -m "deploy: preview for PR #${PR_NUMBER}"
git push origin gh-pages
shell: bash
comment-preview:
if: ${{ always() && needs.deploy-preview.result == 'success' }}
needs: [prepare, deploy-preview]
runs-on: ubuntu-24.04
name: Add comment for preview
permissions:
pull-requests: write
steps:
- name: Prepare preview URLs
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
with:
script: |
const preview_urls = ${{ needs.prepare.outputs.build_environments }}.map((environment) => {
return `:rocket: Deployed preview to https://centreon.github.io/centreon-documentation/previews/pr-${{ needs.prepare.outputs.pr_number }}/${environment}/`;
});
core.exportVariable('datetime', new Date().toUTCString());
core.exportVariable('preview_urls', preview_urls.join('\n'));
- name: Leave a comment after deployment
uses: marocchino/sticky-pull-request-comment@773744901bac0e8cbb5a0dc842800d45e9b2b405 # v2.9.4
with:
header: pr-preview
number: ${{ needs.prepare.outputs.pr_number }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
message: "\
**PR Previews**
:---:
${{ env.preview_urls }}
at ${{ env.datetime }}
> **_NOTE:_** Previews are deleted after 30 days of inactivity
"