Skip to content

Commit d7f9f36

Browse files
ci(docs): Revamp documentation building, deployment and cleanup (#292)
* Add build-deploy-docs.yml to build the documentation and deploy it to the right folder(s) of TorchJD/documentation repo whenever a pull request is opened, synchronized or reopened, whenever a push is made to the main branch, and whenever a version tag is pushed. * Add cleanup-pr-docs to delete the documentation contained in a folder of TorchJD/documentation whenever the corresponding PR is closed, and to push the changes to the main branch of TorchJD/documentation. --------- Co-authored-by: Valérian Rey <31951177+ValerianRey@users.noreply.github.com> Co-authored-by: Valérian Rey <valerian.rey@gmail.com>
1 parent 3f78d6d commit d7f9f36

File tree

2 files changed

+100
-0
lines changed

2 files changed

+100
-0
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: Build and Deploy Documentation
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
tags:
7+
- 'v[0-9]*.[0-9]*.[0-9]*'
8+
pull_request:
9+
types: [opened, synchronize, reopened]
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
permissions:
15+
contents: write
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@v4
19+
20+
- name: Setup PDM
21+
uses: pdm-project/setup-pdm@v4
22+
with:
23+
python-version: '3.13'
24+
25+
- name: Install dependencies (default & doc)
26+
run: pdm install --group doc --frozen-lockfile
27+
28+
- name: Build Documentation
29+
working-directory: docs
30+
run: pdm run make dirhtml
31+
32+
- name: Determine deployment folder
33+
id: deploy_folder
34+
run: |
35+
echo "Determining deployment folder..."
36+
if [ "${{ github.event_name }}" = "pull_request" ]; then
37+
echo "Deploying to target pr/${{ github.event.number }}"
38+
echo "DEPLOY_DIR=pr/${{ github.event.number }}" >> $GITHUB_OUTPUT
39+
elif [[ "${{ github.ref }}" == refs/tags/* ]]; then
40+
echo "Deploying to target ${{ github.ref_name }}"
41+
echo "DEPLOY_DIR=${{ github.ref_name }}" >> $GITHUB_OUTPUT
42+
else
43+
echo "Deploying to target main"
44+
echo "DEPLOY_DIR=main" >> $GITHUB_OUTPUT
45+
fi
46+
47+
- name: Deploy to DEPLOY_DIR of TorchJD/documentation
48+
uses: peaceiris/actions-gh-pages@v4
49+
with:
50+
deploy_key: ${{ secrets.DOCUMENTATION_DEPLOY_KEY }}
51+
publish_dir: docs/build/dirhtml
52+
destination_dir: ${{ steps.deploy_folder.outputs.DEPLOY_DIR }}
53+
external_repository: TorchJD/documentation
54+
publish_branch: main
55+
56+
- name: Deploy to stable of TorchJD/documentation
57+
if: startsWith(github.ref, 'refs/tags/')
58+
uses: peaceiris/actions-gh-pages@v4
59+
with:
60+
deploy_key: ${{ secrets.DOCUMENTATION_DEPLOY_KEY }}
61+
publish_dir: docs/build/dirhtml
62+
destination_dir: stable
63+
external_repository: TorchJD/documentation
64+
publish_branch: main
65+
66+
- name: Add documentation link to summary
67+
run: |
68+
echo "### 📄 [View Deployed Documentation](https://torchjd.github.io/documentation/${{ steps.deploy_folder.outputs.DEPLOY_DIR }})" >> $GITHUB_STEP_SUMMARY
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Cleanup PR Documentation
2+
3+
on:
4+
pull_request:
5+
types: [closed]
6+
7+
jobs:
8+
cleanup:
9+
runs-on: ubuntu-latest
10+
permissions:
11+
contents: write
12+
steps:
13+
- name: Checkout gh-pages branch
14+
uses: actions/checkout@v4
15+
with:
16+
repository: TorchJD/documentation
17+
ref: main
18+
ssh-key: ${{ secrets.DOCUMENTATION_DEPLOY_KEY }}
19+
20+
- name: Remove PR documentation for closed PR
21+
run: |
22+
PR_NUMBER="${{ github.event.number }}"
23+
echo "Removing documentation for PR #${PR_NUMBER}"
24+
rm -rf pr/${PR_NUMBER}
25+
26+
- name: Commit and push cleanup
27+
run: |
28+
git config user.name "github-actions"
29+
git config user.email "github-actions@github.com"
30+
git add .
31+
git commit -m "Cleanup documentation for closed PR #${{ github.event.number }}" || echo "No changes to commit"
32+
git push origin HEAD:main

0 commit comments

Comments
 (0)