Skip to content

feat: rename master branch main (#7) #1

feat: rename master branch main (#7)

feat: rename master branch main (#7) #1

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/
# Switch to main branch
git checkout main
# Sync files to the main working tree
rsync -av --delete --exclude='.git' /tmp/sync_dir/ ./
# Check for changes
if git diff --quiet; then
echo "No changes to commit."
echo "no_changes=true" >> $GITHUB_ENV
else
echo "Changes detected."
git add -A
git commit -am "Sync files from archive branch (excluding .xz files)"
echo "no_changes=false" >> $GITHUB_ENV
fi
- name: Create Pull Request Branch
if: env.no_changes == 'false'
run: |
# Generate a unique branch name to avoid conflicts
BRANCH_NAME="archive-sync-$(date +%s)"
git checkout -b $BRANCH_NAME
git push origin $BRANCH_NAME
echo "branch_name=$BRANCH_NAME" >> $GITHUB_ENV
- name: Create Pull Request
if: env.no_changes == 'false'
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.