Skip to content

Commit 5fbcc52

Browse files
authored
Merge pull request #966 from hydephp/create-workflow-to-deploy-documentation-previews-for-pull-requests-making-changes-to-the-docs
Create workflow to deploy documentation previews for pull requests making changes to the docs
2 parents d8f95c9 + 45ce708 commit 5fbcc52

File tree

1 file changed

+127
-0
lines changed

1 file changed

+127
-0
lines changed
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
name: Deploy Documentation Preview
2+
3+
on:
4+
pull_request:
5+
branches: [ "master" ]
6+
paths:
7+
- 'docs/**'
8+
9+
jobs:
10+
11+
build-documentation-preview:
12+
environment:
13+
name: pr-documentation-${{ github.event.pull_request.number }}
14+
url: https://hydephp.github.io/develop/pr-${{ github.event.pull_request.number }}/dev-docs-preview
15+
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- uses: actions/checkout@v3
20+
- uses: shivammathur/setup-php@16011a795d747d5f45038f96371c3b98aec5669d
21+
with:
22+
php-version: "8.1"
23+
24+
- name: Cache Composer packages
25+
id: composer-cache
26+
uses: actions/cache@v3
27+
with:
28+
path: vendor
29+
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
30+
restore-keys: |
31+
${{ runner.os }}-php-
32+
33+
- name: Install Composer Dependencies
34+
run: composer install --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
35+
36+
- name: Download configuration
37+
run: wget https://api.github.com/repos/hydephp/develop/zipball/gh-pages-config-dev-docs -O config.zip
38+
39+
- name: Unzip configuration
40+
run: unzip config.zip -d temp
41+
42+
- name: Copy configuration to root
43+
run: cp -r temp/hydephp-develop-*/* .
44+
45+
- name: Update configuration files
46+
run: |
47+
sed -i "s/'output_directory' => 'dev-docs'/'output_directory' => 'dev-docs-preview'/g" config/docs.php
48+
sed -i "s/'header_title' => config('site.name', 'HydePHP').' Docs'/'header_title' => 'PR #${{ github.event.pull_request.number }} - Docs'/g" config/docs.php
49+
50+
- name: Remove published article component
51+
run: rm resources/views/vendor/hyde/components/docs/documentation-article.blade.php
52+
53+
- name: Create component to add an information badge
54+
# TODO 1. Extract to component. 2. Add feature to hide card which is stored in local session storage for the duration of the visit (so it's reset on next PR page visit)
55+
run: |
56+
mkdir -p resources/views/vendor/hyde/layouts
57+
cp vendor/hyde/framework/resources/views/layouts/docs.blade.php resources/views/vendor/hyde/layouts/docs.blade.php
58+
cat <<- HTML >> resources/views/vendor/hyde/layouts/docs.blade.php
59+
<style>.fixed{position:fixed}.bottom-4{bottom:1rem}.right-4{right:1rem}.z-50{z-index:50}.mx-0{margin-left:0;margin-right:0}.mx-0\.5{margin-left:.125rem;margin-right:.125rem}.mx-4{margin-left:1rem;margin-right:1rem}.mx-8{margin-left:2rem;margin-right:2rem}.mb-2{margin-bottom:.5rem}.mr-3{margin-right:.75rem}.flex{display:flex}.hidden{display:none}.flex-row{flex-direction:row}.items-center{align-items:center}.justify-between{justify-content:space-between}.rounded-lg{border-radius:.5rem}.bg-white{--tw-bg-opacity:1;background-color:rgb(255 255 255 / var(--tw-bg-opacity))}.p-4{padding:1rem}.text-center{text-align:center}.text-right{text-align:right}.text-lg{font-size:1.125rem;line-height:1.75rem}.font-bold{font-weight:700}.text-gray-400{--tw-text-opacity:1;color:rgb(156 163 175 / var(--tw-text-opacity))}.text-indigo-500{--tw-text-opacity:1;color:rgb(89 86 235 / var(--tw-text-opacity))}.opacity-75{opacity:.75}.shadow-lg{--tw-shadow:0 10px 15px -3px rgb(0 0 0 / 0.1),0 4px 6px -4px rgb(0 0 0 / 0.1);--tw-shadow-colored:0 10px 15px -3px var(--tw-shadow-color),0 4px 6px -4px var(--tw-shadow-color);box-shadow:var(--tw-ring-offset-shadow,0 0 #0000),var(--tw-ring-shadow,0 0 #0000),var(--tw-shadow)}.dark .dark\:prose-invert{--tw-prose-body:var(--tw-prose-invert-body);--tw-prose-headings:var(--tw-prose-invert-headings);--tw-prose-lead:var(--tw-prose-invert-lead);--tw-prose-links:var(--tw-prose-invert-links);--tw-prose-bold:var(--tw-prose-invert-bold);--tw-prose-counters:var(--tw-prose-invert-counters);--tw-prose-bullets:var(--tw-prose-invert-bullets);--tw-prose-hr:var(--tw-prose-invert-hr);--tw-prose-quotes:var(--tw-prose-invert-quotes);--tw-prose-quote-borders:var(--tw-prose-invert-quote-borders);--tw-prose-captions:var(--tw-prose-invert-captions);--tw-prose-code:var(--tw-prose-invert-code);--tw-prose-pre-code:var(--tw-prose-invert-pre-code);--tw-prose-pre-bg:var(--tw-prose-invert-pre-bg);--tw-prose-th-borders:var(--tw-prose-invert-th-borders);--tw-prose-td-borders:var(--tw-prose-invert-td-borders)}.dark .dark\:prose-invert :where(a):not(:where([class~=not-prose]*)){color:#818cf8}.dark .dark\:prose-invert :where(a):not(:where([class~=not-prose]*)):hover{color:#6366f1}.hover\:text-indigo-600:hover{--tw-text-opacity:1;color:rgb(79 70 229 / var(--tw-text-opacity))}.dark .dark\:bg-gray-800{--tw-bg-opacity:1;background-color:rgb(31 41 55 / var(--tw-bg-opacity))}.dark .dark\:text-indigo-400{--tw-text-opacity:1;color:rgb(129 140 248 / var(--tw-text-opacity))}@media (min-width:768px){.md\:block{display:block}}</style>
60+
<aside class="fixed bottom-4 right-4 z-50 hidden md:block">
61+
<div class="bg-white dark:bg-gray-800 rounded-lg shadow-lg p-4">
62+
<header class="flex flex-row nowrap items-center justify-between">
63+
<h3 class="text-lg font-bold mb-2 mr-3 flex">Documentation preview for&nbsp; <a href="${{ github.event.pull_request.html_url }}" class="dark:text-indigo-400 text-indigo-500 hover:text-indigo-600">PR #${{ github.event.pull_request.number }}</a> &nbsp;
64+
<small class="opacity-75">(#<a href="https://github.com/hydephp/develop/commit/${{ github.event.pull_request.head.sha }}"><span style=" display: inline-flex; font-family: monospace; width: 7ch; white-space: nowrap; overflow: hidden; text-overflow: clip;">${{ github.event.pull_request.head.sha }}</span></a>)</small>
65+
</h3>
66+
<small class="mb-2">
67+
<a href="${{ github.event.pull_request.html_url }}" class="dark:text-indigo-400 text-indigo-500 hover:text-indigo-600">Back to PR</a>
68+
<span class="text-gray-400 mx-0.5">|</span>
69+
<a href="${{ github.event.pull_request.html_url }}/files?file-filters%5B%5D=.md" class="dark:text-indigo-400 text-indigo-500 hover:text-indigo-600">View Diff</a>
70+
</small>
71+
</header>
72+
<p class="prose dark:prose-invert">
73+
You are browsing the documentation for a user-contributed pull request.<br>
74+
<small>Contents may be inaccurate or incomplete, and not representative of the organization.</small><br>
75+
</p>
76+
</div>
77+
</aside>
78+
79+
<!-- Hotpatch for https://github.com/hydephp/develop/issues/968 -->
80+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/hydephp/develop@master/_media/app.css">
81+
HTML
82+
83+
- name: Configure environment variables
84+
run: |
85+
echo 'SITE_NAME="HydePHP Documentation Preview"' >> .env
86+
echo 'SITE_URL="https://hydephp.github.io/develop/pr-${{ github.event.pull_request.number }}/dev-docs-preview"' >> .env
87+
88+
- name: Move documentation files
89+
run: rm -rf _docs && mv -f docs _docs
90+
91+
- name: Compile the static site
92+
run: php hyde build
93+
94+
- name: Upload artifacts
95+
uses: actions/upload-artifact@v1
96+
with:
97+
name: 'preview-docs'
98+
path: '_site/dev-docs-preview'
99+
100+
101+
upload-generated-site:
102+
103+
runs-on: ubuntu-latest
104+
needs:
105+
- build-documentation-preview
106+
107+
steps:
108+
- uses: actions/checkout@v3
109+
with:
110+
ref: 'gh-pages'
111+
112+
- name: Reset output directories
113+
run: |
114+
rm -rf pr-${{ github.event.pull_request.number }}/dev-docs-preview
115+
mkdir -p pr-${{ github.event.pull_request.number }}/dev-docs-preview
116+
117+
- name: Download documentation artifact
118+
uses: actions/download-artifact@v3
119+
with:
120+
name: preview-docs
121+
path: pr-${{ github.event.pull_request.number }}/dev-docs-preview
122+
123+
- name: Commit changes
124+
uses: EndBug/add-and-commit@v9
125+
with:
126+
add: 'pr-${{ github.event.pull_request.number }}/dev-docs-preview'
127+
message: 'Upload documentation preview for PR #${{ github.event.pull_request.number }}'

0 commit comments

Comments
 (0)