-
Notifications
You must be signed in to change notification settings - Fork 8
118 lines (101 loc) · 3.33 KB
/
python_build_docs.yml
File metadata and controls
118 lines (101 loc) · 3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
name: Build and Deploy Python Docs (Dev)
on:
pull_request:
types: [ opened, synchronize, closed ]
paths:
- 'python/docs/**'
- 'python/lib/**'
- 'python/mkdocs.yml'
- 'python/pyproject.toml'
workflow_dispatch:
inputs:
deploy_to_dev:
description: 'Deploy to dev alias using commit hash as version'
required: false
default: true
type: boolean
jobs:
build_docs:
if: github.event.action != 'closed'
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install dependencies
run: |
cd python
pip install -e .[docs-build]
- name: Extract version
id: version
run: |
# Use commit hash as version for dev deployments
VERSION=$(git rev-parse --short HEAD)
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
# Use PR number as alias for PR deployments
ALIAS="pr-${{ github.event.number }}"
else
# Use 'dev' for manual workflow dispatch
ALIAS="dev"
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "alias=$ALIAS" >> $GITHUB_OUTPUT
echo "Dev deployment - Version: $VERSION, Alias: $ALIAS"
- name: Fetch gh-pages branch
run: git fetch origin gh-pages --depth=1
- name: Configure Git
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
- name: Deploy docs with mike
run: |
cd python
# Deploy dev/PR docs with hidden property to hide from version dropdown
mike deploy ${{ steps.version.outputs.alias }} --push --update-aliases --prop-set hidden=true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
cleanup_docs:
if: github.event.action == 'closed'
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install dependencies
run: |
cd python
pip install -e .[docs-build]
- name: Fetch gh-pages branch
run: git fetch origin gh-pages --depth=1
- name: Configure Git
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
- name: Delete PR docs
run: |
cd python
PR_ALIAS="pr-${{ github.event.number }}"
echo "Deleting docs for: $PR_ALIAS"
# Check if the PR docs exist before trying to delete
if mike list | grep -q "$PR_ALIAS"; then
mike delete "$PR_ALIAS" --push
echo "Successfully deleted docs for $PR_ALIAS"
else
echo "No docs found for $PR_ALIAS, nothing to delete"
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}