Skip to content

Commit 76a1399

Browse files
committed
ci: Support docs preview
1 parent b0117ef commit 76a1399

File tree

2 files changed

+118
-45
lines changed

2 files changed

+118
-45
lines changed

.github/workflows/deploy-site.yml

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