Skip to content

Commit

Permalink
Merge pull request #30 from GsLogiMaker:fix/filter-dev-only-files-fro…
Browse files Browse the repository at this point in the history
…m-nightly

Filter dev only files in nightly update process
  • Loading branch information
GsLogiMaker authored Nov 26, 2024
2 parents e0e77d7 + 1858d57 commit e2dbbac
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 20 deletions.
22 changes: 2 additions & 20 deletions .github/workflows/unittests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -303,26 +303,8 @@ jobs:
# # An optional boolean when enabled, allows windows runners to save or restore caches that can be restored or saved respectively on other platforms
# enableCrossOsArchive: true

- name: 🌙 Clone nightly branch
run: |
git clone https://github.com/${{ github.repository }} ../nightly_tmp -b nightly
mkdir ../nightly
mkdir ../nightly/.git
cp -r ../nightly_tmp/.git/* ../nightly/.git/
- name: 🖨️ Copy dev branch plugin to nightly
run: |
cp --recursive --force ./* ../nightly/
- name: ➕ Add and commit to nightly
id: add-and-commit
continue-on-error: true
run: |
cd ../nightly
git config --global user.name github-actions[bot]
git config --global user.email [email protected]
git add .
git commit --all -m "(AUTO) ${{ github.event.head_commit.message }}"
- name: 🌙 Update nightly
run: python utils/update_nightly.py --repository ${{ github.repository }}

- name: 📤 Push to nightly
uses: ad-m/github-push-action@master
Expand Down
80 changes: 80 additions & 0 deletions utils/update_nightly.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@

import argparse
import shutil
import subprocess
import fnmatch
import os

nightly_ignores = [
"./cpp/*",
"./.git/*",
"./.github/*",
"./.vscode/*",
"./unittests/*",
"./utils/*",
"./.gitmodules",
"./.gitignore",
]

def main() -> None:
p = argparse.ArgumentParser(
prog='UpdateNightly',
description='Updates the nightly branch of Glecs from the dev branch.',
)
p.add_argument(
"--repository",
type=str,
required=True,
help="The owner and name of the repository. (Ex. GsLogiMaker/glecs_godot_plugin)",
)

args = p.parse_args()

os.mkdir("../nightly")
clone_nightly(args.repository)
copy_dev_plugin_to_nightly()

def clone_nightly(repo:str) -> None:
subprocess.run(["git", "clone", f"https://github.com/{repo}", f"../nightly_tmp", "-b", "nightly"])
subprocess.run(["cp", "-r", f"../nightly_tmp/.git/", f"../nightly/.git/"])

def copy_dev_plugin_to_nightly() -> None:
# Get all paths
walker = os.walk("./")
paths:list[str] = []
for item in walker:
for folder in item[1]:
paths.append(os.path.join(item[0], folder) + "/")
for file in item[2]:
paths.append(os.path.join(item[0], file))

# Filter paths to copy
filtered_paths = list((n for n in paths
if not any(
fnmatch.fnmatch(n, ignore) for ignore in nightly_ignores
)
))

# Create directories
for path in filtered_paths:
if not path.endswith("/"):
continue
os.mkdir(os.path.join("../nightly/", path))

# Copy files
for path in filtered_paths:
if path.endswith("/"):
continue
shutil.copy(path, os.path.join("../nightly/", path))

def commit_to_nightly() -> None:
cwd = os.getcwd()
subprocess.run(["cd", "../nightly"])
subprocess.run(["git", "config", "--global", "user.name", "github-actions[bot]"])
subprocess.run(["git", "config", "--global", "user.email", "[email protected]"])
subprocess.run(["git", "commit", "--all", "-m", "(AUTO) ${{ github.event.head_commit.message }}"])
subprocess.run(["cd", cwd])


if __name__ == "__main__":
main()

0 comments on commit e2dbbac

Please sign in to comment.