diff --git a/.github/workflows/sync-from-java.yml b/.github/workflows/sync-from-java.yml index ddb94b0..54ee9de 100644 --- a/.github/workflows/sync-from-java.yml +++ b/.github/workflows/sync-from-java.yml @@ -1,7 +1,12 @@ -name: Sync from Java Repo (Manual) +name: Sync to Java Repo on: - workflow_dispatch: + push: + branches: + - main + paths: + - 'sync_folder/**' # Only trigger when files in sync_folder change. More foldes and files can be added later. + workflow_dispatch: jobs: sync: @@ -11,24 +16,30 @@ jobs: uses: actions/checkout@v4 with: path: python-repo - + - name: Checkout Java Repo uses: actions/checkout@v4 with: repository: SikandarEjaz/RepoSyncTestJava token: ${{ secrets.SYNC_TOKEN }} path: java-repo - - - name: Sync files from Java + + - name: Sync files run: | - mkdir -p python-repo/synced-from-java - cp -r java-repo/sync_folder/* python-repo/synced-from-java/ - - - name: Commit and Push + # Copy files from Python repo to Java repo + mkdir -p java-repo/synced-from-python + # Check if sync_folder exists and has files + if [ -d "python-repo/sync_folder" ] && [ "$(ls -A python-repo/sync_folder)" ]; then + cp -r python-repo/sync_folder/* java-repo/synced-from-python/ + else + echo "sync_folder is empty or doesn't exist" + fi + + - name: Commit and Push to Java Repo run: | - cd python-repo + cd java-repo git config user.name "GitHub Action" git config user.email "action@github.com" git add . - git diff --quiet && git diff --staged --quiet || git commit -m "Manual sync from Java repo" - git push + git diff --quiet && git diff --staged --quiet || git commit -m "Sync from Python repo [automated]" + git push \ No newline at end of file diff --git a/sync_folder/PythonFile.txt b/sync_folder/PythonFile.txt new file mode 100644 index 0000000..8fb3cc5 --- /dev/null +++ b/sync_folder/PythonFile.txt @@ -0,0 +1 @@ +This is a file in Python repo for testing synchronisation with the Java repo. \ No newline at end of file diff --git a/synced-from-java/AnotherFile.txt b/synced-from-java/AnotherFile.txt new file mode 100644 index 0000000..d31a878 --- /dev/null +++ b/synced-from-java/AnotherFile.txt @@ -0,0 +1 @@ +This is another Text file for testing the synchronisation between the repositories. \ No newline at end of file diff --git a/synced-from-java/YetAnotherFile.txt b/synced-from-java/YetAnotherFile.txt new file mode 100644 index 0000000..ec03e99 --- /dev/null +++ b/synced-from-java/YetAnotherFile.txt @@ -0,0 +1 @@ +This is another file to test syncrinisation between Java-Python repo. \ No newline at end of file diff --git a/synced-from-java/test.txt b/synced-from-java/test.txt new file mode 100644 index 0000000..aef26c2 --- /dev/null +++ b/synced-from-java/test.txt @@ -0,0 +1 @@ +This is atest foile for testing synchronisation bewteen Java and Pyhton repositories. \ No newline at end of file