Skip to content

Commit 19937f6

Browse files
committed
ci: Support docs preview
1 parent b0117ef commit 19937f6

File tree

2 files changed

+116
-45
lines changed

2 files changed

+116
-45
lines changed

.github/workflows/deploy-site.yml

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
name: ChipFlow Libraray Github Pages
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
types: [opened, synchronize, reopened, closed]
9+
branches:
10+
- main
11+
permissions:
12+
contents: read
13+
pages: write
14+
id-token: write
15+
16+
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
17+
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
18+
concurrency:
19+
group: "pages"
20+
cancel-in-progress: false
21+
22+
jobs:
23+
build_and_deploy_docs:
24+
runs-on: ubuntu-latest
25+
name: Build and Deploy Docs
26+
env:
27+
PR_PATH: pull/${{github.event.number}}
28+
steps:
29+
- name: Delete old doc PR comment
30+
if: ${{ github.event_name == 'pull_request' }}
31+
uses: hasura/[email protected]
32+
with:
33+
github-token: ${{ secrets.GITHUB_TOKEN }}
34+
repository: ${{ github.repository }}
35+
number: ${{ github.event.number }}
36+
id: deploy-preview
37+
delete: true
38+
39+
- name: Comment on PR
40+
if: ${{ github.event_name == 'pull_request' }}
41+
uses: hasura/[email protected]
42+
with:
43+
github-token: ${{ secrets.GITHUB_TOKEN }}
44+
repository: ${{ github.repository }}
45+
number: ${{ github.event.number }}
46+
id: deploy-preview
47+
message: "Starting deployment of preview ⏳..."
48+
recreate: true
49+
50+
- name: Get Site URL
51+
env:
52+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
53+
run: |
54+
url=$(gh api "repos/$GITHUB_REPOSITORY/pages" --jq '.html_url' | sed -e 's/[^/]*\/\/\([^@]*@\)\?\([^:/]*\).*/\2/')
55+
echo "DOMAIN=$url" >> $GITHUB_ENV
56+
57+
- name: Set production base URL
58+
if: ${{ github.ref == 'refs/heads/main' }}
59+
run: echo "BASE_URL=https://${{ env.DOMAIN }}/" >> $GITHUB_ENV
60+
61+
- name: Set base URL for preview if PR
62+
if: ${{ github.event_name == 'pull_request' }}
63+
run: echo "BASE_URL=https://${{ env.DOMAIN }}/${{ env.PR_PATH}}/" >> $GITHUB_ENV
64+
65+
- uses: actions/checkout@v2
66+
with:
67+
submodules: true
68+
69+
- uses: actions/checkout@v4
70+
- name: Setup PDM
71+
uses: pdm-project/setup-pdm@v4
72+
with:
73+
python-version: 3.12
74+
cache: true
75+
76+
- name: Install dependencies
77+
run: pdm install
78+
79+
- name: Build docs
80+
run: pdm docs
81+
82+
- name: Setup Pages
83+
uses: actions/configure-pages@v5
84+
85+
- name: Upload artifacts
86+
uses: actions/upload-artifact@v3
87+
with:
88+
name: html-docs
89+
path: docs/_build
90+
91+
- name: Deploy if this is the `main` branch
92+
uses: peaceiris/actions-gh-pages@v3
93+
if: ${{ github.ref == 'refs/heads/main' }}
94+
with:
95+
github_token: ${{ secrets.GITHUB_TOKEN }}
96+
publish_dir: site
97+
cname: ${{ env.DOMAIN }}
98+
99+
- name: Deploy to PR preview
100+
if: ${{ github.event_name == 'pull_request' }}
101+
uses: peaceiris/actions-gh-pages@v3
102+
with:
103+
github_token: ${{ secrets.GITHUB_TOKEN }}
104+
publish_dir: site
105+
destination_dir: ${{ env.PR_PATH }}
106+
107+
- name: Update comment
108+
if: ${{ github.event_name == 'pull_request' }}
109+
uses: hasura/[email protected]
110+
with:
111+
github-token: ${{ secrets.GITHUB_TOKEN }}
112+
repository: ${{ github.repository }}
113+
number: ${{ github.event.number }}
114+
id: deploy-preview
115+
message: "A preview of ${{ github.event.after }} is uploaded and can be seen here:\n\n ✨ ${{ env.BASE_URL }} ✨\n\nChanges may take a few minutes to propagate. Since this is a preview of production, content with `draft: true` will not be rendered. The source is here: https://github.com/${{ github.repository }}/tree/gh-pages/${{ env.PR_PATH }}/"
116+
recreate: true

.github/workflows/main.yaml

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -40,48 +40,3 @@ jobs:
4040
- name: Check source code licenses
4141
run: |
4242
docker run --platform=linux/amd64 -v ${PWD}:/src ghcr.io/google/addlicense -v -check -l BSD-2-Clause -c "ChipFlow" -s=only -ignore **/__init__.py **/*.py
43-
44-
build-docs:
45-
needs: test
46-
runs-on: ubuntu-22.04
47-
steps:
48-
- name: Checkout
49-
uses: actions/checkout@v4
50-
- name: Set up PDM
51-
uses: pdm-project/setup-pdm@v4
52-
with:
53-
python-version: 3.9
54-
- name: Install deps
55-
run: pdm install
56-
- name: Build docs
57-
run: pdm run document
58-
- name: Upload docs artifact
59-
uses: actions/upload-artifact@v4
60-
with:
61-
name: docs
62-
path: docs/_build
63-
64-
publish-docs:
65-
needs: build-docs
66-
if: ${{ github.repository == 'chipflow/chipflow-lib' }}
67-
runs-on: ubuntu-latest
68-
steps:
69-
- name: Checkout
70-
uses: actions/checkout@v4
71-
with:
72-
fetch-depth: 0
73-
- name: Download docs artifact
74-
uses: actions/download-artifact@v4
75-
with:
76-
name: docs
77-
path: docs/
78-
- name: Publish "latest" docs
79-
if: ${{ github.event_name == 'push' && github.event.ref == 'refs/heads/main' }}
80-
uses: JamesIves/github-pages-deploy-action@releases/v4
81-
with:
82-
repository-name: chipflow/chipflow.github.io
83-
ssh-key: ${{ secrets.PAGES_DEPLOY_KEY }}
84-
branch: main
85-
folder: docs/
86-
target-folder: chipflow-lib/latest/
87-

0 commit comments

Comments
 (0)