From af2d2215bf0417635ae1e8effe7109ed8416d11f Mon Sep 17 00:00:00 2001 From: Marcello Bertoli Date: Wed, 27 May 2026 17:12:10 +0200 Subject: [PATCH 1/6] create empty workflow --- .github/workflows/push_on_public_repo.yml | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 .github/workflows/push_on_public_repo.yml diff --git a/.github/workflows/push_on_public_repo.yml b/.github/workflows/push_on_public_repo.yml new file mode 100644 index 00000000..ad7cdcb8 --- /dev/null +++ b/.github/workflows/push_on_public_repo.yml @@ -0,0 +1,8 @@ +name: Push documentation on public repository + +on: + workflow_dispatch: + +jobs: + push-to-target: + runs-on: ubuntu-latest \ No newline at end of file From e84085558fbc698bbe2e2058326119d5830d1159 Mon Sep 17 00:00:00 2001 From: Marcello Bertoli Date: Thu, 28 May 2026 09:33:13 +0200 Subject: [PATCH 2/6] add script, workflow logic and gitignore --- .github/workflows/push_on_public_repo.yml | 76 +++++++++++++- .gitignore | 1 + scripts/synch_repo.sh | 116 ++++++++++++++++++++++ 3 files changed, 192 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100644 scripts/synch_repo.sh diff --git a/.github/workflows/push_on_public_repo.yml b/.github/workflows/push_on_public_repo.yml index ad7cdcb8..ef834cbc 100644 --- a/.github/workflows/push_on_public_repo.yml +++ b/.github/workflows/push_on_public_repo.yml @@ -2,7 +2,81 @@ name: Push documentation on public repository on: workflow_dispatch: + inputs: + base_branch: + description: 'Private repository branch from which to checkout' + required: true + default: 'docs/from-gitbook' + type: string + target_branch: + description: 'Public repository branch from which to checkout' + required: true + default: 'main' + type: string + public_repository: + description: 'Name of the public repository to push to (owner/repo format)' + required: true + default: 'pagopa/public_doc' + type: string + commit_message: + description: 'Custom commit message' + required: false + default: 'Update documentation' + type: string + paths_to_add: + description: 'Comma-separated list of paths to add' + required: false + default: '' + type: string + paths_to_remove: + description: 'Comma-separated list of paths to remove' + required: false + default: '' + type: string jobs: push-to-target: - runs-on: ubuntu-latest \ No newline at end of file + runs-on: ubuntu-latest + steps: + - name: Checkout private repository + uses: actions/checkout@v4 + with: + ref: ${{ inputs.base_branch }} + path: private_repo + + - name: Checkout public repository + uses: actions/checkout@v4 + with: + ref: ${{ inputs.target_branch }} + repository: ${{ inputs.public_repository }} + token: ${{ secrets.PAT }} + path: public_repo + + - name: Sync Repositories content + id: sync_step + env: + PATHS_TO_ADD: ${{ inputs.paths_to_add }} + PATHS_TO_REMOVE: ${{ inputs.paths_to_remove }} + run: | + chmod +x scripts/synch_repo.sh + ./scripts/synch_repo.sh + + - name: Push commit to public repo + run: | + cd public-repo + + git config user.name ${{ vars.GH_USER_NAME }} + git config user.email ${{ vars.GH_MAIL }} + + echo "${{ steps.sync_step.outputs.modified_files }}" | while IFS= read -r file; do + if [[ -n "$file" ]]; then + git add -A -- "$file" + fi + done + + if git diff-index --quiet HEAD; then + echo "No updates to commit" + else + git commit -m "${{ inputs.commit_message || 'update documentation' }}" + git push origin ${{ inputs.target_branch }} + fi \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..bc8a670e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea/* \ No newline at end of file diff --git a/scripts/synch_repo.sh b/scripts/synch_repo.sh new file mode 100644 index 00000000..3fb50982 --- /dev/null +++ b/scripts/synch_repo.sh @@ -0,0 +1,116 @@ +#!/bin/bash + +# Exit immediately if a command exits with a non-zero status +set -e + +# Fetch inputs (accepts environment variables or positional parameters) +PATHS_TO_ADD="${1:-$PATHS_TO_ADD}" +PATHS_TO_REMOVE="${2:-$PATHS_TO_REMOVE}" + +# File to store the list of copied files +MODIFIED_FILES_LIST="MODIFIED_FILES_LIST.txt" +: > "$MODIFIED_FILES_LIST" # Empty or create the file on startup + +validate_path() { + local p="$1" + # Reject traversal (..), home directory (~), double slashes (//), and absolute paths (leading /) + if [[ "$p" == *".."* ]] || [[ "$p" == *"~"* ]] || [[ "$p" == *"//"* ]] || [[ "$p" == /* ]]; then + echo " [ERROR] Security violation. Unsafe path detected: '$p'." + echo " Paths cannot contain '..', '~', '//', or start with '/'." + exit 1 # Abort the entire script to prevent accidental deletions + fi +} + +# Set internal field separator to comma (,) to split inputs into arrays +IFS=',' read -r -a add_array <<< "$PATHS_TO_ADD" +IFS=',' read -r -a remove_array <<< "$PATHS_TO_REMOVE" + +echo "=== Processing paths to ADD (paths_to_add) ===" +for path in "${add_array[@]}"; do + # Remove leading/trailing whitespaces (trim) + path=$(echo "$path" | xargs) + + # Skip iteration if the path is empty + if [[ -z "$path" ]]; then continue; fi + + validate_path "$path" + + # Strip leading './' or '/' if present + path="${path#./}" + path="${path#/}" + + # Handle 'docs' prefix safely + if [[ "$path" == "docs" || "$path" == "docs/" ]]; then + path="docs" + elif [[ "$path" != docs/* ]]; then + path="docs/$path" + fi + + echo "-> Handling path: $path" + + # 1. Search inside public_repo; if found, delete recursively + if [[ -e "public_repo/$path" ]]; then + echo " Found in public_repo. Deleting..." + rm -rf "public_repo/$path" + fi + + # 2. Search inside private_repo, explore recursively and copy files + if [[ -e "private_repo/$path" ]]; then + echo " Found in private_repo. Copying files..." + + # Enter private_repo so 'find' returns easy-to-use relative paths + ( + cd private_repo || exit 1 + # Find only files (-type f) to exactly recreate the folder structure + find "$path" -type f | while read -r file; do + + # Create the destination folder structure in public_repo + mkdir -p "../public_repo/$(dirname "$file")" + + # Copy the single file + cp "$file" "../public_repo/$file" + + # Register the file in the list (saving the relative path) + echo "$file" >> "../$MODIFIED_FILES_LIST" + done + ) + else + echo " Warning: Path '$path' does not exist in private_repo." + fi +done + +echo "" +echo "=== Processing paths to REMOVE (paths_to_remove) ===" +for path in "${remove_array[@]}"; do + path=$(echo "$path" | xargs) + if [[ -z "$path" ]]; then continue; fi + validate_path "$path" + if [[ "$path" != docs/* ]]; then + path="docs/$path" + fi + echo "-> Handling path: $path" + if [[ -e "public_repo/$path" ]]; then + echo " Deleting $path from public_repo..." + find "public_repo/$path" -type f | sed 's|^public_repo/||' >> "$MODIFIED_FILES_LIST" + rm -rf "public_repo/$path" + else + echo " Path '$path' is not present in public_repo (nothing to do)." + fi +done + +echo "" +echo "=== Operation Completed. List of copied files: ===" +if [[ -s "$MODIFIED_FILES_LIST" ]]; then + cat "$MODIFIED_FILES_LIST" +else + echo "No files modified." +fi + +# Write the multiline output for GitHub Actions +if [[ -n "$GITHUB_OUTPUT" ]]; then + echo "Setting GitHub Actions output 'modified_files'..." + # Using the EOF syntax to safely pass multiline strings to GITHUB_OUTPUT + echo "modified_files<> "$GITHUB_OUTPUT" + cat "$MODIFIED_FILES_LIST" >> "$GITHUB_OUTPUT" + echo "EOF" >> "$GITHUB_OUTPUT" +fi \ No newline at end of file From a98ec826cb30596a5c6e269eae654a449b9a4f2e Mon Sep 17 00:00:00 2001 From: MarBert <41899883+MarBert@users.noreply.github.com> Date: Thu, 28 May 2026 10:30:06 +0200 Subject: [PATCH 3/6] Apply suggestions from code review Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Co-authored-by: Sebastiano Bertolin <56671015+Sebastiano-Bertolin@users.noreply.github.com> --- .github/workflows/push_on_public_repo.yml | 14 +++++++------- .gitignore | 2 +- scripts/synch_repo.sh | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/push_on_public_repo.yml b/.github/workflows/push_on_public_repo.yml index ef834cbc..4885ef24 100644 --- a/.github/workflows/push_on_public_repo.yml +++ b/.github/workflows/push_on_public_repo.yml @@ -45,7 +45,7 @@ jobs: path: private_repo - name: Checkout public repository - uses: actions/checkout@v4 + uses: actions/checkout@v6 with: ref: ${{ inputs.target_branch }} repository: ${{ inputs.public_repository }} @@ -58,15 +58,15 @@ jobs: PATHS_TO_ADD: ${{ inputs.paths_to_add }} PATHS_TO_REMOVE: ${{ inputs.paths_to_remove }} run: | - chmod +x scripts/synch_repo.sh - ./scripts/synch_repo.sh + chmod +x private_repo/scripts/synch_repo.sh + ./private_repo/scripts/synch_repo.sh - name: Push commit to public repo run: | - cd public-repo + cd public_repo - git config user.name ${{ vars.GH_USER_NAME }} - git config user.email ${{ vars.GH_MAIL }} + git config user.name "${{ vars.GH_USER_NAME }}" + git config user.email "${{ vars.GH_MAIL }}" echo "${{ steps.sync_step.outputs.modified_files }}" | while IFS= read -r file; do if [[ -n "$file" ]]; then @@ -77,6 +77,6 @@ jobs: if git diff-index --quiet HEAD; then echo "No updates to commit" else - git commit -m "${{ inputs.commit_message || 'update documentation' }}" + git commit -m "${{ inputs.commit_message }}" git push origin ${{ inputs.target_branch }} fi \ No newline at end of file diff --git a/.gitignore b/.gitignore index bc8a670e..1c2d52b6 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1 @@ -.idea/* \ No newline at end of file +.idea/* diff --git a/scripts/synch_repo.sh b/scripts/synch_repo.sh index 3fb50982..9354ae19 100644 --- a/scripts/synch_repo.sh +++ b/scripts/synch_repo.sh @@ -113,4 +113,4 @@ if [[ -n "$GITHUB_OUTPUT" ]]; then echo "modified_files<> "$GITHUB_OUTPUT" cat "$MODIFIED_FILES_LIST" >> "$GITHUB_OUTPUT" echo "EOF" >> "$GITHUB_OUTPUT" -fi \ No newline at end of file +fi From 8f2f7042c45fc4a3a0785bacb1921be409ce1d07 Mon Sep 17 00:00:00 2001 From: Marcello Bertoli Date: Thu, 28 May 2026 10:54:00 +0200 Subject: [PATCH 4/6] fixes required by reviewer --- .github/workflows/push_on_public_repo.yml | 25 +++++++++++++++-------- scripts/{synch_repo.sh => sync_repo.sh} | 9 +++++++- 2 files changed, 25 insertions(+), 9 deletions(-) rename scripts/{synch_repo.sh => sync_repo.sh} (95%) diff --git a/.github/workflows/push_on_public_repo.yml b/.github/workflows/push_on_public_repo.yml index 4885ef24..136dc7b8 100644 --- a/.github/workflows/push_on_public_repo.yml +++ b/.github/workflows/push_on_public_repo.yml @@ -58,25 +58,34 @@ jobs: PATHS_TO_ADD: ${{ inputs.paths_to_add }} PATHS_TO_REMOVE: ${{ inputs.paths_to_remove }} run: | - chmod +x private_repo/scripts/synch_repo.sh - ./private_repo/scripts/synch_repo.sh + chmod +x private_repo/scripts/sync_repo.sh + ./private_repo/scripts/sync_repo.sh - name: Push commit to public repo + env: + MODIFIED_FILES: ${{ steps.sync_step.outputs.modified_files }} + COMMIT_MESSAGE: ${{ inputs.commit_message }} + TARGET_BRANCH: ${{ inputs.target_branch }} + GH_USER: ${{ vars.GH_USER_NAME }} + GH_MAIL: ${{ vars.GH_MAIL }} run: | cd public_repo - git config user.name "${{ vars.GH_USER_NAME }}" - git config user.email "${{ vars.GH_MAIL }}" + # Read from the safe environment variables + git config user.name "$GH_USER" + git config user.email "$GH_MAIL" - echo "${{ steps.sync_step.outputs.modified_files }}" | while IFS= read -r file; do + # Use <<< to feed the environment variable safely into the while loop + while IFS= read -r file; do if [[ -n "$file" ]]; then git add -A -- "$file" fi - done + done <<< "$MODIFIED_FILES" if git diff-index --quiet HEAD; then echo "No updates to commit" else - git commit -m "${{ inputs.commit_message }}" - git push origin ${{ inputs.target_branch }} + # Safely commit and push using environment variables + git commit -m "$COMMIT_MESSAGE" + git push origin "$TARGET_BRANCH" fi \ No newline at end of file diff --git a/scripts/synch_repo.sh b/scripts/sync_repo.sh similarity index 95% rename from scripts/synch_repo.sh rename to scripts/sync_repo.sh index 9354ae19..4c243f82 100644 --- a/scripts/synch_repo.sh +++ b/scripts/sync_repo.sh @@ -85,9 +85,16 @@ for path in "${remove_array[@]}"; do path=$(echo "$path" | xargs) if [[ -z "$path" ]]; then continue; fi validate_path "$path" - if [[ "$path" != docs/* ]]; then + + path="${path#./}" + path="${path#/}" + + if [[ "$path" == "docs" || "$path" == "docs/" ]]; then + path="docs" + elif [[ "$path" != docs/* ]]; then path="docs/$path" fi + echo "-> Handling path: $path" if [[ -e "public_repo/$path" ]]; then echo " Deleting $path from public_repo..." From 5b6d33810c6f4ab33293ea2dcb246dc5cd683d83 Mon Sep 17 00:00:00 2001 From: Marcello Bertoli Date: Thu, 28 May 2026 12:35:17 +0200 Subject: [PATCH 5/6] simplify code --- .github/workflows/push_on_public_repo.yml | 14 +--- scripts/sync_repo.sh | 93 ++++++++--------------- 2 files changed, 31 insertions(+), 76 deletions(-) diff --git a/.github/workflows/push_on_public_repo.yml b/.github/workflows/push_on_public_repo.yml index b255039f..1df675f6 100644 --- a/.github/workflows/push_on_public_repo.yml +++ b/.github/workflows/push_on_public_repo.yml @@ -53,7 +53,6 @@ jobs: path: public_repo - name: Sync Repositories content - id: sync_step env: PATHS_TO_ADD: ${{ inputs.paths_to_add }} PATHS_TO_REMOVE: ${{ inputs.paths_to_remove }} @@ -63,29 +62,18 @@ jobs: - name: Push commit to public repo env: - MODIFIED_FILES: ${{ steps.sync_step.outputs.modified_files }} COMMIT_MESSAGE: ${{ inputs.commit_message }} TARGET_BRANCH: ${{ inputs.target_branch }} GH_USER: ${{ vars.GH_USER_NAME }} GH_MAIL: ${{ vars.GH_MAIL }} run: | cd public_repo - - # Read from the safe environment variables git config user.name "$GH_USER" git config user.email "$GH_MAIL" - - # Use <<< to feed the environment variable safely into the while loop - while IFS= read -r file; do - if [[ -n "$file" ]]; then - git add -A -- "$file" - fi - done <<< "$MODIFIED_FILES" - + git add -A if git diff-index --quiet HEAD; then echo "No updates to commit" else - # Safely commit and push using environment variables git commit -m "$COMMIT_MESSAGE" git push origin "$TARGET_BRANCH" fi diff --git a/scripts/sync_repo.sh b/scripts/sync_repo.sh index 4c243f82..1a365487 100644 --- a/scripts/sync_repo.sh +++ b/scripts/sync_repo.sh @@ -1,86 +1,62 @@ #!/bin/bash -# Exit immediately if a command exits with a non-zero status set -e -# Fetch inputs (accepts environment variables or positional parameters) PATHS_TO_ADD="${1:-$PATHS_TO_ADD}" PATHS_TO_REMOVE="${2:-$PATHS_TO_REMOVE}" -# File to store the list of copied files -MODIFIED_FILES_LIST="MODIFIED_FILES_LIST.txt" -: > "$MODIFIED_FILES_LIST" # Empty or create the file on startup - validate_path() { local p="$1" - # Reject traversal (..), home directory (~), double slashes (//), and absolute paths (leading /) if [[ "$p" == *".."* ]] || [[ "$p" == *"~"* ]] || [[ "$p" == *"//"* ]] || [[ "$p" == /* ]]; then echo " [ERROR] Security violation. Unsafe path detected: '$p'." echo " Paths cannot contain '..', '~', '//', or start with '/'." - exit 1 # Abort the entire script to prevent accidental deletions + exit 1 fi } -# Set internal field separator to comma (,) to split inputs into arrays IFS=',' read -r -a add_array <<< "$PATHS_TO_ADD" IFS=',' read -r -a remove_array <<< "$PATHS_TO_REMOVE" -echo "=== Processing paths to ADD (paths_to_add) ===" +echo "=== Processing paths to ADD ===" for path in "${add_array[@]}"; do - # Remove leading/trailing whitespaces (trim) path=$(echo "$path" | xargs) - - # Skip iteration if the path is empty if [[ -z "$path" ]]; then continue; fi - validate_path "$path" - # Strip leading './' or '/' if present path="${path#./}" path="${path#/}" - # Handle 'docs' prefix safely if [[ "$path" == "docs" || "$path" == "docs/" ]]; then path="docs" elif [[ "$path" != docs/* ]]; then path="docs/$path" fi - echo "-> Handling path: $path" + # Path in public_repo has no docs/ prefix + if [[ "$path" == "docs" ]]; then + public_path="." + else + public_path="${path#docs/}" + fi + + echo "-> Handling path: $path (public_repo: $public_path)" - # 1. Search inside public_repo; if found, delete recursively - if [[ -e "public_repo/$path" ]]; then + if [[ -e "public_repo/$public_path" ]]; then echo " Found in public_repo. Deleting..." - rm -rf "public_repo/$path" + rm -rf "public_repo/$public_path" fi - # 2. Search inside private_repo, explore recursively and copy files if [[ -e "private_repo/$path" ]]; then - echo " Found in private_repo. Copying files..." - - # Enter private_repo so 'find' returns easy-to-use relative paths - ( - cd private_repo || exit 1 - # Find only files (-type f) to exactly recreate the folder structure - find "$path" -type f | while read -r file; do - - # Create the destination folder structure in public_repo - mkdir -p "../public_repo/$(dirname "$file")" - - # Copy the single file - cp "$file" "../public_repo/$file" - - # Register the file in the list (saving the relative path) - echo "$file" >> "../$MODIFIED_FILES_LIST" - done - ) + echo " Found in private_repo. Copying..." + mkdir -p "public_repo/$(dirname "$public_path")" + cp -r "private_repo/$path" "public_repo/$public_path" else echo " Warning: Path '$path' does not exist in private_repo." fi done echo "" -echo "=== Processing paths to REMOVE (paths_to_remove) ===" +echo "=== Processing paths to REMOVE ===" for path in "${remove_array[@]}"; do path=$(echo "$path" | xargs) if [[ -z "$path" ]]; then continue; fi @@ -90,34 +66,25 @@ for path in "${remove_array[@]}"; do path="${path#/}" if [[ "$path" == "docs" || "$path" == "docs/" ]]; then - path="docs" + path="docs" elif [[ "$path" != docs/* ]]; then - path="docs/$path" + path="docs/$path" + fi + + if [[ "$path" == "docs" ]]; then + public_path="." + else + public_path="${path#docs/}" fi - echo "-> Handling path: $path" - if [[ -e "public_repo/$path" ]]; then - echo " Deleting $path from public_repo..." - find "public_repo/$path" -type f | sed 's|^public_repo/||' >> "$MODIFIED_FILES_LIST" - rm -rf "public_repo/$path" + echo "-> Handling path: $path (public_repo: $public_path)" + if [[ -e "public_repo/$public_path" ]]; then + echo " Deleting $public_path from public_repo..." + rm -rf "public_repo/$public_path" else - echo " Path '$path' is not present in public_repo (nothing to do)." + echo " Path '$public_path' is not present in public_repo (nothing to do)." fi done echo "" -echo "=== Operation Completed. List of copied files: ===" -if [[ -s "$MODIFIED_FILES_LIST" ]]; then - cat "$MODIFIED_FILES_LIST" -else - echo "No files modified." -fi - -# Write the multiline output for GitHub Actions -if [[ -n "$GITHUB_OUTPUT" ]]; then - echo "Setting GitHub Actions output 'modified_files'..." - # Using the EOF syntax to safely pass multiline strings to GITHUB_OUTPUT - echo "modified_files<> "$GITHUB_OUTPUT" - cat "$MODIFIED_FILES_LIST" >> "$GITHUB_OUTPUT" - echo "EOF" >> "$GITHUB_OUTPUT" -fi +echo "=== Operation Completed ===" \ No newline at end of file From 50c61d0a95d9b846e2c69ae7be85f2e621a90639 Mon Sep 17 00:00:00 2001 From: Marcello Bertoli Date: Thu, 28 May 2026 12:52:56 +0200 Subject: [PATCH 6/6] fixes to naming --- .github/workflows/push_on_public_repo.yml | 28 ++++++++++---------- scripts/sync_repo.sh | 32 +++++++++++------------ 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/.github/workflows/push_on_public_repo.yml b/.github/workflows/push_on_public_repo.yml index 1df675f6..6e44aed1 100644 --- a/.github/workflows/push_on_public_repo.yml +++ b/.github/workflows/push_on_public_repo.yml @@ -1,4 +1,4 @@ -name: Push documentation on public repository +name: Push documentation on target repository on: workflow_dispatch: @@ -9,14 +9,14 @@ on: default: 'docs/from-gitbook' type: string target_branch: - description: 'Public repository branch from which to checkout' + description: 'Target repository branch from which to checkout' required: true default: 'main' type: string - public_repository: - description: 'Name of the public repository to push to (owner/repo format)' + target_repository: + description: 'Name of the target repository to push to (owner/repo format)' required: true - default: 'pagopa/public_doc' + default: 'pagopa/developer-portal-docs' type: string commit_message: description: 'Custom commit message' @@ -44,13 +44,13 @@ jobs: ref: ${{ inputs.base_branch }} path: private_repo - - name: Checkout public repository + - name: Checkout target repository uses: actions/checkout@v6 with: ref: ${{ inputs.target_branch }} - repository: ${{ inputs.public_repository }} + repository: ${{ inputs.target_repository }} token: ${{ secrets.PAT }} - path: public_repo + path: target_repo - name: Sync Repositories content env: @@ -60,16 +60,16 @@ jobs: chmod +x private_repo/scripts/sync_repo.sh ./private_repo/scripts/sync_repo.sh - - name: Push commit to public repo + - name: Push commit to target repo env: COMMIT_MESSAGE: ${{ inputs.commit_message }} TARGET_BRANCH: ${{ inputs.target_branch }} - GH_USER: ${{ vars.GH_USER_NAME }} - GH_MAIL: ${{ vars.GH_MAIL }} + GH_USER_NAME: ${{ vars.GH_USER_NAME }} + GH_USER_MAIL: ${{ vars.GH_USER_MAIL }} run: | - cd public_repo - git config user.name "$GH_USER" - git config user.email "$GH_MAIL" + cd target_repo + git config user.name "$GH_USER_NAME" + git config user.email "$GH_USER_MAIL" git add -A if git diff-index --quiet HEAD; then echo "No updates to commit" diff --git a/scripts/sync_repo.sh b/scripts/sync_repo.sh index 1a365487..b28be987 100644 --- a/scripts/sync_repo.sh +++ b/scripts/sync_repo.sh @@ -32,24 +32,24 @@ for path in "${add_array[@]}"; do path="docs/$path" fi - # Path in public_repo has no docs/ prefix + # Path in target_repo has no docs/ prefix if [[ "$path" == "docs" ]]; then - public_path="." + target_path="." else - public_path="${path#docs/}" + target_path="${path#docs/}" fi - echo "-> Handling path: $path (public_repo: $public_path)" + echo "-> Handling path: $path (target_repo: $target_path)" - if [[ -e "public_repo/$public_path" ]]; then - echo " Found in public_repo. Deleting..." - rm -rf "public_repo/$public_path" + if [[ -e "target_repo/$target_path" ]]; then + echo " Found in target_repo. Deleting..." + rm -rf "target_repo/$target_path" fi if [[ -e "private_repo/$path" ]]; then echo " Found in private_repo. Copying..." - mkdir -p "public_repo/$(dirname "$public_path")" - cp -r "private_repo/$path" "public_repo/$public_path" + mkdir -p "target_repo/$(dirname "$target_path")" + cp -r "private_repo/$path" "target_repo/$target_path" else echo " Warning: Path '$path' does not exist in private_repo." fi @@ -72,17 +72,17 @@ for path in "${remove_array[@]}"; do fi if [[ "$path" == "docs" ]]; then - public_path="." + target_path="." else - public_path="${path#docs/}" + target_path="${path#docs/}" fi - echo "-> Handling path: $path (public_repo: $public_path)" - if [[ -e "public_repo/$public_path" ]]; then - echo " Deleting $public_path from public_repo..." - rm -rf "public_repo/$public_path" + echo "-> Handling path: $path (target_repo: $target_path)" + if [[ -e "target_repo/$target_path" ]]; then + echo " Deleting $target_path from target_repo..." + rm -rf "target_repo/$target_path" else - echo " Path '$public_path' is not present in public_repo (nothing to do)." + echo " Path '$target_path' is not present in target_repo (nothing to do)." fi done