From 3696f94fef47ac610b86829726c8845cf81ae40a Mon Sep 17 00:00:00 2001 From: kRxZykRxZy <192328467+kRxZykRxZy@users.noreply.github.com> Date: Thu, 27 Mar 2025 07:37:15 +0000 Subject: [PATCH 01/22] Create Auto Sync With Main.yml --- .github/workflows/Auto Sync With Main.yml | 55 +++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 .github/workflows/Auto Sync With Main.yml diff --git a/.github/workflows/Auto Sync With Main.yml b/.github/workflows/Auto Sync With Main.yml new file mode 100644 index 0000000..9aa1245 --- /dev/null +++ b/.github/workflows/Auto Sync With Main.yml @@ -0,0 +1,55 @@ +name: Auto Sync Data from Another Repo + +on: + schedule: + - cron: '* * * * *' # Runs every minute + workflow_dispatch: # Manual trigger if needed + +jobs: + sync-repo: + runs-on: ubuntu-latest + + steps: + - name: Checkout Current Repo + uses: actions/checkout@v2 + + - name: Clone Target Repo + run: | + git clone https://github.com/username/target-repo.git temp-repo + env: + GITHUB_TOKEN: ${{ secrets.PAT }} + + - name: Check for Changes + id: check_changes + run: | + cd temp-repo + LATEST_COMMIT=$(git rev-parse HEAD) + cd .. + if [ -f .latest_commit ]; then + PREV_COMMIT=$(cat .latest_commit) + if [ "$LATEST_COMMIT" == "$PREV_COMMIT" ]; then + echo "No changes detected." + exit 0 + fi + fi + echo $LATEST_COMMIT > .latest_commit + echo "New changes detected." + + - name: Copy Files to Current Repo + if: success() # Only run if changes are detected + run: | + rsync -av --progress temp-repo/ . --exclude .git --delete + rm -rf temp-repo + + - name: Configure Git + if: success() + run: | + git config user.name "github-actions" + git config user.email "github-actions@github.com" + + - name: Commit and Push Changes + if: success() + run: | + git add . + git diff --quiet && git diff --staged --quiet || git commit -m "Sync data from target repo" + git push From 10f8fb29d3c2a81e95c6661f6bb3b838fa5b468e Mon Sep 17 00:00:00 2001 From: kRxZykRxZy <192328467+kRxZykRxZy@users.noreply.github.com> Date: Thu, 27 Mar 2025 07:40:03 +0000 Subject: [PATCH 02/22] Update Auto Sync With Main.yml --- .github/workflows/Auto Sync With Main.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/Auto Sync With Main.yml b/.github/workflows/Auto Sync With Main.yml index 9aa1245..05e174c 100644 --- a/.github/workflows/Auto Sync With Main.yml +++ b/.github/workflows/Auto Sync With Main.yml @@ -15,9 +15,7 @@ jobs: - name: Clone Target Repo run: | - git clone https://github.com/username/target-repo.git temp-repo - env: - GITHUB_TOKEN: ${{ secrets.PAT }} + git clone https://${{ secrets.PAT }}@github.com/Scratch-Coding-Hut/Scratch-Coding-Hut.github.io.git temp-repo - name: Check for Changes id: check_changes From b15bece7766f439d7eef5ac0bb71436ee36766a1 Mon Sep 17 00:00:00 2001 From: github-actions Date: Thu, 27 Mar 2025 07:40:29 +0000 Subject: [PATCH 03/22] Sync data from target repo --- .github/workflows/Auto Sync With Main.yml | 53 ----------------------- 1 file changed, 53 deletions(-) delete mode 100644 .github/workflows/Auto Sync With Main.yml diff --git a/.github/workflows/Auto Sync With Main.yml b/.github/workflows/Auto Sync With Main.yml deleted file mode 100644 index 05e174c..0000000 --- a/.github/workflows/Auto Sync With Main.yml +++ /dev/null @@ -1,53 +0,0 @@ -name: Auto Sync Data from Another Repo - -on: - schedule: - - cron: '* * * * *' # Runs every minute - workflow_dispatch: # Manual trigger if needed - -jobs: - sync-repo: - runs-on: ubuntu-latest - - steps: - - name: Checkout Current Repo - uses: actions/checkout@v2 - - - name: Clone Target Repo - run: | - git clone https://${{ secrets.PAT }}@github.com/Scratch-Coding-Hut/Scratch-Coding-Hut.github.io.git temp-repo - - - name: Check for Changes - id: check_changes - run: | - cd temp-repo - LATEST_COMMIT=$(git rev-parse HEAD) - cd .. - if [ -f .latest_commit ]; then - PREV_COMMIT=$(cat .latest_commit) - if [ "$LATEST_COMMIT" == "$PREV_COMMIT" ]; then - echo "No changes detected." - exit 0 - fi - fi - echo $LATEST_COMMIT > .latest_commit - echo "New changes detected." - - - name: Copy Files to Current Repo - if: success() # Only run if changes are detected - run: | - rsync -av --progress temp-repo/ . --exclude .git --delete - rm -rf temp-repo - - - name: Configure Git - if: success() - run: | - git config user.name "github-actions" - git config user.email "github-actions@github.com" - - - name: Commit and Push Changes - if: success() - run: | - git add . - git diff --quiet && git diff --staged --quiet || git commit -m "Sync data from target repo" - git push From b365088bb90f03ce27ddc0d8c6b7d9637c979d1c Mon Sep 17 00:00:00 2001 From: kRxZykRxZy <192328467+kRxZykRxZy@users.noreply.github.com> Date: Thu, 27 Mar 2025 17:06:34 +0000 Subject: [PATCH 04/22] Create Auto Sync.yml --- .github/workflows/Auto Sync.yml | 53 +++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 .github/workflows/Auto Sync.yml diff --git a/.github/workflows/Auto Sync.yml b/.github/workflows/Auto Sync.yml new file mode 100644 index 0000000..e19df9c --- /dev/null +++ b/.github/workflows/Auto Sync.yml @@ -0,0 +1,53 @@ +name: Auto Sync Data from Another Repo + +on: + schedule: + - cron: '* * * * *' # Runs every minute + workflow_dispatch: # Manual trigger if needed + +jobs: + sync-repo: + runs-on: ubuntu-latest + + steps: + - name: Checkout Current Repo + uses: actions/checkout@v2 + + - name: Clone Target Repo + run: | + git clone https://${{ secrets.PAT }}@github.com/Scratch-Coding-Hut/Scratch-Coding-Hut.github.io.git temp-repo + + - name: Check for Changes + id: check_changes + run: | + cd temp-repo + LATEST_COMMIT=$(git rev-parse HEAD) + cd .. + if [ -f .latest_commit ]; then + PREV_COMMIT=$(cat .latest_commit) + if [ "$LATEST_COMMIT" == "$PREV_COMMIT" ]; then + echo "No changes detected." + exit 0 + fi + fi + echo $LATEST_COMMIT > .latest_commit + echo "New changes detected." + + - name: Copy Files to Current Repo + if: success() # Only run if changes are detected + run: | + rsync -av --progress temp-repo/ . --exclude .git --exclude .github --ignore-missing-args --delete + rm -rf temp-repo + + - name: Configure Git + if: success() + run: | + git config user.name "github-actions" + git config user.email "github-actions@github.com" + + - name: Commit and Push Changes + if: success() + run: | + git add . + git diff --quiet && git diff --staged --quiet || git commit -m "Sync data from target repo" + git push From 20d58e7304857d3e7055233840bfb2e3abc53c3e Mon Sep 17 00:00:00 2001 From: kRxZykRxZy <192328467+kRxZykRxZy@users.noreply.github.com> Date: Thu, 27 Mar 2025 17:09:35 +0000 Subject: [PATCH 05/22] Update Auto Sync.yml --- .github/workflows/Auto Sync.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/Auto Sync.yml b/.github/workflows/Auto Sync.yml index e19df9c..3923c58 100644 --- a/.github/workflows/Auto Sync.yml +++ b/.github/workflows/Auto Sync.yml @@ -36,7 +36,7 @@ jobs: - name: Copy Files to Current Repo if: success() # Only run if changes are detected run: | - rsync -av --progress temp-repo/ . --exclude .git --exclude .github --ignore-missing-args --delete + rsync -av --progress temp-repo/ . --exclude .git --exclude .github --ignore-missing-args --delete --ignore-errors rm -rf temp-repo - name: Configure Git From 1aa17583ec33f033ef120631f210bc2cdfd46e0e Mon Sep 17 00:00:00 2001 From: kRxZykRxZy <192328467+kRxZykRxZy@users.noreply.github.com> Date: Thu, 27 Mar 2025 17:14:21 +0000 Subject: [PATCH 06/22] Update Auto Sync.yml --- .github/workflows/Auto Sync.yml | 31 +++++++------------------------ 1 file changed, 7 insertions(+), 24 deletions(-) diff --git a/.github/workflows/Auto Sync.yml b/.github/workflows/Auto Sync.yml index 3923c58..513e8a2 100644 --- a/.github/workflows/Auto Sync.yml +++ b/.github/workflows/Auto Sync.yml @@ -13,40 +13,23 @@ jobs: - name: Checkout Current Repo uses: actions/checkout@v2 - - name: Clone Target Repo + - name: Delete Current Repo Contents run: | - git clone https://${{ secrets.PAT }}@github.com/Scratch-Coding-Hut/Scratch-Coding-Hut.github.io.git temp-repo + find . -mindepth 1 -maxdepth 1 ! -name ".git" -exec rm -rf {} + - - name: Check for Changes - id: check_changes + - name: Download and Extract Target Repo run: | - cd temp-repo - LATEST_COMMIT=$(git rev-parse HEAD) - cd .. - if [ -f .latest_commit ]; then - PREV_COMMIT=$(cat .latest_commit) - if [ "$LATEST_COMMIT" == "$PREV_COMMIT" ]; then - echo "No changes detected." - exit 0 - fi - fi - echo $LATEST_COMMIT > .latest_commit - echo "New changes detected." - - - name: Copy Files to Current Repo - if: success() # Only run if changes are detected - run: | - rsync -av --progress temp-repo/ . --exclude .git --exclude .github --ignore-missing-args --delete --ignore-errors - rm -rf temp-repo + wget -q https://github.com/Scratch-Coding-Hut/Scratch-Coding-Hut.github.io/archive/refs/heads/main.zip -O main.zip + unzip -q main.zip + rsync -av --progress Scratch-Coding-Hut.github.io-main/ . --exclude .git --delete + rm -rf Scratch-Coding-Hut.github.io-main main.zip - name: Configure Git - if: success() run: | git config user.name "github-actions" git config user.email "github-actions@github.com" - name: Commit and Push Changes - if: success() run: | git add . git diff --quiet && git diff --staged --quiet || git commit -m "Sync data from target repo" From 67a6ebbe3bbe41ef52ac2fbd453e11d8f196f309 Mon Sep 17 00:00:00 2001 From: kRxZykRxZy <192328467+kRxZykRxZy@users.noreply.github.com> Date: Fri, 28 Mar 2025 16:25:34 +0000 Subject: [PATCH 07/22] Update Auto Sync.yml --- .github/workflows/Auto Sync.yml | 36 +++++++++++++-------------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/.github/workflows/Auto Sync.yml b/.github/workflows/Auto Sync.yml index 513e8a2..fe32ecc 100644 --- a/.github/workflows/Auto Sync.yml +++ b/.github/workflows/Auto Sync.yml @@ -1,36 +1,28 @@ -name: Auto Sync Data from Another Repo +name: Clone Scratch-Coding-Hut Repo on: schedule: - - cron: '* * * * *' # Runs every minute - workflow_dispatch: # Manual trigger if needed + - cron: '*/1 * * * *' # Run every minute + workflow_dispatch: # Allows manual trigger if needed jobs: - sync-repo: + clone-repo: runs-on: ubuntu-latest steps: - - name: Checkout Current Repo - uses: actions/checkout@v2 + - name: Checkout the current repository + uses: actions/checkout@v3 - - name: Delete Current Repo Contents + - name: Clone Scratch-Coding-Hut repository run: | - find . -mindepth 1 -maxdepth 1 ! -name ".git" -exec rm -rf {} + + git clone https://github.com/scratch-coding-hut/Scratch-Coding-Hut.git temp-repo + rsync -av --progress temp-repo/ ./ + rm -rf temp-repo - - name: Download and Extract Target Repo - run: | - wget -q https://github.com/Scratch-Coding-Hut/Scratch-Coding-Hut.github.io/archive/refs/heads/main.zip -O main.zip - unzip -q main.zip - rsync -av --progress Scratch-Coding-Hut.github.io-main/ . --exclude .git --delete - rm -rf Scratch-Coding-Hut.github.io-main main.zip - - - name: Configure Git - run: | - git config user.name "github-actions" - git config user.email "github-actions@github.com" - - - name: Commit and Push Changes + - name: Commit and push changes run: | + git config --global user.name 'github-actions[bot]' + git config --global user.email 'github-actions[bot]@users.noreply.github.com' git add . - git diff --quiet && git diff --staged --quiet || git commit -m "Sync data from target repo" + git commit -m "Add content from Scratch-Coding-Hut repo" || echo "No changes to commit" git push From 90cfb48c6d6ef1ca0fac90cb0d72389333109250 Mon Sep 17 00:00:00 2001 From: kRxZykRxZy <192328467+kRxZykRxZy@users.noreply.github.com> Date: Fri, 28 Mar 2025 16:27:07 +0000 Subject: [PATCH 08/22] Update Auto Sync.yml --- .github/workflows/Auto Sync.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/Auto Sync.yml b/.github/workflows/Auto Sync.yml index fe32ecc..ed39cb4 100644 --- a/.github/workflows/Auto Sync.yml +++ b/.github/workflows/Auto Sync.yml @@ -12,6 +12,8 @@ jobs: steps: - name: Checkout the current repository uses: actions/checkout@v3 + with: + persist-credentials: false - name: Clone Scratch-Coding-Hut repository run: | @@ -19,10 +21,13 @@ jobs: rsync -av --progress temp-repo/ ./ rm -rf temp-repo - - name: Commit and push changes + - name: Configure Git run: | git config --global user.name 'github-actions[bot]' git config --global user.email 'github-actions[bot]@users.noreply.github.com' + + - name: Commit and push changes + run: | git add . git commit -m "Add content from Scratch-Coding-Hut repo" || echo "No changes to commit" - git push + git push https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git HEAD:main From e12464cec7add87f76d62b694d33419cdafb7785 Mon Sep 17 00:00:00 2001 From: kRxZykRxZy <192328467+kRxZykRxZy@users.noreply.github.com> Date: Fri, 28 Mar 2025 16:28:41 +0000 Subject: [PATCH 09/22] Update Auto Sync.yml --- .github/workflows/Auto Sync.yml | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/.github/workflows/Auto Sync.yml b/.github/workflows/Auto Sync.yml index ed39cb4..b132b38 100644 --- a/.github/workflows/Auto Sync.yml +++ b/.github/workflows/Auto Sync.yml @@ -13,12 +13,12 @@ jobs: - name: Checkout the current repository uses: actions/checkout@v3 with: - persist-credentials: false + persist-credentials: false # Disables default credentials - name: Clone Scratch-Coding-Hut repository run: | git clone https://github.com/scratch-coding-hut/Scratch-Coding-Hut.git temp-repo - rsync -av --progress temp-repo/ ./ + rsync -av --progress temp-repo/ ./ --exclude .git/ rm -rf temp-repo - name: Configure Git @@ -26,8 +26,13 @@ jobs: git config --global user.name 'github-actions[bot]' git config --global user.email 'github-actions[bot]@users.noreply.github.com' - - name: Commit and push changes + - name: Check for changes run: | git add . - git commit -m "Add content from Scratch-Coding-Hut repo" || echo "No changes to commit" - git push https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git HEAD:main + if ! git diff --cached --quiet; then + echo "Changes detected, committing..." + git commit -m "Add content from Scratch-Coding-Hut repo" + git push https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git HEAD:main + else + echo "No changes to commit" + fi From ff1d86bcff04d75f9752ba55f73d5be49b2f9faa Mon Sep 17 00:00:00 2001 From: kRxZykRxZy <192328467+kRxZykRxZy@users.noreply.github.com> Date: Fri, 28 Mar 2025 16:30:36 +0000 Subject: [PATCH 10/22] Update Auto Sync.yml --- .github/workflows/Auto Sync.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/Auto Sync.yml b/.github/workflows/Auto Sync.yml index b132b38..e8338e3 100644 --- a/.github/workflows/Auto Sync.yml +++ b/.github/workflows/Auto Sync.yml @@ -13,7 +13,7 @@ jobs: - name: Checkout the current repository uses: actions/checkout@v3 with: - persist-credentials: false # Disables default credentials + persist-credentials: false # Disable automatic credentials - name: Clone Scratch-Coding-Hut repository run: | @@ -25,6 +25,7 @@ jobs: run: | git config --global user.name 'github-actions[bot]' git config --global user.email 'github-actions[bot]@users.noreply.github.com' + git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git - name: Check for changes run: | @@ -32,7 +33,7 @@ jobs: if ! git diff --cached --quiet; then echo "Changes detected, committing..." git commit -m "Add content from Scratch-Coding-Hut repo" - git push https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git HEAD:main + git push origin main else echo "No changes to commit" fi From b851df2fbf439bfffed49267114ad4464728978d Mon Sep 17 00:00:00 2001 From: kRxZykRxZy <192328467+kRxZykRxZy@users.noreply.github.com> Date: Fri, 28 Mar 2025 16:32:59 +0000 Subject: [PATCH 11/22] Update Auto Sync.yml --- .github/workflows/Auto Sync.yml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/workflows/Auto Sync.yml b/.github/workflows/Auto Sync.yml index e8338e3..157cf35 100644 --- a/.github/workflows/Auto Sync.yml +++ b/.github/workflows/Auto Sync.yml @@ -13,7 +13,7 @@ jobs: - name: Checkout the current repository uses: actions/checkout@v3 with: - persist-credentials: false # Disable automatic credentials + persist-credentials: false # Disable automatic credentials to use GITHUB_TOKEN manually - name: Clone Scratch-Coding-Hut repository run: | @@ -25,7 +25,6 @@ jobs: run: | git config --global user.name 'github-actions[bot]' git config --global user.email 'github-actions[bot]@users.noreply.github.com' - git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git - name: Check for changes run: | @@ -33,7 +32,13 @@ jobs: if ! git diff --cached --quiet; then echo "Changes detected, committing..." git commit -m "Add content from Scratch-Coding-Hut repo" - git push origin main else echo "No changes to commit" + exit 0 fi + + - name: Push changes to the repository + uses: ad-m/github-push-action@v0.8.0 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + branch: main From 4d1b284da00419d7ffe9c64649319a839ad928da Mon Sep 17 00:00:00 2001 From: kRxZykRxZy <192328467+kRxZykRxZy@users.noreply.github.com> Date: Fri, 28 Mar 2025 16:34:39 +0000 Subject: [PATCH 12/22] Update Auto Sync.yml --- .github/workflows/Auto Sync.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/Auto Sync.yml b/.github/workflows/Auto Sync.yml index 157cf35..9a9674a 100644 --- a/.github/workflows/Auto Sync.yml +++ b/.github/workflows/Auto Sync.yml @@ -38,7 +38,5 @@ jobs: fi - name: Push changes to the repository - uses: ad-m/github-push-action@v0.8.0 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - branch: main + run: | + git push https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git HEAD:main From 0472d480dc06880ee64b7c57d32e5c33a1f34b09 Mon Sep 17 00:00:00 2001 From: kRxZykRxZy <192328467+kRxZykRxZy@users.noreply.github.com> Date: Fri, 28 Mar 2025 16:44:44 +0000 Subject: [PATCH 13/22] Update Auto Sync.yml --- .github/workflows/Auto Sync.yml | 55 ++++++++++++++------------------- 1 file changed, 23 insertions(+), 32 deletions(-) diff --git a/.github/workflows/Auto Sync.yml b/.github/workflows/Auto Sync.yml index 9a9674a..757fb47 100644 --- a/.github/workflows/Auto Sync.yml +++ b/.github/workflows/Auto Sync.yml @@ -1,42 +1,33 @@ -name: Clone Scratch-Coding-Hut Repo +name: Clone and Push Repository on: schedule: - - cron: '*/1 * * * *' # Run every minute - workflow_dispatch: # Allows manual trigger if needed + - cron: '*/1 * * * *' # This cron expression means every minute jobs: - clone-repo: + clone_and_push: runs-on: ubuntu-latest - + steps: - - name: Checkout the current repository - uses: actions/checkout@v3 - with: - persist-credentials: false # Disable automatic credentials to use GITHUB_TOKEN manually - - - name: Clone Scratch-Coding-Hut repository - run: | - git clone https://github.com/scratch-coding-hut/Scratch-Coding-Hut.git temp-repo - rsync -av --progress temp-repo/ ./ --exclude .git/ - rm -rf temp-repo + # Step 1: Checkout the current repository (kRxZykRxZy/Scratch-Coding-Hut) + - name: Checkout the current repository + uses: actions/checkout@v2 - - name: Configure Git - run: | - git config --global user.name 'github-actions[bot]' - git config --global user.email 'github-actions[bot]@users.noreply.github.com' + # Step 2: Clone Scratch-Coding-Hut/Scratch-Coding-Hut repository using PAT + - name: Clone Scratch-Coding-Hut/Scratch-Coding-Hut repository + run: | + git clone https://x-access-token:${{ secrets.MY_GITHUB_TOKEN }}@github.com/Scratch-Coding-Hut/Scratch-Coding-Hut.git + cd Scratch-Coding-Hut - - name: Check for changes - run: | - git add . - if ! git diff --cached --quiet; then - echo "Changes detected, committing..." - git commit -m "Add content from Scratch-Coding-Hut repo" - else - echo "No changes to commit" - exit 0 - fi + # Step 3: Copy files into the current repository, excluding .github folder + - name: Copy files to current repository, excluding .github folder + run: | + shopt -s extglob + cp -r Scratch-Coding-Hut/!(.github) . - - name: Push changes to the repository - run: | - git push https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git HEAD:main + # Step 4: Commit and push the cloned content into kRxZykRxZy/Scratch-Coding-Hut + - name: Commit and push changes to kRxZykRxZy/Scratch-Coding-Hut + run: | + git add . + git commit -m "Cloned contents of Scratch-Coding-Hut/Scratch-Coding-Hut excluding .github folder" + git push https://x-access-token:${{ secrets.MY_GITHUB_TOKEN }}@github.com/kRxZykRxZy/Scratch-Coding-Hut.git main From c8de011c0fb83bff4a252177f4dc3d7c49774686 Mon Sep 17 00:00:00 2001 From: kRxZykRxZy <192328467+kRxZykRxZy@users.noreply.github.com> Date: Fri, 28 Mar 2025 16:50:56 +0000 Subject: [PATCH 14/22] Update Auto Sync.yml --- .github/workflows/Auto Sync.yml | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/.github/workflows/Auto Sync.yml b/.github/workflows/Auto Sync.yml index 757fb47..8c5827f 100644 --- a/.github/workflows/Auto Sync.yml +++ b/.github/workflows/Auto Sync.yml @@ -1,4 +1,4 @@ -name: Clone and Push Repository +name: Clone and Push Repository via Python on: schedule: @@ -13,19 +13,23 @@ jobs: - name: Checkout the current repository uses: actions/checkout@v2 - # Step 2: Clone Scratch-Coding-Hut/Scratch-Coding-Hut repository using PAT - - name: Clone Scratch-Coding-Hut/Scratch-Coding-Hut repository + # Step 2: Set up Python environment + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.x' + + # Step 3: Install required Python dependencies (requests, gitpython) + - name: Install dependencies run: | - git clone https://x-access-token:${{ secrets.MY_GITHUB_TOKEN }}@github.com/Scratch-Coding-Hut/Scratch-Coding-Hut.git - cd Scratch-Coding-Hut + pip install requests gitpython - # Step 3: Copy files into the current repository, excluding .github folder - - name: Copy files to current repository, excluding .github folder + # Step 4: Run the Python script to clone and handle files + - name: Run Python script to clone and manage files run: | - shopt -s extglob - cp -r Scratch-Coding-Hut/!(.github) . + python3 ./clone_and_manage.py - # Step 4: Commit and push the cloned content into kRxZykRxZy/Scratch-Coding-Hut + # Step 5: Commit and push changes to kRxZykRxZy/Scratch-Coding-Hut - name: Commit and push changes to kRxZykRxZy/Scratch-Coding-Hut run: | git add . From 6a057c89a2e6d5cc29782166d8c000f103f25c94 Mon Sep 17 00:00:00 2001 From: kRxZykRxZy <192328467+kRxZykRxZy@users.noreply.github.com> Date: Fri, 28 Mar 2025 16:51:31 +0000 Subject: [PATCH 15/22] Create clone_and_manage.py --- clone_and_manage.py | 47 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 clone_and_manage.py diff --git a/clone_and_manage.py b/clone_and_manage.py new file mode 100644 index 0000000..0d61304 --- /dev/null +++ b/clone_and_manage.py @@ -0,0 +1,47 @@ +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 = os.environ["MY_GITHUB_TOKEN"] # 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 the .github folder +def copy_files(src_dir, dest_dir): + # Iterate over the source directory and copy files, skipping .github + for item in os.listdir(src_dir): + if item != ".github": # Skip the .github 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 + +# Main function +def main(): + # Step 1: Clone the repo + src_repo_dir = clone_repo() + + # Step 2: Prepare the destination path (current repository) + dest_repo_dir = Path(".") # This is the current directory where the GitHub Action is running + + # Step 3: Copy files excluding .github folder + copy_files(src_repo_dir, dest_repo_dir) + + # Step 4: 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() From 8941c0d2b63fbd311cf070b0dc04f8fddbaef54f Mon Sep 17 00:00:00 2001 From: kRxZykRxZy <192328467+kRxZykRxZy@users.noreply.github.com> Date: Fri, 28 Mar 2025 16:54:54 +0000 Subject: [PATCH 16/22] Update clone_and_manage.py --- clone_and_manage.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/clone_and_manage.py b/clone_and_manage.py index 0d61304..dadd413 100644 --- a/clone_and_manage.py +++ b/clone_and_manage.py @@ -17,11 +17,11 @@ def clone_repo(): git.Repo.clone_from(repo_url, repo_dir, depth=1) return repo_dir -# Function to copy files excluding the .github folder +# 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 + # Iterate over the source directory and copy files, skipping .github and .git for item in os.listdir(src_dir): - if item != ".github": # Skip the .github folder + 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(): @@ -29,18 +29,27 @@ def copy_files(src_dir, dest_dir): 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 "github-actions@github.com"') + os.system('git config --global user.name "GitHub Actions"') + # Main function def main(): - # Step 1: Clone the repo + # Step 1: Set Git config + set_git_config() + + # Step 2: Clone the repo src_repo_dir = clone_repo() - # Step 2: Prepare the destination path (current repository) + # Step 3: Prepare the destination path (current repository) dest_repo_dir = Path(".") # This is the current directory where the GitHub Action is running - # Step 3: Copy files excluding .github folder + # Step 4: Copy files excluding .github and .git folders copy_files(src_repo_dir, dest_repo_dir) - # Step 4: Clean up - Remove the cloned repo directory if you don't need it anymore (excluding Python script) + # 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__": From 7703388d288b30e9bfe1d5ff1239b5103c6c8d8b Mon Sep 17 00:00:00 2001 From: kRxZykRxZy <192328467+kRxZykRxZy@users.noreply.github.com> Date: Fri, 28 Mar 2025 17:57:59 +0000 Subject: [PATCH 17/22] Update clone_and_manage.py --- clone_and_manage.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clone_and_manage.py b/clone_and_manage.py index dadd413..4d95641 100644 --- a/clone_and_manage.py +++ b/clone_and_manage.py @@ -6,7 +6,7 @@ # Your GitHub repository URL and token repo_url = "https://github.com/Scratch-Coding-Hut/Scratch-Coding-Hut" -token = os.environ["MY_GITHUB_TOKEN"] # This is your PAT stored as a secret in GitHub +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(): From f1f10b45171f0fe13ffb06bc15fd54fa6d7f70cf Mon Sep 17 00:00:00 2001 From: kRxZykRxZy <192328467+kRxZykRxZy@users.noreply.github.com> Date: Fri, 28 Mar 2025 18:14:53 +0000 Subject: [PATCH 18/22] Update Auto Sync.yml --- .github/workflows/Auto Sync.yml | 39 ++++++++++----------------------- 1 file changed, 11 insertions(+), 28 deletions(-) diff --git a/.github/workflows/Auto Sync.yml b/.github/workflows/Auto Sync.yml index 8c5827f..ec76832 100644 --- a/.github/workflows/Auto Sync.yml +++ b/.github/workflows/Auto Sync.yml @@ -1,37 +1,20 @@ -name: Clone and Push Repository via Python +name: Repo File Sync on: schedule: - - cron: '*/1 * * * *' # This cron expression means every minute + - cron: "*/1 * * * *" # Runs every minute + workflow_dispatch: # Manual trigger if needed jobs: - clone_and_push: + sync: runs-on: ubuntu-latest - + steps: - # Step 1: Checkout the current repository (kRxZykRxZy/Scratch-Coding-Hut) - - name: Checkout the current repository - uses: actions/checkout@v2 + - name: Checkout Source Repo + uses: actions/checkout@v3 - # Step 2: Set up Python environment - - name: Set up Python - uses: actions/setup-python@v2 + - name: Repo File Sync Action + uses: BetaHuhn/repo-file-sync-action@v1.21.1 with: - python-version: '3.x' - - # Step 3: Install required Python dependencies (requests, gitpython) - - name: Install dependencies - run: | - pip install requests gitpython - - # Step 4: Run the Python script to clone and handle files - - name: Run Python script to clone and manage files - run: | - python3 ./clone_and_manage.py - - # Step 5: Commit and push changes to kRxZykRxZy/Scratch-Coding-Hut - - name: Commit and push changes to kRxZykRxZy/Scratch-Coding-Hut - run: | - git add . - git commit -m "Cloned contents of Scratch-Coding-Hut/Scratch-Coding-Hut excluding .github folder" - git push https://x-access-token:${{ secrets.MY_GITHUB_TOKEN }}@github.com/kRxZykRxZy/Scratch-Coding-Hut.git main + GH_PAT: ${{ secrets.PERSONAL_ACCESS_TOKEN }} + CONFIG_PATH: .github/sync-config.yml # Use custom config to sync src From 1cddf3c22fb6f21e473d34b90a27b7031d9ae683 Mon Sep 17 00:00:00 2001 From: kRxZykRxZy <192328467+kRxZykRxZy@users.noreply.github.com> Date: Fri, 28 Mar 2025 18:16:18 +0000 Subject: [PATCH 19/22] Create sync-config.yml --- .github/sync-config.yml | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .github/sync-config.yml diff --git a/.github/sync-config.yml b/.github/sync-config.yml new file mode 100644 index 0000000..1c5f881 --- /dev/null +++ b/.github/sync-config.yml @@ -0,0 +1,7 @@ +repos: + - "kRxZykRxZy/Scratch-Coding-Hut" # Target repo + +files: + - source: "/src" # Sync the entire src folder + dest: "/" # Place it in the root directory of the target repo + delete: true # Set to true if you want to delete extra files in the target repo From fff289e2a3967c5cb32bbec81113cc4469497e5e Mon Sep 17 00:00:00 2001 From: kRxZykRxZy <192328467+kRxZykRxZy@users.noreply.github.com> Date: Fri, 28 Mar 2025 18:20:52 +0000 Subject: [PATCH 20/22] Delete .github/workflows/Auto Sync.yml --- .github/workflows/Auto Sync.yml | 20 -------------------- 1 file changed, 20 deletions(-) delete mode 100644 .github/workflows/Auto Sync.yml diff --git a/.github/workflows/Auto Sync.yml b/.github/workflows/Auto Sync.yml deleted file mode 100644 index ec76832..0000000 --- a/.github/workflows/Auto Sync.yml +++ /dev/null @@ -1,20 +0,0 @@ -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/repo-file-sync-action@v1.21.1 - with: - GH_PAT: ${{ secrets.PERSONAL_ACCESS_TOKEN }} - CONFIG_PATH: .github/sync-config.yml # Use custom config to sync src From f17825864bb4d10210422bb5be376674203c4e7a Mon Sep 17 00:00:00 2001 From: kRxZykRxZy <192328467+kRxZykRxZy@users.noreply.github.com> Date: Fri, 28 Mar 2025 18:21:05 +0000 Subject: [PATCH 21/22] Create Sync.yml --- .github/workflows/Sync.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 .github/workflows/Sync.yml diff --git a/.github/workflows/Sync.yml b/.github/workflows/Sync.yml new file mode 100644 index 0000000..ec76832 --- /dev/null +++ b/.github/workflows/Sync.yml @@ -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/repo-file-sync-action@v1.21.1 + with: + GH_PAT: ${{ secrets.PERSONAL_ACCESS_TOKEN }} + CONFIG_PATH: .github/sync-config.yml # Use custom config to sync src From 6cce6a7308941042ee879a845009ba5b8d991d6f Mon Sep 17 00:00:00 2001 From: kRxZykRxZy <192328467+kRxZykRxZy@users.noreply.github.com> Date: Sat, 29 Mar 2025 07:46:06 +0000 Subject: [PATCH 22/22] Update sync-config.yml --- .github/sync-config.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/sync-config.yml b/.github/sync-config.yml index 1c5f881..424eeb6 100644 --- a/.github/sync-config.yml +++ b/.github/sync-config.yml @@ -1,7 +1,7 @@ repos: - - "kRxZykRxZy/Scratch-Coding-Hut" # Target repo + - "Scratch-Coding-Hut/Scratch-Coding-Hut" # Correct target repo files: - - source: "/src" # Sync the entire src folder - dest: "/" # Place it in the root directory of the target repo - delete: true # Set to true if you want to delete extra files in the target repo + - 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