c5be752e2e gha: Simplify sync.yml according to sync-upstream.sh changes (Tim Ruffing)
260fad30aa sync-upstream: Optionally switch to sync branch (Tim Ruffing)
f0ff45f3ab sync-upstream: Simplify (Tim Ruffing)

Pull request description:

  This is a half-rewrite of the sync-upstream script because I still wasn't happy with it. Looking for early feedback on this.

  Advantages:
   - The script does not hardcode any repo URLs, branches, etc.
   - Nicer separation of responsibilities between the script and the GHA workflow. This brings back the usefulness of the script when used locally outside GHA.
   - Much simpler code, and we could simplify also the GHA workflow.

  Still to do:
   - Rewrite the "Tips" section in the generated PR description, e.g., add how to resolve merge conflicts.
   - Change the GHA workflow accordingly.

ACKs for top commit:
  mllwchrry:
    ACK c5be752

Tree-SHA512: 7335b4690642c07965366da952a74065ec404f750e0c6c7e735a9a48285cbe6b9c7db27ff4bdeba1d5ce59717d77be1ecb2334200b56a1a0a2c0fcddc7530d0b
This commit is contained in:
merge-script
2026-06-02 09:20:18 +02:00
2 changed files with 115 additions and 136 deletions

View File

@@ -9,11 +9,10 @@ jobs:
sync-upstream:
runs-on: ubuntu-latest
env:
UPSTREAM: "https://github.com/bitcoin-core/secp256k1.git"
UPSTREAM_BRANCH: "master"
ORIGIN_BRANCH: "master"
MIN_UPSTREAM_MERGES: 1
UPSTREAM: "https://github.com/bitcoin-core/secp256k1.git"
BASE_BRANCH: "master"
UPSTREAM_REF: "upstream/master"
steps:
- name: Checkout repository
uses: actions/checkout@v6
@@ -26,66 +25,37 @@ jobs:
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Fetch upstream & generate branch name & check for new commits
id: check_commits
env:
GH_TOKEN: ${{ secrets.SYNC_PAT }}
- name: Fetch upstream
run: |
gh repo set-default ${{ github.repository }} # Set the default repo to the origin repository
git remote add upstream ${{ env.UPSTREAM }}
git fetch upstream
MERGES=$(git rev-list --count --merges HEAD..upstream/${{ env.UPSTREAM_BRANCH }})
echo "Found $MERGES new merge commits in upstream."
if [ "$MERGES" -lt ${{ env.MIN_UPSTREAM_MERGES }} ]; then
echo "Exiting."
echo "skip=true" >> "$GITHUB_OUTPUT"
else
echo "skip=false" >> "$GITHUB_OUTPUT"
fi
# Generate a sync branch name "sync-UPSTREAM_HEAD", where UPSTREAM_HEAD is a commit ID.
UPSTREAM_HEAD=$(git rev-parse --short upstream/${{ env.UPSTREAM_BRANCH }})
SYNC_BRANCH="sync-$UPSTREAM_HEAD"
echo "Sync branch name: $SYNC_BRANCH"
echo "SYNC_BRANCH=$SYNC_BRANCH" >> "$GITHUB_ENV"
# Check if the sync branch already exists in the origin repository
if git ls-remote --heads origin "$SYNC_BRANCH" | grep -q "$SYNC_BRANCH"; then
echo "Branch $SYNC_BRANCH already exists. Skipping the sync."
echo "skip=true" >> "$GITHUB_OUTPUT"
else
echo "skip=false" >> "$GITHUB_OUTPUT"
fi
- name: Generate PR metadata
id: branch_pr_metadata
if: steps.check_commits.outputs.skip == 'false'
run: |
# Call the sync script to generate PR title and body
./contrib/sync-upstream.sh -b ${{ env.ORIGIN_BRANCH }} "$SYNC_BRANCH"
- name: Push a sync branch
id: push_branch
if: steps.check_commits.outputs.skip == 'false'
run: |
echo "Creating sync branch: $SYNC_BRANCH"
git checkout upstream/${{ env.UPSTREAM_BRANCH }}
git checkout -b "$SYNC_BRANCH"
git push -u origin "$SYNC_BRANCH"
- name: Create pull request
id: create_pr
if: steps.check_commits.outputs.skip == 'false'
gh repo set-default ${{ github.repository }}
env:
GH_TOKEN: ${{ secrets.SYNC_PAT }}
run: |
# Execute the generated PR creation script
./contrib/gh-pr-create.sh
- name: Cleanup sync branch on failure
if: steps.push_branch.outcome == 'success' && steps.create_pr.outcome == 'failure'
- name: Run sync-upstream.sh
id: sync
run: |
echo "PR creation failed but branch was pushed. Deleting: $SYNC_BRANCH"
git push origin --delete "$SYNC_BRANCH"
OUTPUT=$(./contrib/sync-upstream.sh --switch "${{ env.BASE_BRANCH }}" "${{ env.UPSTREAM_REF }}" 2>&1) || { echo "$OUTPUT"; exit 1; }
echo "$OUTPUT"
if echo "$OUTPUT" | grep -qv "^No merge commits"; then
echo "newcommits=true" >> "$GITHUB_OUTPUT"
else
echo "Skipping further workflow steps."
fi
- name: Push sync branch
id: push
if: steps.sync.outputs.newcommits == 'true'
run: |
if git push -u origin HEAD; then
echo "pushed=true" >> "$GITHUB_OUTPUT"
else
echo "Skipping further workflow steps."
fi
- name: Create pull request
if: steps.sync.outputs.newcommits == 'true' && steps.push.outputs.pushed == 'true'
env:
GH_TOKEN: ${{ secrets.SYNC_PAT }}
run: ./gh-pr-create.sh