Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Internal: Update monorepo documentation previews to use the new server #1543

Merged
merged 15 commits into from
Feb 10, 2024
70 changes: 31 additions & 39 deletions .github/workflows/deploy-documentation-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,27 @@ on:
branches: [ "master" ]
paths:
- 'docs/**'
- '.github/workflows/deploy-documentation-preview.yml'

jobs:

build-documentation-preview:
build-and-deploy-documentation-preview:
# We could add a check to only rerun if docs have changed since last run on the PR
# But this would require a state storage, and the current version is good enough.
if: "! contains(github.event.pull_request.labels.*.name, 'pause-pages')"

environment:
name: pr-documentation-${{ github.event.pull_request.number }}
url: https://hydephp.github.io/develop/pr-${{ github.event.pull_request.number }}/dev-docs-preview
url: https://ci.hydephp.com/previews/develop/${{ github.event.pull_request.number }}

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: shivammathur/setup-php@v2
with:
php-version: "8.1"
# Disabled as it should not be necessary, and it takes a long time to run
# - uses: shivammathur/setup-php@v2
# with:
# php-version: "8.1"

- name: Cache Composer packages
id: composer-cache
Expand All @@ -49,7 +51,7 @@ jobs:
- name: Update configuration files
run: |
echo "output_directories:" >> hyde.yml
echo " Hyde\Pages\DocumentationPage: dev-docs-preview" >> 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: Remove published article component
Expand Down Expand Up @@ -87,46 +89,36 @@ jobs:
- name: Configure environment variables
run: |
echo 'SITE_NAME="HydePHP Documentation Preview"' >> .env
echo 'SITE_URL="https://hydephp.github.io/develop/pr-${{ github.event.pull_request.number }}/dev-docs-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: Upload artifacts
uses: actions/upload-artifact@v1
with:
name: 'preview-docs'
path: '_site/dev-docs-preview'


upload-generated-site:

runs-on: ubuntu-latest
needs:
- build-documentation-preview

steps:
- uses: actions/checkout@v3
with:
ref: 'gh-pages'
- name: Package the static site
run: zip -r site.zip _site

- name: Reset output directories
- name: Sign the artifact
run: |
rm -rf pr-${{ github.event.pull_request.number }}/dev-docs-preview
mkdir -p pr-${{ github.event.pull_request.number }}/dev-docs-preview
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: Download documentation artifact
uses: actions/download-artifact@v3
with:
name: preview-docs
path: pr-${{ github.event.pull_request.number }}/dev-docs-preview

- name: Commit changes
uses: EndBug/add-and-commit@v9
with:
pull: 'origin gh-pages'
add: 'pr-${{ github.event.pull_request.number }}/dev-docs-preview'
message: 'Upload documentation preview for PR ${{ github.event.pull_request.number }}'
- 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
Loading