Skip to content

Commit 9222f66

Browse files
committed
Add CI
1 parent 4b68ee4 commit 9222f66

File tree

9 files changed

+226
-0
lines changed

9 files changed

+226
-0
lines changed

.github/actions/setup/action.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: 'Default Checkout'
2+
description: 'checkout & setup'
3+
inputs:
4+
python-version:
5+
description: 'Python version'
6+
required: true
7+
default: '>=3'
8+
runs:
9+
using: "composite"
10+
steps:
11+
- name: Set up Python ${{ inputs.python-version }}
12+
uses: actions/setup-python@v5
13+
with:
14+
python-version: ${{ inputs.python-version }}
15+
- uses: actions/cache@v4
16+
with:
17+
path: |
18+
~/.cache/pip
19+
~\AppData\Local\pip\Cache
20+
~/Library/Caches/pip
21+
key: ${{ runner.os }}-py${{ inputs.python-version }}

.github/pdoc_template/config.mako

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<%!
2+
3+
git_link_template = 'https://github.com/sambo-optimization/sambo/blob/{commit}/{path}#L{start_line}-L{end_line}'
4+
5+
# google_search_query = '''
6+
# site:sambo-optimization.github.io
7+
# inurl:github.com/sambo-optimization
8+
# "sambo optimization"
9+
# "sambo optimizer"
10+
# '''
11+
12+
show_source_code = True
13+
14+
lunr_search = {'fuzziness': 1}
15+
16+
hljs_style = 'base16/equilibrium-gray-dark'
17+
18+
%>

.github/pdoc_template/credits.mako

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<p><span style="color:#ddd">&#21328;</span></p>

.github/pdoc_template/head.mako

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<style>
2+
a[rel="home"] img { max-width:70%; display: block; margin: auto; margin-bottom: 2em }
3+
</style>
4+
<link rel="canonical" href="https://sambo-optimization.github.io/doc/${module.url()[:-len('index.html')] if module.is_package else module.url()}">
5+
<link rel="icon logo image" href="/logo.svg">

.github/pdoc_template/logo.mako

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<header>
2+
<a rel="home" title="SAMBO Home" href="https://sambo-optimization.github.io"><img src="/logo.svg" alt="SAMBO"></a>
3+
</header>

.github/scripts/build.sh

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/bin/bash
2+
set -eu
3+
4+
die () { echo "ERROR: $*" >&2; exit 2; }
5+
6+
for cmd in pdoc3; do
7+
command -v "$cmd" >/dev/null ||
8+
die "Missing $cmd; \`pip install $cmd\`"
9+
done
10+
11+
out="www/doc"
12+
package="sambo"
13+
14+
15+
echo
16+
echo 'Building API reference docs'
17+
echo
18+
pdoc3 --html --force \
19+
--template-dir ".github/pdoc_template" \
20+
--output-dir "$out" \
21+
"$package"
22+
23+
24+
ANALYTICS1="<script async src='https://www.googletagmanager.com/gtag/js?id=G-QJH7PLMB12'></script><script>window.dataLayer=window.dataLayer||[];function gtag(){dataLayer.push(arguments);}gtag('js',new Date());gtag('config','G-QJH7PLMB12');</script>"
25+
ANALYTICS2='<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-2900001379782823" crossorigin></script>'
26+
find "$out" -name '*.html' -print0 |
27+
xargs -0 -- sed -i "s#</head>#$ANALYTICS1$ANALYTICS2</head>#i"
28+
29+
exit 0 # TODO: For now
30+
31+
echo
32+
echo 'Testing for broken links'
33+
echo
34+
problematic_urls='
35+
https://www.gnu.org/licenses/agpl-3.0.html
36+
'
37+
pushd "$out" >/dev/null
38+
grep -PR '<a .*?href=' |
39+
sed -E "s/:.*?<a .*?href=([\"'])(.*?)/\t\2/g" |
40+
tr "\"'" '#' |
41+
cut -d'#' -f1 |
42+
sort -u -t$'\t' -k 2 |
43+
sort -u |
44+
python -c '
45+
import sys
46+
from urllib.parse import urljoin
47+
for line in sys.stdin.readlines():
48+
base, url = line.split("\t")
49+
print(base, urljoin(base, url.strip()), sep="\t")
50+
' |
51+
grep -v $'\t''$' |
52+
while read -r line; do
53+
while IFS=$'\t' read -r file url; do
54+
echo "$file: $url"
55+
[ -f "$url" ] ||
56+
curl --silent --fail --retry 3 --retry-delay 1 --connect-timeout 10 \
57+
--user-agent 'Mozilla/5.0 Firefox 125' "$url" >/dev/null 2>&1 ||
58+
grep -qF "$url" <(echo "$problematic_urls") ||
59+
die "broken link in $file: $url"
60+
done
61+
done
62+
popd >/dev/null
63+
64+
65+
echo
66+
echo "All good. Docs in: $out"
67+
echo
68+
echo " file://$(readlink -f "$out")/$package/index.html"
69+
echo

