phasicFlow/.github/workflows/sync-wiki.yml

97 lines
3.6 KiB
YAML

name: Sync README files to Wiki
on:
push:
branches: [ main ]
paths:
- '**/README.md'
- '**/readme.md'
permissions:
contents: write
jobs:
sync-wiki:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Configure Git for Wiki
run: |
git config --global user.name "GitHub Actions"
git config --global user.email "actions@github.com"
- name: Clone Wiki Repository
run: git clone https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.wiki.git ./wiki
- name: Copy README files to Wiki
run: |
# Special mappings - add specific README files to specific wiki pages
declare -A special_mappings
special_mappings["benchmarks/rotatingDrum/readme.md"]="Performance-of-phasicFlow.md"
# Create an images directory in the wiki if it doesn't exist
mkdir -p ./wiki/images
# Process mapped files
for rel_path in "${!special_mappings[@]}"; do
if [ -f "./$rel_path" ]; then
wiki_page="${special_mappings[$rel_path]}"
echo "Processing special mapping: $rel_path -> $wiki_page"
# Get the base directory of the readme file
base_dir=$(dirname "./$rel_path")
# Read content of the README file
content=$(cat "./$rel_path")
# Process image references line by line for more reliable detection
while IFS= read -r line; do
if [[ $line =~ !\[([^]]*)\]\(([^)]+)\) ]]; then
img_path="${BASH_REMATCH[2]}"
# Skip URLs
if [[ $img_path == http* ]]; then
continue
fi
# Determine the absolute path of the image
if [[ $img_path == /* ]]; then
# Absolute path within repository
abs_img_path="./$img_path"
else
# Relative path to the README
abs_img_path="$base_dir/$img_path"
fi
# Extract just the filename
img_filename=$(basename "$img_path")
wiki_img_path="images/$img_filename"
# Copy the image to wiki repository if it exists
if [ -f "$abs_img_path" ]; then
echo "Copying image: $abs_img_path -> ./wiki/$wiki_img_path"
cp "$abs_img_path" "./wiki/$wiki_img_path"
# Replace the image reference in content using a safer delimiter
content=$(echo "$content" | sed "s|!\\[\(.*\\)\\]($img_path)|![\\1]($wiki_img_path)|g")
echo "Replaced image reference: $img_path → $wiki_img_path"
else
echo "Warning: Image file not found: $abs_img_path"
fi
fi
done < "./$rel_path"
# Replace the wiki page with the updated content rather than appending
echo -e "# $(basename "$wiki_page" .md)\n\nContent from $rel_path:\n\n$content" > "./wiki/$wiki_page"
echo "Updated wiki page: $wiki_page"
fi
done
- name: Commit and Push to Wiki
working-directory: ./wiki
run: |
git add .
git diff-index --quiet HEAD || git commit -m "Sync README files from main repository"
git push