HydePHP v2.x Development #1302
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deploy Documentation Preview | |
on: | |
pull_request: | |
branches: [ "master" ] | |
paths: | |
- 'docs/**' | |
- '.github/workflows/deploy-documentation-preview.yml' | |
jobs: | |
build-and-deploy-documentation-preview: | |
if: "! contains(github.event.pull_request.labels.*.name, 'pause-pages')" | |
environment: | |
name: pr-documentation-${{ github.event.pull_request.number }} | |
url: https://ci.hydephp.com/previews/develop/${{ github.event.pull_request.number }} | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Cache Composer packages | |
id: composer-cache | |
uses: actions/cache@v4 | |
with: | |
path: vendor | |
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} | |
restore-keys: | | |
${{ runner.os }}-php- | |
- name: Install Composer Dependencies | |
run: composer install --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist | |
- name: Download configuration | |
run: wget https://api.github.com/repos/hydephp/develop/zipball/gh-pages-config-dev-docs -O config.zip | |
- name: Unzip configuration | |
run: unzip config.zip -d temp | |
- name: Copy configuration to root | |
run: cp -r temp/hydephp-develop-*/* . | |
- name: Update configuration files | |
run: | | |
echo "output_directories:" >> hyde.yml | |
echo " Hyde\Pages\DocumentationPage: ''" >> hyde.yml | |
sed -i "s/'header' => env('SITE_NAME', 'HydePHP').' Docs'/'header' => 'PR #${{ github.event.pull_request.number }} - Docs'/g" config/docs.php | |
- name: Create component to add an information badge | |
run: | | |
mkdir -p resources/views/vendor/hyde/layouts | |
cp vendor/hyde/framework/resources/views/layouts/docs.blade.php resources/views/vendor/hyde/layouts/docs.blade.php | |
cat <<- HTML >> resources/views/vendor/hyde/layouts/docs.blade.php | |
<style>.font-bold{font-weight: 700;}.text-lg{font-size: 1.125rem; line-height: 1.75rem;}.mr-3{margin-right: 0.75rem rem ;}.mb-2{margin-bottom: 0.5rem;}.mr-3{margin-right: 0.75rem;}.text-gray-400{--tw-text-opacity: 1; color: rgb(156 163 175 / var(--tw-text-opacity));}.mx-0\.5{margin-left: 0.125rem; margin-right: 0.125rem;}</style> | |
<aside class="fixed bottom-4 right-4 z-50 hidden md:block"> | |
<div class="bg-white dark:bg-gray-800 rounded-lg shadow-lg p-4"> | |
<header class="flex flex-row nowrap items-center justify-between"> | |
<h3 class="text-lg font-bold mb-2 mr-3 flex">Documentation preview for <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> | |
<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> | |
</h3> | |
<small class="mb-2"> | |
<a href="${{ github.event.pull_request.html_url }}" class="dark:text-indigo-400 text-indigo-500 hover:text-indigo-600">Back to PR</a> | |
<span class="text-gray-400 mx-0.5">|</span> | |
<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> | |
</small> | |
</header> | |
<p class="prose dark:prose-invert"> | |
You are browsing the documentation for a user-contributed pull request.<br> | |
<small>Contents may be inaccurate or incomplete, and not representative of the organization.</small><br> | |
</p> | |
</div> | |
</aside> | |
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/highlightjs/[email protected]/build/styles/dark.min.css"> | |
<script src="https://cdn.jsdelivr.net/gh/highlightjs/[email protected]/build/highlight.min.js"></script> | |
<script>hljs.highlightAll();</script> | |
<style>.prose :where(pre):not(:where([class~=not-prose] *)) { background-color: #303030 } </style> | |
<style>pre code.hljs { padding: 0; }</style> | |
HTML | |
- name: Configure environment variables | |
run: | | |
echo 'SITE_NAME="HydePHP Documentation Preview"' >> .env | |
echo 'SITE_URL="https://ci.hydephp.com/previews/develop/${{ github.event.pull_request.number }}"' >> .env | |
- name: Move documentation files | |
run: rm -rf _docs && mv -f docs _docs | |
- name: Compile the static site | |
run: php hyde build | |
- name: Package the static site | |
run: zip -r site.zip _site | |
- name: Sign the artifact | |
run: | | |
echo '${{ secrets.CI_PREVIEW_SIGNING_RSA_PRIVATE_KEY }}' > private.pem | |
openssl dgst -sha256 -sign private.pem -out signature.bin site.zip | |
unlink private.pem | |
- name: Upload the artifact | |
run: | | |
repository="develop" | |
bearerToken="${{ secrets.CI_SERVER_TOKEN }}" | |
pullRequest="${{ github.event.pull_request.number }}" | |
signature="$(openssl base64 -in signature.bin)" | |
artifact="site.zip" | |
curl -X POST --fail-with-body \ | |
-H "Content-Type: multipart/form-data" \ | |
-H "Authorization: Bearer $bearerToken" \ | |
-F "repository=$repository" \ | |
-F "pullRequest=$pullRequest" \ | |
-F "artifact=@$artifact" \ | |
-F "signature=$signature" \ | |
https://ci.hydephp.com/api/deployment-previews |