gha: Simplify sync.yml according to sync-upstream.sh changes
This commit is contained in:
92
.github/workflows/sync.yml
vendored
92
.github/workflows/sync.yml
vendored
@@ -9,11 +9,10 @@ jobs:
|
|||||||
sync-upstream:
|
sync-upstream:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
env:
|
env:
|
||||||
UPSTREAM: "https://github.com/bitcoin-core/secp256k1.git"
|
UPSTREAM: "https://github.com/bitcoin-core/secp256k1.git"
|
||||||
UPSTREAM_BRANCH: "master"
|
BASE_BRANCH: "master"
|
||||||
ORIGIN_BRANCH: "master"
|
UPSTREAM_REF: "upstream/master"
|
||||||
MIN_UPSTREAM_MERGES: 1
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v6
|
uses: actions/checkout@v6
|
||||||
@@ -26,66 +25,37 @@ jobs:
|
|||||||
git config user.name "github-actions[bot]"
|
git config user.name "github-actions[bot]"
|
||||||
git config user.email "github-actions[bot]@users.noreply.github.com"
|
git config user.email "github-actions[bot]@users.noreply.github.com"
|
||||||
|
|
||||||
- name: Fetch upstream & generate branch name & check for new commits
|
- name: Fetch upstream
|
||||||
id: check_commits
|
|
||||||
env:
|
|
||||||
GH_TOKEN: ${{ secrets.SYNC_PAT }}
|
|
||||||
run: |
|
run: |
|
||||||
gh repo set-default ${{ github.repository }} # Set the default repo to the origin repository
|
|
||||||
git remote add upstream ${{ env.UPSTREAM }}
|
git remote add upstream ${{ env.UPSTREAM }}
|
||||||
git fetch upstream
|
git fetch upstream
|
||||||
|
gh repo set-default ${{ github.repository }}
|
||||||
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'
|
|
||||||
env:
|
env:
|
||||||
GH_TOKEN: ${{ secrets.SYNC_PAT }}
|
GH_TOKEN: ${{ secrets.SYNC_PAT }}
|
||||||
run: |
|
|
||||||
# Execute the generated PR creation script
|
|
||||||
./contrib/gh-pr-create.sh
|
|
||||||
|
|
||||||
- name: Cleanup sync branch on failure
|
- name: Run sync-upstream.sh
|
||||||
if: steps.push_branch.outcome == 'success' && steps.create_pr.outcome == 'failure'
|
id: sync
|
||||||
run: |
|
run: |
|
||||||
echo "PR creation failed but branch was pushed. Deleting: $SYNC_BRANCH"
|
OUTPUT=$(./contrib/sync-upstream.sh --switch "${{ env.BASE_BRANCH }}" "${{ env.UPSTREAM_REF }}" 2>&1) || { echo "$OUTPUT"; exit 1; }
|
||||||
git push origin --delete "$SYNC_BRANCH"
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user