diff --git a/.github/workflows/push_on_public_repo.yml b/.github/workflows/push_on_public_repo.yml index 6e44aed1..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 - uses: actions/checkout@v4 + - 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 @@ -52,13 +52,20 @@ jobs: token: ${{ secrets.PAT }} path: target_repo - - name: Sync Repositories content + - name: Sync Repositories content (Incremental) + if: ${{ inputs.paths_to_add != '' || inputs.paths_to_remove != '' }} env: 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 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..4de2f745 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 @@ -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 new file mode 100755 index 00000000..a7531dba --- /dev/null +++ b/scripts/synch_full_repo.sh @@ -0,0 +1,24 @@ +#!/bin/bash +set -e + +JSON_URL="https://static-contents.developer.pagopa.it/it/dirNames.json" + +echo "Downloading path list from $JSON_URL..." +PATHS=$(curl -s "$JSON_URL" | grep -o '"[^"]*"' | grep -v '"dirNames"' | tr -d '"') + +echo "Syncing directories..." +for PATH_NAME in $PATHS; do + SRC="./source_repo/docs/$PATH_NAME" + DEST="./public_repo/$PATH_NAME" + + if [ -d "$SRC" ]; then + rm -rf "$DEST" + cp -r "$SRC" "$DEST" + echo "Synced: $PATH_NAME" + else + echo "Warning: $SRC does not exist. Skipping..." + fi +done + +echo "" +echo "=== Operation Completed ==="