Skip to content

Commit 67b84f2

Browse files
committed
[CIR][Github][CI] Add clangir upstream rebase workflow
1 parent ac090d5 commit 67b84f2

File tree

3 files changed

+154
-0
lines changed

3 files changed

+154
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Clang CIR Rebase
2+
3+
on: workflow_dispatch
4+
5+
permissions:
6+
contents: write
7+
8+
env:
9+
UPSTREAM_REPO: https://github.com/llvm/llvm-project.git
10+
TARGET_BRANCH: rebased-${{ github.head_ref || github.ref_name }}
11+
12+
jobs:
13+
rebase:
14+
name: Rebase Clang CIR onto LLVM upstream
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 0
21+
token: ${{ secrets.WORKFLOW_TOKEN }}
22+
23+
- name: Set up Git user
24+
run: |
25+
git config --global user.name "github-actions[bot]"
26+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
27+
28+
- name: Add upstream remote
29+
run: |
30+
git remote add upstream $UPSTREAM_REPO
31+
git fetch upstream main
32+
33+
- name: Rebase CIR branch onto LLVM upstream
34+
run: |
35+
sh ./.github/workflows/rebase-clangir-onto-llvm-upstream.sh $TARGET_BRANCH
36+
37+
- name: Push rebase branch ${{ github.env.TARGET_BRANCH }}
38+
run: |
39+
git push --set-upstream origin ${{ github.env.TARGET_BRANCH }}
40+
41+
test-clang-cir:
42+
name: Test Clang CIR
43+
needs: rebase
44+
uses: ./.github/workflows/llvm-project-tests.yml
45+
with:
46+
build_target: check-clang-cir
47+
projects: clang;mlir
48+
extra_cmake_args: -DCLANG_ENABLE_CIR=ON
49+
repo_ref: ${{ github.env.TARGET_BRANCH }}

.github/workflows/llvm-project-tests.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ on:
5151
type: string
5252
default: '3.11'
5353

54+
# Optional reference to the branch being checked out.
55+
# Uses the current branch if not specified.
56+
repo_ref:
57+
required: false
58+
type: string
59+
5460
concurrency:
5561
# Skip intermediate builds: always.
5662
# Cancel intermediate builds: only if it is a pull request build.
@@ -93,6 +99,7 @@ jobs:
9399
# clean: false.
94100
- uses: actions/checkout@v4
95101
with:
102+
ref: ${{ inputs.repo_ref || github.ref }}
96103
fetch-depth: 250
97104
- name: Setup ccache
98105
uses: hendrikmuhs/ccache-action@v1
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
GREEN='\033[0;32m'
6+
RED='\033[0;31m'
7+
YELLOW='\033[1;33m'
8+
NC='\033[0m'
9+
10+
REBASE_BRANCH=rebased-clangir-onto-llvm-upstream
11+
TARGET_BRANCH=$1
12+
13+
log() { printf "%b[%s]%b %s\n" "$1" "$2" "$NC" "$3"; }
14+
log_info() { log "$GREEN" "INFO" "$1"; }
15+
log_warn() { log "$YELLOW" "WARN" "$1"; }
16+
log_error() { log "$RED" "ERROR" "$1" >&2; }
17+
18+
error_exit() {
19+
log_error "$1"
20+
exit 1
21+
}
22+
23+
is_rebasing() {
24+
git rev-parse --git-path rebase-merge >/dev/null 2>&1 ||
25+
git rev-parse --git-path rebase-apply >/dev/null 2>&1
26+
}
27+
28+
git rev-parse --is-inside-work-tree >/dev/null 2>&1 ||
29+
error_exit "Not in a Git repository."
30+
31+
git remote get-url upstream >/dev/null 2>&1 ||
32+
error_exit "Upstream remote not found."
33+
34+
log_info "Fetching latest changes from upstream..."
35+
36+
git fetch upstream main ||
37+
error_exit "Failed to fetch from upstream."
38+
39+
REBASING_CIR_BRANCH=$(git branch --show-current)
40+
41+
if [ -z "$COMMON_ANCESTOR" ]; then
42+
COMMON_ANCESTOR=$(git merge-base upstream/main "$REBASING_CIR_BRANCH") ||
43+
error_exit "Could not find common ancestor."
44+
log_info "Common ancestor commit: $COMMON_ANCESTOR"
45+
fi
46+
47+
if [ "$REBASING_CIR_BRANCH" != "$REBASE_BRANCH" ]; then
48+
if git rev-parse --verify "$REBASE_BRANCH" >/dev/null 2>&1; then
49+
git branch -D "$REBASE_BRANCH" >/dev/null 2>&1 ||
50+
log_warn "Failed to delete existing branch $REBASE_BRANCH."
51+
fi
52+
53+
git switch -c "$REBASE_BRANCH" "$COMMON_ANCESTOR" ||
54+
error_exit "Failed to create branch $REBASE_BRANCH."
55+
fi
56+
57+
#
58+
# Rebase upstream changes
59+
#
60+
log_info "Processing upstream commits..."
61+
git rebase upstream/main ||
62+
error_exit "Failed to rebase."
63+
64+
#
65+
# Reverse upstream CIR commits
66+
#
67+
log_info "Reverting upstream CIR commits..."
68+
git log --grep="\[CIR\]" --format="%H %s" "$COMMON_ANCESTOR..upstream/main" | while read -r HASH MESSAGE; do
69+
log_info "Reverting: $MESSAGE"
70+
71+
if ! git revert --no-edit "$HASH"; then
72+
error_exit "Failed to revert commit $HASH"
73+
fi
74+
done
75+
76+
#
77+
# Rebase CIR commits
78+
#
79+
log_info "Rebasing CIR incubator commits..."
80+
81+
if [ -z "$TARGET_BRANCH" ]; then
82+
log_error "Target branch not specified."
83+
exit 1
84+
fi
85+
86+
if git rev-parse --verify "$TARGET_BRANCH" >/dev/null 2>&1; then
87+
git branch -D "$TARGET_BRANCH" >/dev/null 2>&1 ||
88+
error_exit "Failed to delete existing branch $TARGET_BRANCH."
89+
fi
90+
91+
git switch "$REBASING_CIR_BRANCH" ||
92+
error_exit "Failed to switch to $REBASING_CIR_BRANCH."
93+
git checkout -b "$TARGET_BRANCH" ||
94+
error_exit "Failed to checkout $TARGET_BRANCH."
95+
git rebase "$REBASE_BRANCH" "$TARGET_BRANCH" ||
96+
error_exit "Failed to rebase."
97+
98+
log_info "Rebase completed successfully!"

0 commit comments

Comments
 (0)