.github/scripts/deploy-gh-pages.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/bash
2+
set -eu
3+
4+
if [ ! -d www ]; then
5+
echo 'Error: invalid directory. Deploy from repo root.'
6+
exit 1
7+
fi
8+
9+
[ "$GH_PASSWORD" ] || exit 12
10+
11+
sitemap() {
12+
WEBSITE='https://sambo-optimization.github.io'
13+
find -name '*.html' |
14+
sed "s,^\.,$WEBSITE," |
15+
sed 's/index.html$//' |
16+
grep -v '/google.*\.html$' |
17+
sort -u > 'sitemap.txt'
18+
echo "Sitemap: $WEBSITE/sitemap.txt" > 'robots.txt'
19+
}
20+
21+
head=$(git rev-parse HEAD)
22+
23+
git clone -b gh-pages "https://kernc:$GH_PASSWORD@github.com/sambo-optimization/sambo-optimization.github.io.git" gh-pages
24+
mkdir -p gh-pages/doc
25+
cp -R www/* gh-pages
26+
cd gh-pages
27+
sitemap
28+
git add *
29+
if git diff --staged --quiet; then
30+
echo "$0: No changes to commit."
31+
exit 0
32+
fi
33+
34+
if ! git config user.name; then
35+
git config user.name 'github-actions'
36+
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
37+
fi
38+
39+
git commit -a -m "CI: Update docs for ${GITHUB_REF#refs/tags/} ($head)"
40+
git push

.github/workflows/ci.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: CI
2+
on:
3+
push: { branches: [master] }
4+
pull_request: { branches: [master] }
5+
schedule: [ cron: '11 3 7 * *' ]
6+
7+
jobs:
8+
test-matrix:
9+
runs-on: ubuntu-latest
10+
strategy:
11+
matrix:
12+
python-version: ['3.10', '>=3']
13+
steps:
14+
- uses: actions/checkout@v4
15+
- uses: ./.github/actions/setup
16+
with:
17+
python-version: ${{ matrix.python-version }}
18+
- run: pip install -U pip setuptools wheel && pip install -U --pre .[all]
19+
- run: time python -m unittest -v sambo._test
20+
21+
lint-test-coverage:
22+
runs-on: ubuntu-latest
23+
steps:
24+
- uses: actions/checkout@v4
25+
- uses: ./.github/actions/setup
26+
with:
27+
python-version: 3.13
28+
- run: pip install -U pip setuptools wheel && pip install -U .[all]
29+
- run: pip install flake8 coverage
30+
- run: flake8 sambo benchmark setup.py
31+
- run: time coverage run -m unittest -v sambo._test
32+
- run: coverage report
33+
34+
docs:
35+
runs-on: ubuntu-latest
36+
steps:
37+
- uses: actions/checkout@v4
38+
- uses: ./.github/actions/setup
39+
with:
40+
python-version: 3.13
41+
- name: Fetch tags
42+
run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
43+
44+
- run: pip install -U pip setuptools wheel pdoc3 && pip install -e .[all]
45+
- run: time .github/scripts/build.sh

.github/workflows/deploy-docs.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Deploy docs
2+
on:
3+
push:
4+
tags: [ v* ]
5+
6+
jobs:
7+
deploy:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v4
11+
with:
12+
fetch-depth: 3
13+
- name: Fetch tags
14+
run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
15+
- uses: ./.github/actions/setup
16+
with:
17+
python-version: 3.13
18+
19+
- run: pip install -e .[all] pdoc3
20+
- run: time .github/scripts/build.sh
21+
22+
- env:
23+
GH_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
24+
run: .github/scripts/deploy-gh-pages.sh

0 commit comments

Comments
 (0)