Skip to content

Commit eb6b63d

Browse files
authored
[CIR][Github][CI] Add clangir upstream rebase workflow (#1345)
1 parent f9c0515 commit eb6b63d

File tree

3 files changed

+174
-0
lines changed

3 files changed

+174
-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: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
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+
RUN_CHECK=false
13+
14+
log() { printf "%b[%s]%b %s\n" "$1" "$2" "$NC" "$3"; }
15+
log_info() { log "$GREEN" "INFO" "$1"; }
16+
log_warn() { log "$YELLOW" "WARN" "$1"; }
17+
log_error() { log "$RED" "ERROR" "$1" >&2; }
18+
19+
error_exit() {
20+
log_error "$1"
21+
exit 1
22+
}
23+
24+
is_rebasing() {
25+
git rev-parse --git-path rebase-merge >/dev/null 2>&1 ||
26+
git rev-parse --git-path rebase-apply >/dev/null 2>&1
27+
}
28+
29+
while [[ $# -gt 0 ]]; do
30+
case "$1" in
31+
--checked)
32+
RUN_CHECK=true
33+
shift
34+
;;
35+
*)
36+
TARGET_BRANCH="$1"
37+
shift
38+
;;
39+
esac
40+
done
41+
42+
git rev-parse --is-inside-work-tree >/dev/null 2>&1 ||
43+
error_exit "Not in a Git repository."
44+
45+
git remote get-url upstream >/dev/null 2>&1 ||
46+
error_exit "Upstream remote not found."
47+
48+
log_info "Fetching latest changes from upstream..."
49+
50+
git fetch upstream main ||
51+
error_exit "Failed to fetch from upstream."
52+
53+
REBASING_CIR_BRANCH=$(git branch --show-current)
54+
55+
if [ -z "$COMMON_ANCESTOR" ]; then
56+
COMMON_ANCESTOR=$(git merge-base upstream/main "$REBASING_CIR_BRANCH") ||
57+
error_exit "Could not find common ancestor."
58+
log_info "Common ancestor commit: $COMMON_ANCESTOR"
59+
fi
60+
61+
if [ "$REBASING_CIR_BRANCH" != "$REBASE_BRANCH" ]; then
62+
if git rev-parse --verify "$REBASE_BRANCH" >/dev/null 2>&1; then
63+
git branch -D "$REBASE_BRANCH" >/dev/null 2>&1 ||
64+
log_warn "Failed to delete existing branch $REBASE_BRANCH."
65+
fi
66+
67+
git switch -c "$REBASE_BRANCH" "$COMMON_ANCESTOR" ||
68+
error_exit "Failed to create branch $REBASE_BRANCH."
69+
fi
70+
71+
#
72+
# Rebase upstream changes
73+
#
74+
log_info "Processing upstream commits..."
75+
git rebase upstream/main ||
76+
error_exit "Failed to rebase."
77+
78+
#
79+
# Reverse upstream CIR commits
80+
#
81+
log_info "Reverting upstream CIR commits..."
82+
git log --grep="\[CIR\]" --format="%H %s" "$COMMON_ANCESTOR..upstream/main" | while read -r HASH MESSAGE; do
83+
log_info "Reverting: $MESSAGE"
84+
85+
if ! git revert --no-edit "$HASH"; then
86+
error_exit "Failed to revert commit $HASH"
87+
fi
88+
done
89+
90+
#
91+
# Rebase CIR commits
92+
#
93+
log_info "Rebasing CIR incubator commits..."
94+
95+
if [ -z "$TARGET_BRANCH" ]; then
96+
log_error "Target branch not specified."
97+
exit 1
98+
fi
99+
100+
if git rev-parse --verify "$TARGET_BRANCH" >/dev/null 2>&1; then
101+
git branch -D "$TARGET_BRANCH" >/dev/null 2>&1 ||
102+
error_exit "Failed to delete existing branch $TARGET_BRANCH."
103+
fi
104+
105+
git switch "$REBASING_CIR_BRANCH" ||
106+
error_exit "Failed to switch to $REBASING_CIR_BRANCH."
107+
git checkout -b "$TARGET_BRANCH" ||
108+
error_exit "Failed to checkout $TARGET_BRANCH."
109+
110+
if [ "$RUN_CHECK" = true ]; then
111+
git rebase --exec "ninja -C build check-clang-cir" "$REBASE_BRANCH" "$TARGET_BRANCH" ||
112+
error_exit "Failed to rebase."
113+
else
114+
git rebase "$REBASE_BRANCH" "$TARGET_BRANCH" ||
115+
error_exit "Failed to rebase."
116+
fi
117+
118+
log_info "Rebase completed successfully!"

0 commit comments

Comments
 (0)