This file contains 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
name: Sync across different OS on specific files | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- '**' | |
paths: | |
- '.github/**' | |
- '.config/nvim/**' | |
- '.config/fish/**' | |
- '.config/tmux/**' | |
- '.config/kitty/**' | |
- '.config/oh-my-posh/**' | |
- '.config/gtk-3.0/**' | |
- '.config/btop/**' | |
env: | |
SYNC_BRANCHES: | | |
master | |
windows | |
ALL_PATHS: | | |
.config/nvim | |
.config/fish | |
.config/tmux | |
.config/kitty | |
.config/oh-my-posh | |
.config/gtk-3.0 | |
.config/btop | |
WINDOWS_SYNC_PATHS: | | |
.config/nvim | |
.config/oh-my-posh | |
jobs: | |
sync-to-other-branches: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Sync to other branches | |
run: | | |
SYNC_BRANCHES=$(echo "$SYNC_BRANCHES" | sed '/^$/d') # Remove empty lines | |
declare -a sync_branches | |
while IFS= read -r line; do | |
sync_branches+=("$line") | |
done <<< "$SYNC_BRANCHES" | |
ALL_PATHS=$(echo "$ALL_PATHS" | sed '/^$/d') # Remove empty lines | |
declare -a sync_branches | |
while IFS= read -r line; do | |
sync_branches+=("$line") | |
done <<< "$ALL_PATHS" | |
WINDOWS_SYNC_PATHS=$(echo "$WINDOWS_SYNC_PATHS" | sed '/^$/d') # Remove empty lines | |
declare -a sync_branches | |
while IFS= read -r line; do | |
sync_branches+=("$line") | |
done <<< "$WINDOWS_SYNC_PATHS" | |
sync_files_from() { | |
for path in "${WATCHED_PATHS[@]}"; do | |
echo "Syncing $path" | |
git checkout $1 -- "${path}" | |
if [ $? -eq 0 ]; then | |
echo -e "Successfully synced $path\n" | |
else | |
echo "Failed to sync $path" | |
fi | |
done | |
} | |
CHANGED_FILES=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }}) | |
echo -e "Changed files: $CHANGED_FILES\n" | |
for branch in "${SYNC_BRANCHES[@]}"; do | |
if [ "$branch" == "${{ github.ref_name }}" ]; then | |
echo "Skipping branch: $branch" | |
continue | |
fi | |
[ "$branch" == "windows" ] && WATCHED_PATHS=("${WINDOWS_SYNC_PATHS[@]}") || WATCHED_PATHS=("${ALL_PATHS[@]}") | |
echo "Checking out to branch: $branch" | |
git checkout "$branch" | |
if [ $? -eq 0 ]; then | |
echo "Successfully checked out to $branch" | |
echo "Sync files from branch ${{ github.ref_name }} to $branch" | |
sync_files_from "${{ github.ref_name }}" | |
git status | |
else | |
echo "Failed to checkout to $branch. Please check if the branch exists." | |
fi | |
done | |