Skip to content

Merge #52

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 29 commits into from
Mar 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
3696f94
Create Auto Sync With Main.yml
kRxZykRxZy Mar 27, 2025
10f8fb2
Update Auto Sync With Main.yml
kRxZykRxZy Mar 27, 2025
b15bece
Sync data from target repo
invalid-email-address Mar 27, 2025
0f13ee8
Merge branch 'Scratch-Coding-Hut:main' into main
kRxZykRxZy Mar 27, 2025
b365088
Create Auto Sync.yml
kRxZykRxZy Mar 27, 2025
20d58e7
Update Auto Sync.yml
kRxZykRxZy Mar 27, 2025
1aa1758
Update Auto Sync.yml
kRxZykRxZy Mar 27, 2025
455e4ed
Merge branch 'Scratch-Coding-Hut:main' into main
kRxZykRxZy Mar 27, 2025
2a1a188
Merge branch 'Scratch-Coding-Hut:main' into main
kRxZykRxZy Mar 28, 2025
482421e
Merge branch 'Scratch-Coding-Hut:main' into main
kRxZykRxZy Mar 28, 2025
2356557
Merge branch 'Scratch-Coding-Hut:main' into main
kRxZykRxZy Mar 28, 2025
67a6ebb
Update Auto Sync.yml
kRxZykRxZy Mar 28, 2025
90cfb48
Update Auto Sync.yml
kRxZykRxZy Mar 28, 2025
e12464c
Update Auto Sync.yml
kRxZykRxZy Mar 28, 2025
ff1d86b
Update Auto Sync.yml
kRxZykRxZy Mar 28, 2025
b851df2
Update Auto Sync.yml
kRxZykRxZy Mar 28, 2025
4d1b284
Update Auto Sync.yml
kRxZykRxZy Mar 28, 2025
0472d48
Update Auto Sync.yml
kRxZykRxZy Mar 28, 2025
c8de011
Update Auto Sync.yml
kRxZykRxZy Mar 28, 2025
6a057c8
Create clone_and_manage.py
kRxZykRxZy Mar 28, 2025
8941c0d
Update clone_and_manage.py
kRxZykRxZy Mar 28, 2025
7703388
Update clone_and_manage.py
kRxZykRxZy Mar 28, 2025
f1f10b4
Update Auto Sync.yml
kRxZykRxZy Mar 28, 2025
1cddf3c
Create sync-config.yml
kRxZykRxZy Mar 28, 2025
fff289e
Delete .github/workflows/Auto Sync.yml
kRxZykRxZy Mar 28, 2025
f178258
Create Sync.yml
kRxZykRxZy Mar 28, 2025
c1ef0a3
Merge branch 'Scratch-Coding-Hut:main' into main
kRxZykRxZy Mar 28, 2025
6cce6a7
Update sync-config.yml
kRxZykRxZy Mar 29, 2025
01c94eb
Merge branch 'Scratch-Coding-Hut:main' into main
kRxZykRxZy Mar 29, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/sync-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
repos:
- "Scratch-Coding-Hut/Scratch-Coding-Hut" # Correct target repo

files:
- source: "/src/" # Copy all files inside 'src' folder
dest: "/" # Place them in the root of the target repo
delete: true # Delete extra files in the target repo
20 changes: 20 additions & 0 deletions .github/workflows/Sync.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Repo File Sync

on:
schedule:
- cron: "*/1 * * * *" # Runs every minute
workflow_dispatch: # Manual trigger if needed

jobs:
sync:
runs-on: ubuntu-latest

steps:
- name: Checkout Source Repo
uses: actions/checkout@v3

- name: Repo File Sync Action
uses: BetaHuhn/[email protected]
with:
GH_PAT: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
CONFIG_PATH: .github/sync-config.yml # Use custom config to sync src
56 changes: 56 additions & 0 deletions clone_and_manage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import os
import requests
import git
from pathlib import Path
import shutil

# Your GitHub repository URL and token
repo_url = "https://github.com/Scratch-Coding-Hut/Scratch-Coding-Hut"
token = "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" # This is your PAT stored as a secret in GitHub

# Function to clone the repo using GitHub API
def clone_repo():
# Clone the repo using GitPython (it can also clone using git command internally)
repo_dir = Path("./Scratch-Coding-Hut")
if repo_dir.exists():
shutil.rmtree(repo_dir) # Remove the old repo if it exists, but not the Python script
git.Repo.clone_from(repo_url, repo_dir, depth=1)
return repo_dir

# Function to copy files excluding .github and .git folder
def copy_files(src_dir, dest_dir):
# Iterate over the source directory and copy files, skipping .github and .git
for item in os.listdir(src_dir):
if item not in [".github", ".git"]: # Skip both .github and .git folder
src_path = src_dir / item
dest_path = dest_dir / item
if src_path.is_dir():
shutil.copytree(src_path, dest_path) # Copy directories
else:
shutil.copy2(src_path, dest_path) # Copy files

# Function to set Git config
def set_git_config():
# Set the Git config for user name and email to avoid identity issues
os.system('git config --global user.email "[email protected]"')
os.system('git config --global user.name "GitHub Actions"')

# Main function
def main():
# Step 1: Set Git config
set_git_config()

# Step 2: Clone the repo
src_repo_dir = clone_repo()

# Step 3: Prepare the destination path (current repository)
dest_repo_dir = Path(".") # This is the current directory where the GitHub Action is running

# Step 4: Copy files excluding .github and .git folders
copy_files(src_repo_dir, dest_repo_dir)

# Step 5: Clean up - Remove the cloned repo directory if you don't need it anymore (excluding Python script)
shutil.rmtree(src_repo_dir)

if __name__ == "__main__":
main()
Loading