From 1ee144b49cdb6a98d0f167ca5306d19c3b8e3b25 Mon Sep 17 00:00:00 2001 From: "mr. m" <91018726+mr-cheff@users.noreply.github.com> Date: Tue, 26 Nov 2024 20:43:22 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20pre-deploy=20workflow=20and?= =?UTF-8?q?=20redirect=20script;=20remove=20obsolete=20redirects?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/pre-deploy.yml | 41 ++++++++++++++++++++++++++++++++ _redirects | 1 - scripts/write_redirects.py | 35 +++++++++++++++++++++++++++ 3 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/pre-deploy.yml delete mode 100644 _redirects create mode 100644 scripts/write_redirects.py diff --git a/.github/workflows/pre-deploy.yml b/.github/workflows/pre-deploy.yml new file mode 100644 index 0000000..f2bb116 --- /dev/null +++ b/.github/workflows/pre-deploy.yml @@ -0,0 +1,41 @@ + +name: Pre-Deploy Updates Server + +on: + push: + branches: + - main + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + with: + token: ${{ secrets.DEPLOY_KEY }} + + - name: Install Python + uses: actions/setup-python@v2 + with: + python-version: '3.x' + + - name: Fetch and override deploy branch + run: | + git fetch origin main:main + git checkout main + + git branch -D deploy || true + git checkout -b deploy + + - name: Write redirects + run: | + python scripts/write_redirects.py + + - uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: 🔖 Updated update server + commit_user_name: Zen Browser Robot + commit_user_email: zen-browser-auto@users.noreply.github.com + branch: deploy \ No newline at end of file diff --git a/_redirects b/_redirects deleted file mode 100644 index a43aa2b..0000000 --- a/_redirects +++ /dev/null @@ -1 +0,0 @@ -/home / 301 \ No newline at end of file diff --git a/scripts/write_redirects.py b/scripts/write_redirects.py new file mode 100644 index 0000000..417cffe --- /dev/null +++ b/scripts/write_redirects.py @@ -0,0 +1,35 @@ +import os + +# For branch redirects. E.g. if we want to convert 'alpha' -> 'beta' in all URLs, +# but still maintain the old URLs just in case someone has not updated +# broken branch -> fixed branch +REDIRECTS = { + "twilightundefined": "twilight", # A bug there was with previous twilight updates +} + +UPDATES_ROOT = "updates/browser" + +for new, old in REDIRECTS.items(): + print(f"Redirecting {old} -> {new}") + # just create and copy the content of the old file to the new file + # the structure of the updates server is updates/browser///update.xml + # we want to replace the branch with the new branch + for target in os.listdir(UPDATES_ROOT): + target_path = os.path.join(UPDATES_ROOT, target) + for branch in os.listdir(target_path): + if branch == old: + # The directory doesnt exist, so we create a new one + new_branch_path = os.path.join(target_path, new) + old_branch_path = os.path.join(target_path, old) + os.makedirs(new_branch_path) + for update in os.listdir(old_branch_path): + update_path = os.path.join(old_branch_path, update) + with open(update_path, "r") as f: + content = f.read() + new_update_path = os.path.join(new_branch_path, update) + with open(new_update_path, "w") as nf: + nf.write(content) + print(f"Redirected {old} -> {new} in {target}/{branch}") + +print("Done!") +