Skip to content

Commit 32ff23d

Browse files
nicoleribtinova
authored andcommitted
M #-: build of legacy docs with pinned sphinx and theme versions (#3300)
(cherry picked from commit e70a059)
1 parent f4db43a commit 32ff23d

File tree

4 files changed

+217
-0
lines changed

4 files changed

+217
-0
lines changed

.github/workflows/make_html.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Make html
2+
3+
on: [pull_request]
4+
5+
jobs:
6+
build:
7+
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- uses: actions/checkout@v5
12+
- name: Set up Python ${{ matrix.python-version }}
13+
uses: actions/setup-python@v5
14+
with:
15+
python-version: 3.8
16+
- name: Install dependencies
17+
run: |
18+
python -m pip install --upgrade pip
19+
pip install "setuptools<58" "wheel<1.0"
20+
pip install --no-use-pep517 sphinx_bootstrap_theme==0.4.0
21+
pip install "Sphinx==1.8.6" "Jinja2<3.1" "docutils<0.17"
22+
- name: Make html
23+
run: |
24+
make SPHINXBUILD="python -m sphinx" html

.github/workflows/publish_html.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: Publish HTML
2+
3+
on: [push]
4+
5+
jobs:
6+
build:
7+
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- uses: actions/checkout@v5
12+
13+
# ------------------------------------------------------------------------------
14+
# Install requirements needed to compile docs and publish them
15+
# ------------------------------------------------------------------------------
16+
- name: Set up Python ${{ matrix.python-version }}
17+
uses: actions/setup-python@v5
18+
with:
19+
python-version: 3.8
20+
21+
- name: Set up Ruby ${{ matrix.ruby-version }}
22+
uses: ruby/setup-ruby@v1
23+
with:
24+
ruby-version: 3.0
25+
bundler-cache: true
26+
27+
- name: Install dependencies
28+
run: |
29+
python -m pip install --upgrade pip
30+
pip install "setuptools<58" "wheel<1.0"
31+
pip install --no-use-pep517 sphinx_bootstrap_theme==0.4.0
32+
pip install "Sphinx==1.8.6" "Jinja2<3.1" "docutils<0.17"
33+
gem install yaml open3
34+
35+
# ------------------------------------------------------------------------------
36+
# Get useful information
37+
#
38+
# - current branch: needed by the publish script
39+
# ------------------------------------------------------------------------------
40+
- name: Get current branch name
41+
id: get_branch
42+
shell: bash
43+
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
44+
45+
# ------------------------------------------------------------------------------
46+
# Setup SSH keys
47+
# ------------------------------------------------------------------------------
48+
- name: Setup SSH keys
49+
shell: bash
50+
run: |
51+
echo "$SSH_PRIVATE_KEY" > /tmp/id_rsa
52+
echo "$SSH_PUBLIC_KEY" > /tmp/id_rsa.pub
53+
sudo chmod 600 /tmp/id_rsa
54+
sudo chmod 644 /tmp/id_rsa.pub
55+
env:
56+
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
57+
SSH_PUBLIC_KEY: ${{ secrets.SSH_PUBLIC_KEY }}
58+
59+
# ------------------------------------------------------------------------------
60+
# Install requirements needed to compile docs and publish them
61+
# ------------------------------------------------------------------------------
62+
- name: Compile and publish documentation
63+
id: build_publish_docs
64+
shell: bash
65+
env:
66+
HOST: ${{ secrets.HOST }}
67+
HOST_PATH: ${{ secrets.HOST_PATH }}
68+
run: ruby ./publish/publish.rb ${{ steps.get_branch.outputs.branch }}

publish/config.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
mapping:
2+
one-6.10: '6.10'
3+
one-6.8: '6.8'
4+
one-6.6: '6.6'
5+
one-6.4: '6.4'
6+
one-6.2: '6.2'
7+
one-6.0: '6.0'
8+
one-5.12: '5.12'
9+
one-5.10: '5.10'
10+
one-4.14: '4.14'
11+
one-4.12: '4.12'
12+
one-4.10: '4.10'
13+
one-4.8: '4.8'
14+
one-4.6: '4.6'
15+
one-4.4: '4.4'

