forked from opendatahub-io/odh-model-controller
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprow-merge-incubating-with-main.yaml
More file actions
69 lines (56 loc) · 2.06 KB
/
prow-merge-incubating-with-main.yaml
File metadata and controls
69 lines (56 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
name: "Prow merge incubating to main"
on:
workflow_dispatch:
concurrency:
group: sync-incubating-to-main
cancel-in-progress: false
env:
SOURCE_BRANCH: "incubating"
TARGET_BRANCH: "main"
permissions:
contents: write
pull-requests: write
jobs:
auto-merge:
if: github.ref == 'refs/heads/incubating'
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Create sync PR instead of direct push
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
git fetch origin "$TARGET_BRANCH"
git fetch origin "$SOURCE_BRANCH"
# Skip if nothing to merge
if git merge-base --is-ancestor "origin/$SOURCE_BRANCH" "origin/$TARGET_BRANCH"; then
echo "Nothing to merge — $SOURCE_BRANCH is already merged into $TARGET_BRANCH"
exit 0
fi
# Skip if a sync PR already exists
SYNC_BRANCH="sync/merge-${SOURCE_BRANCH}-to-${TARGET_BRANCH}"
EXISTING_PR=$(gh pr list --base "$TARGET_BRANCH" --head "$SYNC_BRANCH" --state open --json number -q '.[0].number' || true)
if [ -n "$EXISTING_PR" ]; then
echo "Sync PR already exists: #$EXISTING_PR"
exit 0
fi
# Configure git
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# Create sync branch and merge
git checkout -b "$SYNC_BRANCH" "origin/$TARGET_BRANCH"
git merge --no-ff "origin/$SOURCE_BRANCH"
# Push and create PR
git push --force origin "$SYNC_BRANCH"
PR_URL=$(gh pr create \
--base "$TARGET_BRANCH" \
--head "$SYNC_BRANCH" \
--title "Merge $SOURCE_BRANCH to $TARGET_BRANCH" \
--body "Automated merge of $SOURCE_BRANCH into $TARGET_BRANCH" \
--label "tide/merge-method-merge")
echo "Created sync PR: $PR_URL"