Skip to content
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_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