diff --git a/.github/workflows/helpers/deploy-docs.py b/.github/workflows/helpers/deploy-docs.py new file mode 100755 index 0000000000..353997d59e --- /dev/null +++ b/.github/workflows/helpers/deploy-docs.py @@ -0,0 +1,63 @@ +#! /usr/bin/env python3 + +import os +import tempfile +import subprocess +from typing import Tuple +from pathlib import Path +import shlex + +KNOWN_HOSTS = ''' +flexflow.ai ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAING3BmAIYc0G5hxIFPqQrgLjCt2t4vlRaLxds3QY6MaE +''' + +def create_ssh_key_file(d: Path) -> Tuple[Path, Path]: + d.chmod(0o700) + + ssh_private_key_path = d / 'id_ed25519' + ssh_private_key_path.touch(mode=0o600, exist_ok=False) + + ssh_known_hosts_path = d / 'known_hosts' + ssh_known_hosts_path.touch(mode=0o600, exist_ok=False) + + ssh_private_key_path.write_text(os.environ['SSH_PRIVATE_KEY'] + '\n') + ssh_known_hosts_path.write_text(KNOWN_HOSTS) + + return ssh_private_key_path, ssh_known_hosts_path + +def deploy(ssh_private_key_path: Path, ssh_known_hosts_path: Path) -> None: + assert ssh_private_key_path.is_file() + assert ssh_known_hosts_path.is_file() + + docs_html_dir = Path('./build/doxygen/html/') + assert docs_html_dir.is_dir() + assert (docs_html_dir / 'index.html').is_file() + + ssh_command = shlex.join([ + 'ssh', '-i', str(ssh_private_key_path), '-o', f'UserKnownHostsFile={ssh_known_hosts_path}', + ]) + print(ssh_command) + subprocess.run( + [ + 'rsync', + '--delete', + '--recursive', + '--verbose', + '--human-readable', + f'--rsh={ssh_command}', + str(docs_html_dir) + '/', + 'deploy-ff-train-docs@flexflow.ai:/opt/www/ff-train-docs/', + ], + check=True, + ) + +if __name__ == '__main__': + with tempfile.TemporaryDirectory() as _d: + d = Path(_d) + + ssh_private_key_path, ssh_known_hosts_path = create_ssh_key_file(d) + + deploy( + ssh_private_key_path=ssh_private_key_path, + ssh_known_hosts_path=ssh_known_hosts_path, + ) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 799e3069a9..9248e1d7ea 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -43,6 +43,13 @@ jobs: run: | proj check cpu-ci + - name: Deploy docs to flexflow.ai + env: + SSH_PRIVATE_KEY: ${{secrets.DOCS_SSH_PRIVATE_KEY}} + if: ${{ success() && ( github.event_name == 'push' || github.event_name == 'workflow_dispatch' ) && github.ref == 'refs/heads/master' }} + run: | + ./.github/workflows/helpers/deploy-docs.py + - name: Upload code coverage uses: codecov/codecov-action@v4 with: