Skip to content

Upstream Sync (v4-web Release Triggered) #12

Upstream Sync (v4-web Release Triggered)

Upstream Sync (v4-web Release Triggered) #12

Workflow file for this run

name: Upstream Sync (v4-web Release Triggered)
on:
schedule:
- cron: '0 3 * * *' # 3:00:00am daily
workflow_dispatch:
jobs:
sync:
runs-on: ubuntu-latest
steps:
- name: Checkout fork main
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: main
- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Add upstream remote
run: git remote add upstream https://github.com/dydxprotocol/v4-web.git
- name: Fetch upstream
run: git fetch upstream --tags
#######################################################################
# Detect new upstream release
#######################################################################
- name: Get latest upstream release tag
id: upstream_tag
run: |
TAG=$(git ls-remote --tags upstream | grep -o 'refs/tags/.*' | sed 's|refs/tags/||' | sort -V | tail -n1)
echo "tag=$TAG" >> $GITHUB_OUTPUT
- name: Get latest local release tag
id: local_tag
run: |
TAG=$(git tag --sort=version:refname | tail -n1)
echo "tag=${TAG:-none}" >> $GITHUB_OUTPUT
- name: Compare release tags
id: compare
run: |
if [ "${{ steps.upstream_tag.outputs.tag }}" = "${{ steps.local_tag.outputs.tag }}" ]; then
echo "no_update=true" >> $GITHUB_OUTPUT
else
echo "no_update=false" >> $GITHUB_OUTPUT
fi
- name: Stop if no new upstream release
if: steps.compare.outputs.no_update == 'true'
run: echo "No new upstream release. Exiting..."
#######################################################################
# Rebase + squash fork custom changes on top of upstream/main
#######################################################################
- name: Create sync branch
if: steps.compare.outputs.no_update == 'false'
run: |
BRANCH="sync/upstream-$(date +'%Y-%m-%d')"
echo "BRANCH=$BRANCH" >> $GITHUB_ENV
git checkout -b $BRANCH
- name: Rebase main onto upstream/main
if: steps.compare.outputs.no_update == 'false'
run: |
git rebase upstream/main || true
- name: Squash fork changes into one commit
if: steps.compare.outputs.no_update == 'false'
run: |
git reset --soft upstream/main
git commit -m "Fork custom changes (squashed)"
- name: Push sync branch
if: steps.compare.outputs.no_update == 'false'
run: git push origin $BRANCH --force
#######################################################################
# Create Pull Request
#######################################################################
- name: Create Pull Request
if: steps.compare.outputs.no_update == 'false'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh pr create \
--base main \
--head $BRANCH \
--title "chore: Sync Upstream Release → Fork (Rebase + Squash)" \
--body "A new upstream release (**${{ steps.upstream_tag.outputs.tag }}**) was detected.\n\n
This PR:\n
- Rebases fork changes on top of upstream/main\n
- Squashes fork custom modifications into a single commit\n
- Automatically opens for manual review + merge\n
_Generated by GitHub Actions._"