Skip to content

Commit f00a853

Browse files
authored
Merge pull request #52 from kRxZykRxZy/main
Merge
2 parents 7aa1c04 + 01c94eb commit f00a853

File tree

3 files changed

+83
-0
lines changed

3 files changed

+83
-0
lines changed

.github/sync-config.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
repos:
2+
- "Scratch-Coding-Hut/Scratch-Coding-Hut" # Correct target repo
3+
4+
files:
5+
- source: "/src/" # Copy all files inside 'src' folder
6+
dest: "/" # Place them in the root of the target repo
7+
delete: true # Delete extra files in the target repo

.github/workflows/Sync.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Repo File Sync
2+
3+
on:
4+
schedule:
5+
- cron: "*/1 * * * *" # Runs every minute
6+
workflow_dispatch: # Manual trigger if needed
7+
8+
jobs:
9+
sync:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout Source Repo
14+
uses: actions/checkout@v3
15+
16+
- name: Repo File Sync Action
17+
uses: BetaHuhn/[email protected]
18+
with:
19+
GH_PAT: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
20+
CONFIG_PATH: .github/sync-config.yml # Use custom config to sync src

clone_and_manage.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import os
2+
import requests
3+
import git
4+
from pathlib import Path
5+
import shutil
6+
7+
# Your GitHub repository URL and token
8+
repo_url = "https://github.com/Scratch-Coding-Hut/Scratch-Coding-Hut"
9+
token = "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" # This is your PAT stored as a secret in GitHub
10+
11+
# Function to clone the repo using GitHub API
12+
def clone_repo():
13+
# Clone the repo using GitPython (it can also clone using git command internally)
14+
repo_dir = Path("./Scratch-Coding-Hut")
15+
if repo_dir.exists():
16+
shutil.rmtree(repo_dir) # Remove the old repo if it exists, but not the Python script
17+
git.Repo.clone_from(repo_url, repo_dir, depth=1)
18+
return repo_dir
19+
20+
# Function to copy files excluding .github and .git folder
21+
def copy_files(src_dir, dest_dir):
22+
# Iterate over the source directory and copy files, skipping .github and .git
23+
for item in os.listdir(src_dir):
24+
if item not in [".github", ".git"]: # Skip both .github and .git folder
25+
src_path = src_dir / item
26+
dest_path = dest_dir / item
27+
if src_path.is_dir():
28+
shutil.copytree(src_path, dest_path) # Copy directories
29+
else:
30+
shutil.copy2(src_path, dest_path) # Copy files
31+
32+
# Function to set Git config
33+
def set_git_config():
34+
# Set the Git config for user name and email to avoid identity issues
35+
os.system('git config --global user.email "[email protected]"')
36+
os.system('git config --global user.name "GitHub Actions"')
37+
38+
# Main function
39+
def main():
40+
# Step 1: Set Git config
41+
set_git_config()
42+
43+
# Step 2: Clone the repo
44+
src_repo_dir = clone_repo()
45+
46+
# Step 3: Prepare the destination path (current repository)
47+
dest_repo_dir = Path(".") # This is the current directory where the GitHub Action is running
48+
49+
# Step 4: Copy files excluding .github and .git folders
50+
copy_files(src_repo_dir, dest_repo_dir)
51+
52+
# Step 5: Clean up - Remove the cloned repo directory if you don't need it anymore (excluding Python script)
53+
shutil.rmtree(src_repo_dir)
54+
55+
if __name__ == "__main__":
56+
main()

0 commit comments

Comments
 (0)