Skip to content

feat: stop creating branch if no diff (#8) #2

feat: stop creating branch if no diff (#8)

feat: stop creating branch if no diff (#8) #2

name: Sync archive to main
on:
push:
branches:
- archive
jobs:
create-pull-request:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Git
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Filter and copy files
run: |
# Create a temporary directory for syncing files
mkdir -p /tmp/sync_dir
# Switch to archive branch and copy files excluding .git and .xz files
git checkout archive
rsync -av --exclude='.git' --exclude='*.xz' ./ /tmp/sync_dir/
# Generate a unique branch name to avoid conflicts
BRANCH_NAME="archive-sync-$(date +%s)"
# Switch to pull request branch
git checkout main
git checkout -b $BRANCH_NAME
# Sync files to the main working tree
rsync -av --delete --exclude='.git' /tmp/sync_dir/ ./
git add -A
git commit --allow-empty -am "Sync files from archive branch (excluding .xz files)"
if git diff --quiet HEAD main; then
echo "branch_name=" >> $GITHUB_ENV
else
git push origin $BRANCH_NAME
echo "branch_name=$BRANCH_NAME" >> $GITHUB_ENV
fi
- name: Create Pull Request
if: env.branch_name != ''
uses: peter-evans/create-pull-request@v5
with:
token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ env.branch_name }}
base: main
title: "Sync files from archive branch (excluding .xz files)"
body: |
This pull request syncs files from the `archive` branch to the `main` branch.
**Note**: Files with the `.xz` extension are excluded.