2022-09-25 07:31:53 +00:00
|
|
|
#
|
|
|
|
# Copyright © 2022 Maestro Creativescape
|
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
#
|
|
|
|
|
2022-09-25 07:37:25 +00:00
|
|
|
# Imports
|
2022-09-25 07:30:15 +00:00
|
|
|
from git import Repo
|
|
|
|
import subprocess
|
|
|
|
import os
|
|
|
|
from requests import post
|
2022-09-25 16:23:21 +00:00
|
|
|
from pathlib import Path
|
2022-09-25 07:30:15 +00:00
|
|
|
|
2022-09-25 07:37:25 +00:00
|
|
|
# Environment variables for creds
|
2022-09-25 07:30:15 +00:00
|
|
|
content_repo_git = os.environ.get("CONTENT_REPO_GIT")
|
2022-09-25 07:33:02 +00:00
|
|
|
content_repo_id = os.environ.get("CONTENT_REPO_ID")
|
2022-09-25 07:30:15 +00:00
|
|
|
gitlab_token = os.environ.get("GITLAB_TOKEN")
|
2023-06-18 13:51:27 +00:00
|
|
|
ssh_key = os.environ.get("SSH_SECRET_KEY")
|
|
|
|
|
2023-06-18 14:02:22 +00:00
|
|
|
git_ssh_cmd = f"ssh -i {ssh_key}"
|
2022-09-25 07:30:15 +00:00
|
|
|
|
2022-09-25 07:37:25 +00:00
|
|
|
# Get the time and create a tag of epoch
|
2022-09-25 11:10:41 +00:00
|
|
|
cwd = os.getcwd()
|
|
|
|
path = Path(cwd)
|
|
|
|
base_dir = str(path.parent.absolute())
|
|
|
|
repo = Repo(base_dir)
|
2022-09-25 07:30:15 +00:00
|
|
|
|
2022-09-25 07:37:25 +00:00
|
|
|
# Nuke the remote if it existed
|
2022-09-25 16:43:44 +00:00
|
|
|
try:
|
|
|
|
if repo.remote("pushback").exists():
|
|
|
|
repo.remote().remove(repo, "pushback")
|
|
|
|
except ValueError:
|
|
|
|
pass
|
2022-09-25 07:34:39 +00:00
|
|
|
repo.create_remote(
|
|
|
|
"pushback",
|
2023-06-18 13:51:27 +00:00
|
|
|
f"ssh://git@git.baalajimaestro.me:29999/{content_repo_git}.git",
|
2022-09-25 07:34:39 +00:00
|
|
|
)
|
2022-09-25 07:37:25 +00:00
|
|
|
|
|
|
|
# Push the newly created tag
|
2023-06-18 13:51:27 +00:00
|
|
|
repo.git.push("pushback", "HEAD:prod", force=True, env=dict(GIT_SSH_COMMAND=git_ssh_cmd))
|
2022-09-25 07:30:15 +00:00
|
|
|
|
2022-09-25 07:37:25 +00:00
|
|
|
# Trigger site rebuild
|
2022-09-25 07:30:15 +00:00
|
|
|
data = {"token": gitlab_token, "ref": "source"}
|
|
|
|
|
2022-09-25 07:34:39 +00:00
|
|
|
post(
|
|
|
|
f"https://git.baalajimaestro.me/api/v4/projects/{content_repo_id}/trigger/pipeline",
|
|
|
|
json=data,
|
|
|
|
)
|