Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions .github/workflows/backport-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Backport Conflict Check

on:
pull_request:
types: [labeled, synchronize]

jobs:
check-backport:
runs-on: ubuntu-latest
steps:
- name: Extract backport label
id: extract
run: |
echo 'Extracting backport label...'
version=$(jq -r '
.pull_request.labels // []
| map(.name // empty)
| map(select(startswith("backport ")))
| first // ""
| sub("^backport "; "")
' "$GITHUB_EVENT_PATH")

if [[ -z "$version" || "$version" == "null" ]]; then
echo "No backport label found. Skipping."
echo "version=" >> "$GITHUB_OUTPUT"
exit 0
fi

echo "Backport version: '$version'"
echo "version=$version" >> "$GITHUB_OUTPUT"

- name: Checkout backport target branch (from upstream)
if: ${{ steps.extract.outputs.version != '' }}
run: |
git init .
git remote add upstream https://github.com/opensearch-project/OpenSearch.git
git fetch upstream ${{ steps.extract.outputs.version }}
git checkout -b backport-target FETCH_HEAD

git remote add prrepo https://github.com/${{ github.event.pull_request.head.repo.full_name }}.git
git fetch prrepo ${{ github.event.pull_request.head.ref }}

- name: Set git identity
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"

- name: Attempt cherry-pick of PR commits
if: ${{ steps.extract.outputs.version != '' }}
run: |
set -o pipefail
{
git cherry-pick ${{ github.event.pull_request.head.sha }}
} &> err.log || {
cat err.log > conflict.txt
exit 1
}

- name: Report conflicts as PR comment
if: ${{ steps.extract.outputs.version != '' && failure() }}
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
let conflictMsg = "⚠️ Backport conflict detected for branch `${{ steps.extract.outputs.version }}`\n";
if (fs.existsSync('conflict.txt')) {
const conflicts = fs.readFileSync('conflict.txt', 'utf8');
conflictMsg += "```\n" + conflicts + "\n```";
}
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: conflictMsg
});