publish/publish.rb

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
#!/usr/bin/ruby
2+
3+
require 'date'
4+
require 'fileutils'
5+
require 'open3'
6+
require 'yaml'
7+
8+
# ------------------------------------------------------------------------------
9+
# Helpers
10+
# ------------------------------------------------------------------------------
11+
# Run a command
12+
#
13+
# @param cmd [String] Command to run
14+
def run(cmd)
15+
rtn = nil
16+
17+
Open3.popen3(cmd) do |_, o, e, t|
18+
out_reader = Thread.new { o.read }
19+
err_reader = Thread.new { e.read }
20+
21+
rtn = [out_reader.value, err_reader.value, t.value]
22+
end
23+
24+
rtn
25+
end
26+
27+
# Print error and exit
28+
#
29+
# @param rc [Array] rc[0] STDOUT rc[1] STDERR
30+
def error(rc)
31+
return rc[0].strip if rc[2].success?
32+
33+
puts "ERROR: #{rc[1]}"
34+
35+
exit(-1)
36+
end
37+
# ------------------------------------------------------------------------------
38+
# ------------------------------------------------------------------------------
39+
40+
config = YAML.load_file('publish/config.yaml')
41+
42+
unless config['mapping'].include?(ARGV[0])
43+
puts "Aborting, branch '#{ARGV[0]}' is not published"
44+
exit(0)
45+
end
46+
47+
# ------------------------------------------------------------------------------
48+
# Read secrets from ENV
49+
# ------------------------------------------------------------------------------
50+
host = ENV['HOST']
51+
host_path = ENV['HOST_PATH']
52+
53+
# ------------------------------------------------------------------------------
54+
# Compile documentation
55+
# ------------------------------------------------------------------------------
56+
error(run('make SPHINXBUILD="python -m sphinx" html'))
57+
58+
# ------------------------------------------------------------------------------
59+
# Publish documentation
60+
# ------------------------------------------------------------------------------
61+
date_time = DateTime.now.strftime('%Y%m%d%H%M%S')
62+
branch_dir = config['mapping'][ARGV[0]]
63+
branch_symlink_path = "#{host_path}/#{branch_dir}"
64+
branch_build_path = "#{branch_symlink_path}.#{date_time}"
65+
ssh_op = '-o StrictHostKeyChecking=no -i /tmp/id_rsa'
66+
67+
error(run("ssh #{ssh_op} #{host} 'test -d #{host_path} && touch #{host_path}'"))
68+
error(run("ssh #{ssh_op} #{host} 'mkdir #{branch_build_path}'"))
69+
70+
error(run("tar -C 'build/html' --mode='a+r' -cf - . | " \
71+
"ssh #{ssh_op} #{host} 'tar -C '#{branch_build_path}' -xvf -'"))
72+
error(
73+
run(
74+
"ssh #{ssh_op} #{host} " \
75+
"'ln -nsf #{branch_dir}.#{date_time} #{branch_symlink_path}'"
76+
)
77+
)
78+
79+
# ensure dir exists
80+
rc = run("ssh #{ssh_op} #{host} 'ls #{host_path} | grep #{branch_dir}. | sort'")
81+
error(rc)
82+
83+
# ensure branch_symlink_path exists
84+
rc = run("ssh #{ssh_op} #{host} 'test -e #{branch_symlink_path} || " <<
85+
" echo \"#{branch_symlink_path} does not exists\" >&2'")
86+
error(rc)
87+
88+
# ensure branch_symlink_path is a symlink
89+
rc = run("ssh #{ssh_op} #{host} 'test -L #{branch_symlink_path} || " <<
90+
" echo \"#{branch_symlink_path} is not a symlink\" >&2'")
91+
error(rc)
92+
93+
# cleanup old versions
94+
95+
rc = run("ssh #{ssh_op} #{host} 'find #{host_path} -maxdepth 1 -type d -name \"#{branch_dir}.*\" -printf \"%f\\n\" | sort'")
96+
error(rc)
97+
98+
builds = rc[0].split
99+
100+
puts "Total builds found: #{builds.length}"
101+
puts "Builds: #{builds.join("\n")}"
102+
103+
exit(0) if builds.length <= 2
104+
105+
# List all builds except the two most recent
106+
old_builds = builds[0...-2]
107+
old_builds.each do |build|
108+
puts "Removing old build folder: #{build}"
109+
run("ssh #{ssh_op} #{host} rm -rf #{host_path}/#{build}")
110+
end

0 commit comments

Comments
 (0)