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 time import time
|
|
|
|
from requests import post
|
|
|
|
|
2022-09-25 07:37:25 +00:00
|
|
|
# Environment variables for creds
|
2022-09-25 07:30:15 +00:00
|
|
|
base_repo_user = os.environ.get("BASE_REPO_USERNAME")
|
|
|
|
base_repo_pass = os.environ.get("BASE_REPO_PASSWORD")
|
|
|
|
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")
|
|
|
|
|
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())
|
2022-09-25 07:37:25 +00:00
|
|
|
current_time = str(int(time()))
|
2022-09-25 11:10:41 +00:00
|
|
|
repo = Repo(base_dir)
|
2022-09-25 07:30:15 +00:00
|
|
|
repo.create_tag(current_time)
|
|
|
|
|
2022-09-25 07:37:25 +00:00
|
|
|
# Nuke the remote if it existed
|
2022-09-25 07:30:15 +00:00
|
|
|
if repo.remote("pushback").exists():
|
|
|
|
repo.remote().remove(repo, "pushback")
|
2022-09-25 07:34:39 +00:00
|
|
|
repo.create_remote(
|
|
|
|
"pushback",
|
|
|
|
f"https://{base_repo_user}:{base_repo_pass}@git.baalajimaestro.me/baalajimaestro/{content_repo_git}.git",
|
|
|
|
)
|
2022-09-25 07:37:25 +00:00
|
|
|
|
|
|
|
# Push the newly created tag
|
2022-09-25 07:34:39 +00:00
|
|
|
repo.git.push("pushback", current_time)
|
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,
|
|
|
|
)
|