#!/bin/bash

# WARNING: DO NOT EDIT!
#
# This file was generated by plugin_template, and is managed by it. Please use
# './plugin-template --github pulpcore' to update this file.
#
# For more info visit https://github.com/pulp/plugin_template

set -euv

# make sure this script runs at the repo root
cd "$(dirname "$(realpath -e "$0")")"/../..

mkdir ~/.ssh
echo "$PULP_DOCS_KEY" > ~/.ssh/pulp-infra
chmod 600 ~/.ssh/pulp-infra

echo "docs.pulpproject.org,8.43.85.236 ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBGXG+8vjSQvnAkq33i0XWgpSrbco3rRqNZr0SfVeiqFI7RN/VznwXMioDDhc+hQtgVhd6TYBOrV07IMcKj+FAzg=" >> /home/runner/.ssh/known_hosts
chmod 644 /home/runner/.ssh/known_hosts

pip3 install -r docs/doc_requirements.txt

eval "$(ssh-agent -s)" #start the ssh agent
ssh-add ~/.ssh/pulp-infra

mkdocs build

# publish to docs.pulpproject.org/pulp_operator
rsync -avzh site/ doc_builder_pulp_operator@docs.pulpproject.org:/var/www/docs.pulpproject.org/pulp_operator/

# publish to docs.pulpproject.org/pulp_operator/en/{release}
rsync -avzh site/ doc_builder_pulp_operator@docs.pulpproject.org:/var/www/docs.pulpproject.org/pulp_operator/en/"$1"
