From ee19cb313d870a0d6719a24b7420ad79b2ff7c4e Mon Sep 17 00:00:00 2001 From: Aurelio CI Date: Sat, 11 Jul 2026 18:59:44 +0100 Subject: [PATCH] ci: add aurelio mirror action --- .aurelio/mirror.py | 52 +++++++++++++++++++++++++++ .forgejo/workflows/aurelio-mirror.yml | 25 +++++++++++++ 2 files changed, 77 insertions(+) create mode 100755 .aurelio/mirror.py create mode 100644 .forgejo/workflows/aurelio-mirror.yml diff --git a/.aurelio/mirror.py b/.aurelio/mirror.py new file mode 100755 index 000000000..1a9860933 --- /dev/null +++ b/.aurelio/mirror.py @@ -0,0 +1,52 @@ +#!/usr/bin/env python3 +import os +import subprocess +import sys + +def run_cmd(cmd): + print(f"Running: {cmd}") + result = subprocess.run(cmd, shell=True) + if result.returncode != 0: + print(f"Command failed with exit code {result.returncode}") + return result.returncode + +def main(): + repo_name = os.environ.get("GITHUB_REPOSITORY", "") + if "/" in repo_name: + repo_name = repo_name.split("/")[-1] + + if not repo_name: + repo_name = os.path.basename(os.getcwd()) + + github_token = os.environ.get("GITHUB_TOKEN") + gitlab_token = os.environ.get("GITLAB_TOKEN") + codeberg_token = os.environ.get("CODEBERG_TOKEN") + + failures = 0 + + if github_token: + url = f"https://oauth2:{github_token}@github.com/portugalfuturista/{repo_name}.git" + print("Pushing to GitHub...") + if run_cmd(f"git push --mirror {url}") != 0: + failures += 1 + + if gitlab_token: + url = f"https://oauth2:{gitlab_token}@gitlab.com/portugalfuturista/{repo_name}.git" + print("Pushing to GitLab...") + if run_cmd(f"git push --mirror {url}") != 0: + failures += 1 + + if codeberg_token: + url = f"https://{codeberg_token}@codeberg.org/portugalfuturista/{repo_name}.git" + print("Pushing to Codeberg...") + if run_cmd(f"git push --mirror {url}") != 0: + failures += 1 + + if failures > 0: + print(f"Completed with {failures} failures.") + sys.exit(1) + else: + print("Mirroring completed successfully.") + +if __name__ == "__main__": + main() diff --git a/.forgejo/workflows/aurelio-mirror.yml b/.forgejo/workflows/aurelio-mirror.yml new file mode 100644 index 000000000..5aa203cef --- /dev/null +++ b/.forgejo/workflows/aurelio-mirror.yml @@ -0,0 +1,25 @@ +name: Aurelio Mirror Sync + +on: + push: + branches: + - '**' + tags: + - '**' + +jobs: + mirror: + runs-on: self-hosted + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Run Aurelio Mirror Script + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITLAB_TOKEN: ${{ secrets.GITLAB_TOKEN }} + CODEBERG_TOKEN: ${{ secrets.CODEBERG_TOKEN }} + run: | + python3 .aurelio/mirror.py