Skip to content

Sync upstream master & tags #393

Sync upstream master & tags

Sync upstream master & tags #393

Workflow file for this run

name: Sync upstream master & tags
on:
schedule:
- cron: '0 3 * * *'
workflow_dispatch:
jobs:
sync-upstream:
runs-on: ubuntu-latest
steps:
- name: Checkout fork's master branch
uses: actions/checkout@v6
with:
ref: master
fetch-depth: 0
token: ${{ secrets.GH_PAT_PUSH_TOKEN }}
- name: Set up git user
run: |
git config user.name "GitHub Actions"
git config user.email "actions@github.com"
- name: Add upstream remote
run: git remote add upstream https://github.com/trezor/blockbook.git
- name: Fetch upstream changes & tags
run: git fetch upstream --tags --prune
- name: Sync master with upstream (preserve .github/)
run: |
set -euo pipefail
git checkout master
BEFORE=$(git rev-parse HEAD)
# Nothing to do if fork already contains all upstream commits
if git merge-base --is-ancestor upstream/master HEAD; then
echo "Already up to date."
exit 0
fi
# --- Try a clean merge first --------------------------------
if ! git merge --no-edit upstream/master; then
echo "::warning::Merge conflict detected — resolving automatically"
# Resolve every conflicted file:
# .github/* → keep ours (fork's version)
# everything → take theirs (upstream's version)
git diff --name-only --diff-filter=U | while IFS= read -r file; do
if [[ "$file" == .github/* ]]; then
echo " [keep ours] $file"
git checkout --ours -- "$file" 2>/dev/null \
|| git rm -f -- "$file" 2>/dev/null || true
else
echo " [take theirs] $file"
git checkout --theirs -- "$file" 2>/dev/null \
|| git rm -f -- "$file" 2>/dev/null || true
fi
done
git add -A
GIT_EDITOR=true git merge --continue
fi
# --- Restore fork's .github/ directory ----------------------
git checkout "$BEFORE" -- .github/ 2>/dev/null || true
# Remove any .github/ files that only exist because upstream added them
ADDED=$(comm -13 \
<(git ls-tree -r --name-only "$BEFORE" -- .github/ 2>/dev/null | sort) \
<(git ls-tree -r --name-only HEAD -- .github/ 2>/dev/null | sort))
if [ -n "$ADDED" ]; then
echo "Removing upstream .github files:"
echo "$ADDED"
echo "$ADDED" | xargs -r git rm -f
fi
# Amend the merge commit if .github/ was touched
if ! git diff --staged --quiet 2>/dev/null; then
git commit --amend --no-edit
fi
- name: Push master & tags
run: |
git push origin master
git push origin --tags