Skip to content

Commit

Permalink
Set up documentation preview (#1)
Browse files Browse the repository at this point in the history
* Set up docs preview with 'mo-doc'

* Simplify formatter CI

* Add 'docs' npm script

* Update CI

* Fix

* Run 'dfx cache install'

* Update github.io domain

* Add 'destination_dir'

* Fix

* Adjust preview message text

* Fix

* Update CI

* Swap out GH Pages deploy action

* Fix

* Simplify formatter CI

* Use Node 20.x

* Fix version conflict in package.json

* Misc

* Clarify preview text
  • Loading branch information
rvanasa authored Nov 27, 2024
1 parent 17503e5 commit d639538
Show file tree
Hide file tree
Showing 6 changed files with 175 additions and 131 deletions.
31 changes: 0 additions & 31 deletions .github/workflows/formatting.yml

This file was deleted.

83 changes: 83 additions & 0 deletions .github/workflows/gh-pages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: GitHub Pages

on:
push:
branches:
- main
pull_request:

jobs:
deploy:
strategy:
matrix:
node: [20]
concurrency: gh-pages-${{ github.ref }}
runs-on: ubuntu-20.04
env:
PR_PATH: pull/${{github.event.number}}
steps:
- name: Comment on PR
uses: hasura/comment-progress@v2.2.0
if: github.ref != 'refs/heads/main'
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
repository: ${{ github.repository }}
number: ${{ github.event.number }}
id: deploy-preview
message: "⏳ Loading documentation preview..."

- name: Set domain
run: echo "DOMAIN=dfinity.github.io" >> $GITHUB_ENV

- name: Checkout website repo
uses: actions/checkout@v2

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}

- name: Setup dfx
uses: dfinity/setup-dfx@main

- run: dfx cache install

- name: Set production base URL
run: echo "BASE_URL=https://${{ env.DOMAIN }}/${{ github.event.repository.name }}/" >> $GITHUB_ENV

- name: Build docs if main branch
if: github.ref == 'refs/heads/main'
run: npm run docs

- name: Deploy if main branch
uses: JamesIves/github-pages-deploy-action@v4
if: github.ref == 'refs/heads/main'
with:
token: ${{ secrets.GITHUB_TOKEN }}
folder: ./docs

- name: Set base URL for preview if PR
if: github.ref != 'refs/heads/main'
run: echo "BASE_URL=https://${{ env.DOMAIN }}/${{ github.event.repository.name }}/${{ env.PR_PATH}}/" >> $GITHUB_ENV

- name: Build PR preview website
if: github.ref != 'refs/heads/main'
run: npm run docs

- name: Deploy to PR preview
uses: JamesIves/github-pages-deploy-action@v4
if: github.ref != 'refs/heads/main'
with:
token: ${{ secrets.GITHUB_TOKEN }}
folder: ./docs
target-folder: ${{ env.PR_PATH }}

- name: Update comment
uses: hasura/comment-progress@v2.2.0
if: github.ref != 'refs/heads/main'
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
repository: ${{ github.repository }}
number: ${{ github.event.number }}
id: deploy-preview
message: "✨ Documentation preview for ${{ github.event.after }}:\n\n> **${{ env.BASE_URL }}**\n\n[Source code](https://github.com/${{ github.repository }}/tree/gh-pages/${{ env.PR_PATH }}/)"
31 changes: 31 additions & 0 deletions .github/workflows/pr-close.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Delete preview on PR close

# only trigger on pull request closed events
on:
pull_request:
types: [closed]

jobs:
delete_preview:
runs-on: ubuntu-20.04
env:
PR_PATH: pull/${{github.event.number}}
steps:
- name: Make empty dir
run: mkdir public

- name: Delete folder
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./docs
destination_dir: ${{ env.PR_PATH }}

- name: Comment on PR
uses: hasura/comment-progress@v2.2.0
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
repository: ${{ github.repository }}
number: ${{ github.event.number }}
id: deploy-preview
message: "PR closed. Deleted preview at https://github.com/${{ github.repository }}/tree/gh-pages/${{ env.PR_PATH }}/"
19 changes: 19 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Tests
on:
pull_request:

jobs:
format:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
matrix:
os: [ubuntu-22.04]
node: [20]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
- run: npm ci
- run: npm run format:check
137 changes: 39 additions & 98 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d639538

Please sign in to comment.