-
Notifications
You must be signed in to change notification settings - Fork 2
[DEV-4086] add script, workflow logic and gitignore #204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
MarBert
wants to merge
7
commits into
main
Choose a base branch
from
DEV-4086-add-sync-script-from-main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
af2d221
create empty workflow
MarBert e840855
add script, workflow logic and gitignore
MarBert a98ec82
Apply suggestions from code review
MarBert 8f2f704
fixes required by reviewer
MarBert 5b7ad53
Merge branch 'main' into DEV-4086-add-sync-script-from-main
MarBert 5b6d338
simplify code
MarBert 50c61d0
fixes to naming
MarBert File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,79 @@ | ||
| name: Push documentation on public repository | ||
| name: Push documentation on target 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: 'Target repository branch from which to checkout' | ||
| required: true | ||
| default: 'main' | ||
| type: string | ||
| target_repository: | ||
| description: 'Name of the target repository to push to (owner/repo format)' | ||
| required: true | ||
| default: 'pagopa/developer-portal-docs' | ||
| 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 | ||
| steps: | ||
| - name: Placeholder | ||
| run: echo "No sync steps implemented yet." | ||
| - name: Checkout private repository | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| ref: ${{ inputs.base_branch }} | ||
| path: private_repo | ||
|
|
||
| - name: Checkout target repository | ||
| uses: actions/checkout@v6 | ||
| with: | ||
| ref: ${{ inputs.target_branch }} | ||
| repository: ${{ inputs.target_repository }} | ||
| token: ${{ secrets.PAT }} | ||
| path: target_repo | ||
|
|
||
| - name: Sync Repositories content | ||
| 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 | ||
|
|
||
| - name: Push commit to target repo | ||
| env: | ||
| COMMIT_MESSAGE: ${{ inputs.commit_message }} | ||
| TARGET_BRANCH: ${{ inputs.target_branch }} | ||
| GH_USER_NAME: ${{ vars.GH_USER_NAME }} | ||
| GH_USER_MAIL: ${{ vars.GH_USER_MAIL }} | ||
| run: | | ||
| 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" | ||
| else | ||
| git commit -m "$COMMIT_MESSAGE" | ||
| git push origin "$TARGET_BRANCH" | ||
| fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| .idea/* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| #!/bin/bash | ||
|
|
||
| set -e | ||
|
|
||
| PATHS_TO_ADD="${1:-$PATHS_TO_ADD}" | ||
| PATHS_TO_REMOVE="${2:-$PATHS_TO_REMOVE}" | ||
|
|
||
| validate_path() { | ||
| local p="$1" | ||
| if [[ "$p" == *".."* ]] || [[ "$p" == *"~"* ]] || [[ "$p" == *"//"* ]] || [[ "$p" == /* ]]; then | ||
| echo " [ERROR] Security violation. Unsafe path detected: '$p'." | ||
| echo " Paths cannot contain '..', '~', '//', or start with '/'." | ||
| exit 1 | ||
| fi | ||
| } | ||
|
|
||
| IFS=',' read -r -a add_array <<< "$PATHS_TO_ADD" | ||
| IFS=',' read -r -a remove_array <<< "$PATHS_TO_REMOVE" | ||
|
|
||
| echo "=== Processing paths to ADD ===" | ||
| for path in "${add_array[@]}"; do | ||
| path=$(echo "$path" | xargs) | ||
| if [[ -z "$path" ]]; then continue; fi | ||
| validate_path "$path" | ||
|
|
||
| path="${path#./}" | ||
| path="${path#/}" | ||
|
|
||
| if [[ "$path" == "docs" || "$path" == "docs/" ]]; then | ||
| path="docs" | ||
| elif [[ "$path" != docs/* ]]; then | ||
| path="docs/$path" | ||
| fi | ||
|
|
||
| # Path in target_repo has no docs/ prefix | ||
| if [[ "$path" == "docs" ]]; then | ||
| target_path="." | ||
| else | ||
| target_path="${path#docs/}" | ||
| fi | ||
|
|
||
| echo "-> Handling path: $path (target_repo: $target_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 "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 | ||
| done | ||
|
|
||
| echo "" | ||
| echo "=== Processing paths to REMOVE ===" | ||
| for path in "${remove_array[@]}"; do | ||
| path=$(echo "$path" | xargs) | ||
| if [[ -z "$path" ]]; then continue; fi | ||
| validate_path "$path" | ||
|
|
||
| path="${path#./}" | ||
| path="${path#/}" | ||
|
|
||
| if [[ "$path" == "docs" || "$path" == "docs/" ]]; then | ||
| path="docs" | ||
| elif [[ "$path" != docs/* ]]; then | ||
| path="docs/$path" | ||
| fi | ||
|
Comment on lines
+63
to
+78
|
||
|
|
||
| if [[ "$path" == "docs" ]]; then | ||
| target_path="." | ||
| else | ||
| target_path="${path#docs/}" | ||
| fi | ||
|
|
||
| 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 '$target_path' is not present in target_repo (nothing to do)." | ||
| fi | ||
| done | ||
|
|
||
| echo "" | ||
| echo "=== Operation Completed ===" | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.