obsidian-support-scripts/trigger.py

49 lines
1.1 KiB
Python
Raw Normal View History

#
# Copyright © 2022 Maestro Creativescape
#
# SPDX-License-Identifier: AGPL-3.0-or-later
#
# Imports
from git import Repo
import subprocess
import os
from requests import post
from pathlib import Path
# Environment variables for creds
content_repo_git = os.environ.get("CONTENT_REPO_GIT")
content_repo_id = os.environ.get("CONTENT_REPO_ID")
gitlab_token = os.environ.get("GITLAB_TOKEN")
ssh_key = os.environ.get("SSH_SECRET_KEY")
git_ssh_cmd = f"ssh -i {ssh_key}"
# Get the time and create a tag of epoch
cwd = os.getcwd()
path = Path(cwd)
base_dir = str(path.parent.absolute())
repo = Repo(base_dir)
# Nuke the remote if it existed
try:
if repo.remote("pushback").exists():
repo.remote().remove(repo, "pushback")
except ValueError:
pass
repo.create_remote(
"pushback",
f"ssh://git@git.baalajimaestro.me:29999/{content_repo_git}.git",
)
# Push the newly created tag
repo.git.push("pushback", "HEAD:prod", force=True, env=dict(GIT_SSH_COMMAND=git_ssh_cmd))
# Trigger site rebuild
data = {"token": gitlab_token, "ref": "source"}
post(
f"https://git.baalajimaestro.me/api/v4/projects/{content_repo_id}/trigger/pipeline",
json=data,
)