-
Notifications
You must be signed in to change notification settings - Fork 44
159 lines (133 loc) · 5.13 KB
/
release_and_docs.yaml
File metadata and controls
159 lines (133 loc) · 5.13 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
name: Release and Deploy Versioned Docs
on:
push:
branches:
- production
jobs:
release_and_docs:
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
issues: write
pull-requests: write
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install Python build dependencies
run: |
pip install build twine
- name: Build Python package
run: python -m build
- name: Install Node dependencies
run: >
npm install --no-save
semantic-release
@semantic-release/commit-analyzer
@semantic-release/release-notes-generator
semantic-release-pypi
@semantic-release/git
@semantic-release/github
- name: Run semantic-release
id: release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN_PROD }}
PYPI_REPO_URL: https://upload.pypi.org/legacy/
run: |
npx semantic-release
VERSION=$(git describe --tags --abbrev=0 --match "v*" 2>/dev/null || echo "no-version")
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Released version: $VERSION"
- name: Build documentation
run: |
pip install -e ".[ml,dev]"
cd docs/
pip install -r docs_requirements.txt
make html
- name: Checkout gh-pages
uses: actions/checkout@v4
with:
ref: gh-pages
path: gh-pages
fetch-depth: 0
- name: Deploy versioned docs
run: |
VERSION="${{ steps.release.outputs.version }}"
# Only deploy if we have a valid version
if [[ "$VERSION" != "no-version" ]]; then
echo "Deploying documentation for version: $VERSION"
# Create version directory and copy docs
mkdir -p "gh-pages/$VERSION"
rsync -av --delete docs/_build/html/ "gh-pages/$VERSION/"
# Also create/update 'latest' to point to this version
mkdir -p gh-pages/latest
rsync -av --delete docs/_build/html/ gh-pages/latest/
# Build switcher.json for all versions
cd gh-pages
versions=()
# Collect all version directories
for d in */; do
d=${d%/} # Remove trailing slash
if [[ "$d" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]] || [[ "$d" == "latest" ]]; then
versions+=("$d")
fi
done
# Sort versions (latest first, then reverse semver order)
IFS=$'\n' sorted_versions=($(printf '%s\n' "${versions[@]}" | sort -V -r))
# Create switcher.json content
switcher_content="["
first=true
for v in "${sorted_versions[@]}"; do
if [[ "$first" == "true" ]]; then
first=false
else
switcher_content="$switcher_content,"
fi
if [[ "$v" == "latest" ]]; then
entry="{\"version\": \"latest\", \"url\": \"https://baker-laboratory.github.io/atomworks-dev/latest/index.html\", \"name\": \"latest\"}"
else
disp="${v#v}"
# Mark the newest stable version as preferred
if [[ "$v" == "$VERSION" ]]; then
preferred="true"
else
preferred="false"
fi
entry="{\"version\": \"$disp\", \"url\": \"https://baker-laboratory.github.io/atomworks-dev/$v/index.html\", \"name\": \"v$disp\", \"preferred\": $preferred}"
fi
switcher_content="$switcher_content$entry"
done
switcher_content="$switcher_content]"
# Write switcher.json to all version directories
for v in "${sorted_versions[@]}"; do
mkdir -p "$v/_static"
echo "$switcher_content" > "$v/_static/switcher.json"
echo "Created switcher.json for $v"
done
echo "Switcher content: $switcher_content"
else
echo "No version tag found, skipping documentation deployment"
fi
- name: Deploy to GitHub Pages
if: steps.release.outputs.version != 'no-version'
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_branch: gh-pages
publish_dir: gh-pages
keep_files: true # Keep existing versions
force_orphan: false # Don't force orphan, preserve history
user_name: 'github-actions[bot]'
user_email: 'github-actions[bot]@users.noreply.github.com'