From 77d41e6e8383fb3f1257d5279dd2ed7af074323b Mon Sep 17 00:00:00 2001 From: Marcello Bertoli Date: Thu, 28 May 2026 10:24:10 +0200 Subject: [PATCH 1/5] add full sync script --- .github/workflows/push_on_public_repo.yml | 29 ++++++++++----- scripts/synch_full_repo.sh | 43 +++++++++++++++++++++++ scripts/synch_repo.sh | 0 3 files changed, 64 insertions(+), 8 deletions(-) create mode 100755 scripts/synch_full_repo.sh mode change 100644 => 100755 scripts/synch_repo.sh diff --git a/.github/workflows/push_on_public_repo.yml b/.github/workflows/push_on_public_repo.yml index ef834cbc..da2105ae 100644 --- a/.github/workflows/push_on_public_repo.yml +++ b/.github/workflows/push_on_public_repo.yml @@ -52,27 +52,40 @@ jobs: token: ${{ secrets.PAT }} path: public_repo - - name: Sync Repositories content + - name: Sync Repositories content (Incremental) + if: ${{ inputs.paths_to_add != '' || inputs.paths_to_remove != '' }} 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 + ./scripts/synch_repo.sh + + - name: Sync Repositories content (Full) + if: ${{ inputs.paths_to_add == '' && inputs.paths_to_remove == '' }} + run: | + chmod +x scripts/sync_full_repo.sh + ./scripts/sync_full_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 }} - echo "${{ steps.sync_step.outputs.modified_files }}" | while IFS= read -r file; do - if [[ -n "$file" ]]; then - git add -A -- "$file" - fi - done + if [ -n "${{ inputs.paths_to_add }}" ] || [ -n "${{ inputs.paths_to_remove }}" ]; then + echo "Running partial commit..." + echo "${{ steps.sync_step.outputs.modified_files }}" | while IFS= read -r file; do + if [[ -n "$file" ]]; then + git add -A -- "$file" + fi + done + else + echo "Running full commit..." + git add -A + fi if git diff-index --quiet HEAD; then echo "No updates to commit" diff --git a/scripts/synch_full_repo.sh b/scripts/synch_full_repo.sh new file mode 100755 index 00000000..de2bc0da --- /dev/null +++ b/scripts/synch_full_repo.sh @@ -0,0 +1,43 @@ +#!/bin/bash +set -e + +# --- Configuration --- +# Replace this URL with the actual endpoint +JSON_URL="https://static-contents.developer.pagopa.it/it/dirNames.json" + +# Base paths (ensure the script is run from the repository root, or update the paths accordingly) +PRIVATE_DOCS_DIR="./private_repo/docs" +PUBLIC_DOCS_DIR="./public_repo/docs" + +echo "Downloading JSON file from $JSON_URL..." +JSON_CONTENT=$(curl -s "$JSON_URL") + +echo "Extracting the path list..." +# Extracts strings between quotes, ignores the "dirNames" key, and removes the quotes +PATHS=$(echo "$JSON_CONTENT" | grep -o '"[^"]*"' | grep -v '"dirNames"' | tr -d '"') + +echo "Cleaning up the directory $PUBLIC_DOCS_DIR..." +# Create the directory if it doesn't exist, otherwise empty its contents without deleting the root folder +mkdir -p "$PUBLIC_DOCS_DIR" +rm -rf "${PUBLIC_DOCS_DIR:?}/"* + +echo "Starting file copy..." +for PATH_NAME in $PATHS; do + SRC_DIR="$PRIVATE_DOCS_DIR/$PATH_NAME" + DEST_DIR="$PUBLIC_DOCS_DIR/$PATH_NAME" + + # Check if the directory in the private repo actually exists + if [ -d "$SRC_DIR" ]; then + # Create the destination directory structure + mkdir -p "$DEST_DIR" + + # Copy all contents recursively (preserving permissions) + cp -a "$SRC_DIR/." "$DEST_DIR/" + + echo "Copied: $PATH_NAME" + else + echo "Warning: Directory $SRC_DIR does not exist. Skipping..." + fi +done + +echo "Operation completed successfully!" \ No newline at end of file diff --git a/scripts/synch_repo.sh b/scripts/synch_repo.sh old mode 100644 new mode 100755 From 84e1e722330c37d8630805b6e9ce0e4b784e9867 Mon Sep 17 00:00:00 2001 From: Marcello Bertoli Date: Thu, 28 May 2026 12:43:38 +0200 Subject: [PATCH 2/5] simplify code --- scripts/synch_full_repo.sh | 42 ++++++++++---------------------------- 1 file changed, 11 insertions(+), 31 deletions(-) diff --git a/scripts/synch_full_repo.sh b/scripts/synch_full_repo.sh index de2bc0da..e2822ba0 100755 --- a/scripts/synch_full_repo.sh +++ b/scripts/synch_full_repo.sh @@ -1,43 +1,23 @@ #!/bin/bash set -e -# --- Configuration --- -# Replace this URL with the actual endpoint JSON_URL="https://static-contents.developer.pagopa.it/it/dirNames.json" -# Base paths (ensure the script is run from the repository root, or update the paths accordingly) -PRIVATE_DOCS_DIR="./private_repo/docs" -PUBLIC_DOCS_DIR="./public_repo/docs" +echo "Downloading path list from $JSON_URL..." +PATHS=$(curl -s "$JSON_URL" | grep -o '"[^"]*"' | grep -v '"dirNames"' | tr -d '"') -echo "Downloading JSON file from $JSON_URL..." -JSON_CONTENT=$(curl -s "$JSON_URL") - -echo "Extracting the path list..." -# Extracts strings between quotes, ignores the "dirNames" key, and removes the quotes -PATHS=$(echo "$JSON_CONTENT" | grep -o '"[^"]*"' | grep -v '"dirNames"' | tr -d '"') - -echo "Cleaning up the directory $PUBLIC_DOCS_DIR..." -# Create the directory if it doesn't exist, otherwise empty its contents without deleting the root folder -mkdir -p "$PUBLIC_DOCS_DIR" -rm -rf "${PUBLIC_DOCS_DIR:?}/"* - -echo "Starting file copy..." +echo "Syncing directories..." for PATH_NAME in $PATHS; do - SRC_DIR="$PRIVATE_DOCS_DIR/$PATH_NAME" - DEST_DIR="$PUBLIC_DOCS_DIR/$PATH_NAME" - - # Check if the directory in the private repo actually exists - if [ -d "$SRC_DIR" ]; then - # Create the destination directory structure - mkdir -p "$DEST_DIR" - - # Copy all contents recursively (preserving permissions) - cp -a "$SRC_DIR/." "$DEST_DIR/" + SRC="./private_repo/docs/$PATH_NAME" + DEST="./public_repo/$PATH_NAME" - echo "Copied: $PATH_NAME" + if [ -d "$SRC" ]; then + rm -rf "$DEST" + cp -r "$SRC" "$DEST" + echo "Synced: $PATH_NAME" else - echo "Warning: Directory $SRC_DIR does not exist. Skipping..." + echo "Warning: $SRC does not exist. Skipping..." fi done -echo "Operation completed successfully!" \ No newline at end of file +echo "Done!" \ No newline at end of file From 6170e55f8089b48dfef67e72f05394c3c187fef6 Mon Sep 17 00:00:00 2001 From: Marcello Bertoli Date: Thu, 28 May 2026 12:57:00 +0200 Subject: [PATCH 3/5] fix path to script --- .github/workflows/push_on_public_repo.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/push_on_public_repo.yml b/.github/workflows/push_on_public_repo.yml index c667b6a7..2782a94c 100644 --- a/.github/workflows/push_on_public_repo.yml +++ b/.github/workflows/push_on_public_repo.yml @@ -64,8 +64,8 @@ jobs: - name: Sync Repositories content (Full) if: ${{ inputs.paths_to_add == '' && inputs.paths_to_remove == '' }} run: | - chmod +x scripts/sync_full_repo.sh - ./scripts/sync_full_repo.sh + chmod +x private_repo/scripts/sync_full_repo.sh + ./private_repo/scripts/sync_full_repo.sh - name: Push commit to target repo env: From e28c160174bdd949ceb24a8dee459dd21a92e2ae Mon Sep 17 00:00:00 2001 From: Marcello Bertoli Date: Thu, 28 May 2026 17:11:27 +0200 Subject: [PATCH 4/5] renaming private to source --- .github/workflows/push_on_public_repo.yml | 18 +++++++++--------- scripts/sync_repo.sh | 8 ++++---- scripts/synch_full_repo.sh | 2 +- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/.github/workflows/push_on_public_repo.yml b/.github/workflows/push_on_public_repo.yml index 2782a94c..bccc5c74 100644 --- a/.github/workflows/push_on_public_repo.yml +++ b/.github/workflows/push_on_public_repo.yml @@ -3,8 +3,8 @@ name: Push documentation on target repository on: workflow_dispatch: inputs: - base_branch: - description: 'Private repository branch from which to checkout' + source_branch: + description: 'Source repository branch from which to checkout' required: true default: 'docs/from-gitbook' type: string @@ -38,11 +38,11 @@ jobs: push-to-target: runs-on: ubuntu-latest steps: - - name: Checkout private repository + - name: Checkout source repository uses: actions/checkout@v6 with: - ref: ${{ inputs.base_branch }} - path: private_repo + ref: ${{ inputs.source_branch }} + path: source_repo - name: Checkout target repository uses: actions/checkout@v6 @@ -58,14 +58,14 @@ jobs: PATHS_TO_ADD: ${{ inputs.paths_to_add }} PATHS_TO_REMOVE: ${{ inputs.paths_to_remove }} run: | - chmod +x private_repo/scripts/sync_repo.sh - ./private_repo/scripts/sync_repo.sh + chmod +x source_repo/scripts/sync_repo.sh + ./source_repo/scripts/sync_repo.sh - name: Sync Repositories content (Full) if: ${{ inputs.paths_to_add == '' && inputs.paths_to_remove == '' }} run: | - chmod +x private_repo/scripts/sync_full_repo.sh - ./private_repo/scripts/sync_full_repo.sh + chmod +x source_repo/scripts/sync_full_repo.sh + ./source_repo/scripts/sync_full_repo.sh - name: Push commit to target repo env: diff --git a/scripts/sync_repo.sh b/scripts/sync_repo.sh index b28be987..f7797f6b 100644 --- a/scripts/sync_repo.sh +++ b/scripts/sync_repo.sh @@ -46,12 +46,12 @@ for path in "${add_array[@]}"; do rm -rf "target_repo/$target_path" fi - if [[ -e "private_repo/$path" ]]; then - echo " Found in private_repo. Copying..." + if [[ -e "source_repo/$path" ]]; then + echo " Found in source_repo. Copying..." mkdir -p "target_repo/$(dirname "$target_path")" - cp -r "private_repo/$path" "target_repo/$target_path" + cp -r "source_repo/$path" "target_repo/$target_path" else - echo " Warning: Path '$path' does not exist in private_repo." + echo " Warning: Path '$path' does not exist in source_repo." fi done diff --git a/scripts/synch_full_repo.sh b/scripts/synch_full_repo.sh index e2822ba0..b89edcc4 100755 --- a/scripts/synch_full_repo.sh +++ b/scripts/synch_full_repo.sh @@ -8,7 +8,7 @@ PATHS=$(curl -s "$JSON_URL" | grep -o '"[^"]*"' | grep -v '"dirNames"' | tr -d ' echo "Syncing directories..." for PATH_NAME in $PATHS; do - SRC="./private_repo/docs/$PATH_NAME" + SRC="./source_repo/docs/$PATH_NAME" DEST="./public_repo/$PATH_NAME" if [ -d "$SRC" ]; then From 4c07bf71805cff58e00fa915a068cd0bc0f6e38b Mon Sep 17 00:00:00 2001 From: Marcello Bertoli Date: Thu, 28 May 2026 17:12:14 +0200 Subject: [PATCH 5/5] add newline at EOF --- scripts/sync_repo.sh | 2 +- scripts/synch_full_repo.sh | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/sync_repo.sh b/scripts/sync_repo.sh index f7797f6b..4de2f745 100644 --- a/scripts/sync_repo.sh +++ b/scripts/sync_repo.sh @@ -87,4 +87,4 @@ for path in "${remove_array[@]}"; do done echo "" -echo "=== Operation Completed ===" \ No newline at end of file +echo "=== Operation Completed ===" diff --git a/scripts/synch_full_repo.sh b/scripts/synch_full_repo.sh index b89edcc4..a7531dba 100755 --- a/scripts/synch_full_repo.sh +++ b/scripts/synch_full_repo.sh @@ -20,4 +20,5 @@ for PATH_NAME in $PATHS; do fi done -echo "Done!" \ No newline at end of file +echo "" +echo "=== Operation Completed ==="