Skip to content

Sync MD files from dexie-web - Applied patches for: cloud/docs/DexieC… #17

Sync MD files from dexie-web - Applied patches for: cloud/docs/DexieC…

Sync MD files from dexie-web - Applied patches for: cloud/docs/DexieC… #17

Workflow file for this run

name: Sync MD Files to dexie-web-mui
on:
push:
branches: [gh-pages]
paths: ['**/*.md']
jobs:
sync-md-files:
if: false # Workflow disabled
runs-on: ubuntu-latest
steps:
- name: Checkout source repository
uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Get changed MD files
id: changed-files
run: |
CHANGED_FILES=$(git diff --name-only HEAD~1 HEAD | grep '\.md$' || true)
if [ -z "$CHANGED_FILES" ]; then
echo "No .md files have been changed"
echo "has_changes=false" >> $GITHUB_OUTPUT
exit 0
fi
echo "Changed .md files:"
echo "$CHANGED_FILES"
echo "has_changes=true" >> $GITHUB_OUTPUT
echo "$CHANGED_FILES" > changed_files.txt
- name: Generate patches for changed files
if: steps.changed-files.outputs.has_changes == 'true'
run: |
mkdir -p patches
while IFS= read -r file; do
if [ -n "$file" ]; then
echo "Creating patch for: $file"
git diff HEAD~1 HEAD -- "$file" > "patches/${file//\//_}.patch"
if [ -s "patches/${file//\//_}.patch" ]; then
echo "Patch created for $file"
else
echo "Empty patch for $file"
rm -f "patches/${file//\//_}.patch"
fi
fi
done < changed_files.txt
ls -la patches/ || echo "No patches were created"
- name: Checkout target repository
if: steps.changed-files.outputs.has_changes == 'true'
uses: actions/checkout@v4
with:
repository: dexie/dexie-web-mui
token: ${{ secrets.TARGET_REPO_TOKEN }}
path: target-repo
- name: Apply patches to target repository
if: steps.changed-files.outputs.has_changes == 'true'
run: |
cd target-repo
git config user.name "GitHub Action"
git config user.email "action@github.com"
APPLIED_PATCHES=()
FAILED_PATCHES=()
for patch_file in ../patches/*.patch; do
if [ -f "$patch_file" ]; then
original_file=$(basename "$patch_file" .patch | tr '_' '/')
echo "Attempting to apply patch for: $original_file"
if [ -f "$original_file" ]; then
if git apply --check "$patch_file" 2>/dev/null; then
git apply "$patch_file"
git add "$original_file"
APPLIED_PATCHES+=("$original_file")
echo "✓ Patch applied for: $original_file"
else
echo "✗ Patch could not be applied for: $original_file"
FAILED_PATCHES+=("$original_file")
if git apply --3way "$patch_file" 2>/dev/null; then
git add "$original_file"
APPLIED_PATCHES+=("$original_file (3-way merge)")
echo "✓ 3-way merge succeeded for: $original_file"
else
echo "✗ 3-way merge also failed for: $original_file"
fi
fi
else
echo "⚠ Target file does not exist: $original_file"
mkdir -p "$(dirname "$original_file")"
if git apply "$patch_file" 2>/dev/null; then
git add "$original_file"
APPLIED_PATCHES+=("$original_file (new file)")
echo "✓ New file created: $original_file"
else
echo "✗ Could not create new file: $original_file"
FAILED_PATCHES+=("$original_file")
fi
fi
fi
done
echo "=== SUMMARY ==="
echo "Applied patches: ${#APPLIED_PATCHES[@]}"
for file in "${APPLIED_PATCHES[@]}"; do
echo " ✓ $file"
done
echo "Failed patches: ${#FAILED_PATCHES[@]}"
for file in "${FAILED_PATCHES[@]}"; do
echo " ✗ $file"
done
if [ ${#APPLIED_PATCHES[@]} -gt 0 ]; then
APPLIED_LIST=$(printf '%s, ' "${APPLIED_PATCHES[@]}" | sed 's/, $//')
git commit -m "Sync MD files from dexie-website - Applied patches for: $APPLIED_LIST - Source commit: ${{ github.sha }}"
git push
echo "Changes committed and pushed!"
else
echo "No changes to commit"
fi