Skip to content

Sync README Sections from Multiple Repositories #522

Sync README Sections from Multiple Repositories

Sync README Sections from Multiple Repositories #522

Workflow file for this run

name: Sync README Sections from Multiple Repositories
on:
push:
branches:
- main
workflow_dispatch:
schedule:
- cron: '0 0 * * *'
permissions:
contents: write
jobs:
sync-readmes:
runs-on: ubuntu-latest
steps:
- name: Checkout Target Repository
uses: actions/checkout@v3
- name: Clone Source Repositories
run: |
git clone https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/tiktok-privacy-innovation/PETAce.git petace-repo
git clone https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/tiktok-privacy-innovation/shadowgraphy.git shadowgraphy-repo
git clone https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/tiktok-privacy-innovation/PETAce-Solo.git petace-solo-repo
git clone https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/tiktok-privacy-innovation/PETAce-Verse.git petace-verse-repo
git clone https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/tiktok-privacy-innovation/PETAce-Duet.git petace-duet-repo
git clone https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/tiktok-privacy-innovation/PETAce-SetOps.git petace-setops-repo
git clone https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/tiktok-privacy-innovation/PETAce-Network.git petace-network-repo
- name: Extract and Sync README Sections
id: sync
run: |
sources=(
"petace-repo/README.md"
"petace-repo/README.md"
"petace-solo-repo/README.md"
"petace-solo-repo/README.md"
"petace-verse-repo/README.md"
"petace-verse-repo/README.md"
"petace-duet-repo/README.md"
"petace-duet-repo/README.md"
"petace-setops-repo/README.md"
"petace-setops-repo/README.md"
"petace-network-repo/README.md"
"petace-network-repo/README.md"
"shadowgraphy-repo/README.md"
)
targets=(
"content/en/docs/petace/Overview/_index.md"
"content/en/docs/petace/Getting started/_index.md"
"content/en/docs/petace/PETAce-Solo/Overview/_index.md"
"content/en/docs/petace/PETAce-Solo/Getting started/_index.md"
"content/en/docs/petace/PETAce-Verse/Overview/_index.md"
"content/en/docs/petace/PETAce-Verse/Getting started/_index.md"
"content/en/docs/petace/PETAce-Duet/Overview/_index.md"
"content/en/docs/petace/PETAce-Duet/Getting started/_index.md"
"content/en/docs/petace/PETAce-SetOps/Overview/_index.md"
"content/en/docs/petace/PETAce-SetOps/Getting started/_index.md"
"content/en/docs/petace/PETAce-Network/Overview/_index.md"
"content/en/docs/petace/PETAce-Network/Getting started/_index.md"
"content/en/docs/shadowgraphy/overview/_index.md"
)
source_start_markers=(
"<!-- start-petace-overview -->"
"<!-- start-petace-getting-started -->"
"<!-- start-petace-solo-overview -->"
"<!-- start-petace-solo-getting-started -->"
"<!-- start-petace-verse-overview -->"
"<!-- start-petace-verse-getting-started -->"
"<!-- start-petace-duet-overview -->"
"<!-- start-petace-duet-getting-started -->"
"<!-- start-petace-setops-overview -->"
"<!-- start-petace-setops-getting-started -->"
"<!-- start-petace-network-overview -->"
"<!-- start-petace-network-getting-started -->"
"<!-- start-shadowgraphy-overview -->"
)
source_end_markers=(
"<!-- end-petace-overview -->"
"<!-- end-petace-getting-started -->"
"<!-- end-petace-solo-overview -->"
"<!-- end-petace-solo-getting-started -->"
"<!-- end-petace-verse-overview -->"
"<!-- end-petace-verse-getting-started -->"
"<!-- end-petace-duet-overview -->"
"<!-- end-petace-duet-getting-started -->"
"<!-- end-petace-setops-overview -->"
"<!-- end-petace-setops-getting-started -->"
"<!-- end-petace-network-overview -->"
"<!-- end-petace-network-getting-started -->"
"<!-- end-shadowgraphy-overview -->"
)
target_start_markers=(
"<!-- start-petace-overview -->"
"<!-- start-petace-getting-started -->"
"<!-- start-petace-solo-overview -->"
"<!-- start-petace-solo-getting-started -->"
"<!-- start-petace-verse-overview -->"
"<!-- start-petace-verse-getting-started -->"
"<!-- start-petace-duet-overview -->"
"<!-- start-petace-duet-getting-started -->"
"<!-- start-petace-setops-overview -->"
"<!-- start-petace-setops-getting-started -->"
"<!-- start-petace-network-overview -->"
"<!-- start-petace-network-getting-started -->"
"<!-- start-shadowgraphy-overview -->"
)
target_end_markers=(
"<!-- end-petace-overview -->"
"<!-- end-petace-getting-started -->"
"<!-- end-petace-solo-overview -->"
"<!-- end-petace-solo-getting-started -->"
"<!-- end-petace-verse-overview -->"
"<!-- end-petace-verse-getting-started -->"
"<!-- end-petace-duet-overview -->"
"<!-- end-petace-duet-getting-started -->"
"<!-- end-petace-setops-overview -->"
"<!-- end-petace-setops-getting-started -->"
"<!-- end-petace-network-overview -->"
"<!-- end-petace-network-getting-started -->"
"<!-- end-shadowgraphy-overview -->"
)
extract_content() {
local source_file=$1
local start_marker=$2
local end_marker=$3
awk -v start="$start_marker" -v end="$end_marker" '
$0 ~ start, $0 ~ end {if ($0 !~ start && $0 !~ end) print}
' "$source_file"
}
replace_in_file() {
local target_file=$1
local start_marker=$2
local end_marker=$3
local new_content=$4
awk -v start="$start_marker" -v end="$end_marker" -v content="$new_content" '
$0 ~ start {print; print content; in_block=1; next}
in_block && $0 ~ end {in_block=0; print end; next}
!in_block {print}
' "$target_file" > tmpfile && mv tmpfile "$target_file"
}
changes_made=false
for i in "${!sources[@]}"; do
source_file="${sources[$i]}"
target="${targets[$i]}"
source_start_marker="${source_start_markers[$i]}"
source_end_marker="${source_end_markers[$i]}"
target_start_marker="${target_start_markers[$i]}"
target_end_marker="${target_end_markers[$i]}"
new_content=$(extract_content "$source_file" "$source_start_marker" "$source_end_marker")
current_content=$(awk -v start="$target_start_marker" -v end="$target_end_marker" '
$0 ~ start {in_block=1; next}
in_block && $0 ~ end {in_block=0}
in_block {print}
' "$target")
if [ "$new_content" != "$current_content" ]; then
changes_made=true
replace_in_file "$target" "$target_start_marker" "$target_end_marker" "$new_content"
echo "Synced section from $source_file to $target between $target_start_marker and $target_end_marker"
else
echo "No changes for section in $source_file"
fi
done
echo "changes_made=$changes_made" >> $GITHUB_ENV
- name: Commit Changes
if: env.changes_made == 'true'
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add .
git commit -m "Automated sync of README sections from multiple repositories"
git push