Skip to content

Commit 023a862

Browse files
committed
cli-patch: generalize to-git functionality with PUSH_TO_GITHUB and PUSH_TO_REPO & enable for u-boot as well as kernel
- `PUSH_TO_REPO=<url>`: set the full git URL to push to - `PUSH_TO_GITHUB=<org>/<repo>`: shorthand for pushing to GitHub; sets `PUSH_TO_REPO` - note: be kind to GitHub, and use forks of torvalds/linux and u-boot/u-boot so GH has a decent base tree - still, kernel pushes are huge, mostly due to the all-wifi-drivers commit that's always first and always slightly different - note: when pushing to GitHub, keep in mind the pushed branch contains a GHA workflow, which will only run if you have GHA enabled on the repo - examples (adapt to your username/forks): - `./compile.sh BOARD=nanopct6 BRANCH=edge rewrite-kernel-patches PUSH_TO_GITHUB=rpardini/linux` - `./compile.sh BOARD=rock-5b BRANCH=legacy rewrite-uboot-patches PUSH_TO_GITHUB=rpardini/armbian-patched-u-boot`
1 parent 422e91b commit 023a862

File tree

1 file changed

+50
-30
lines changed

1 file changed

+50
-30
lines changed

lib/functions/cli/cli-patch.sh

+50-30
Original file line numberDiff line numberDiff line change
@@ -47,47 +47,27 @@ function cli_patch_kernel_run() {
4747
obtain_kernel_git_info_and_makefile # this populates GIT_INFO_KERNEL and sets KERNEL_GIT_SHA1 readonly global
4848
# </prepare the git sha1>
4949

50-
declare ymd vendor_lc target_repo_url summary_url
51-
ymd="$(date +%Y%m%d)"
52-
# lowercase ${VENDOR} and replace spaces with underscores
53-
vendor_lc="$(tr '[:upper:]' '[:lower:]' <<< "${VENDOR}" | tr ' ' '_')-next"
54-
target_branch="${vendor_lc}-${LINUXFAMILY}-${KERNEL_MAJOR_MINOR}-${ymd}${PUSH_BRANCH_POSTFIX:-""}"
55-
target_repo_url="git@github.com:${PUSH_TO_REPO:-"${PUSH_TO_USER:-"rpardini"}/${PUSH_TO_REPO:-"linux"}"}.git"
56-
summary_url="https://${PUSH_TO_USER:-"rpardini"}.github.io/${PUSH_TO_REPO:-"linux"}/${target_branch}.html"
57-
58-
declare -a push_command
59-
push_command=(git -C "${SRC}/cache/git-bare/kernel" push "--force" "--verbose"
60-
"${target_repo_url}"
61-
"kernel-${LINUXFAMILY}-${KERNEL_MAJOR_MINOR}:${target_branch}")
50+
# prepare push details, if set
51+
declare target_repo_url target_branch do_push="no"
52+
declare -a push_command=()
53+
determine_git_push_details "${LINUXFAMILY}-${KERNEL_MAJOR_MINOR}" # fills in the above; parameter is the branch name
6254

6355
# Prepare the host and build kernel; without using standard build
6456
prepare_host # This handles its own logging sections, and is possibly interactive.
6557
compile_kernel # This handles its own logging sections.
6658

6759
display_alert "Done patching kernel" "${BRANCH} - ${LINUXFAMILY} - ${KERNEL_MAJOR_MINOR}" "cachehit"
6860

69-
declare do_push="no"
70-
if git -C "${SRC}" remote get-url origin &> /dev/null; then
71-
declare src_origin_url
72-
src_origin_url="$(git -C "${SRC}" remote get-url origin | xargs echo -n)"
73-
74-
declare prefix="git@github.com:${PUSH_TO_USER:-"rpardini"}/" # @TODO refactor var
75-
# if the src_origin_url begins with the prefix
76-
if [[ "${src_origin_url}" == "${prefix}"* ]]; then
77-
do_push="yes"
78-
fi
79-
fi
80-
81-
display_alert "Git push command: " "${push_command[*]}" "info"
8261
if [[ "${do_push}" == "yes" ]]; then
83-
display_alert "Pushing to ${target_branch}" "${target_repo_url}" "info"
62+
display_alert "Pushing kernel to Git branch ${target_branch}" "${target_repo_url}" "info"
8463
git_ensure_safe_directory "${SRC}/cache/git-bare/kernel"
85-
# @TODO: do NOT allow shallow trees here, we need the full history to be able to push
86-
GIT_SSH_COMMAND="ssh -o GlobalKnownHostsFile=/dev/null -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" "${push_command[@]}"
87-
display_alert "Done pushing to ${target_branch}" "${summary_url}" "info"
64+
push_command=(git -C "${SRC}/cache/git-bare/kernel" push "--force" "--verbose" "${target_repo_url}" "kernel-${LINUXFAMILY}-${KERNEL_MAJOR_MINOR}:${target_branch}")
65+
display_alert "Git push command: " "${push_command[*]}" "info"
66+
execute_git_push
8867
fi
8968

90-
display_alert "Summary URL (after push & gh-pages deploy): " "${summary_url}" "info"
69+
return 0
70+
9171
}
9272

9373
## Similar stuff as kernel, but for u-boot.
@@ -108,6 +88,11 @@ function cli_patch_uboot_run() {
10888
[[ "${GIT_INFO_UBOOT[SHA1]}" =~ ^[0-9a-f]{40}$ ]] || exit_with_error "SHA1 is not sane: '${GIT_INFO_UBOOT[SHA1]}'"
10989
# </prepare the git sha1>
11090

91+
# prepare push details, if set
92+
declare target_repo_url target_branch do_push="no"
93+
declare -a push_command=()
94+
determine_git_push_details "${BOARD}-${BRANCH}" # fills in the above; parameter is the branch name
95+
11196
# Prepare the host
11297
prepare_host # This handles its own logging sections, and is possibly interactive.
11398

@@ -123,4 +108,39 @@ function cli_patch_uboot_run() {
123108
LOG_SECTION="patch_uboot_target" do_with_logging patch_uboot_target
124109

125110
display_alert "Done patching u-boot" "${BRANCH} - ${LINUXFAMILY} - ${BOOTSOURCE}#${BOOTBRANCH}" "cachehit"
111+
112+
if [[ "${do_push}" == "yes" ]]; then
113+
display_alert "Pushing u-boot to Git branch ${target_branch}" "${target_repo_url}" "info"
114+
git_ensure_safe_directory "${SRC}/cache/git-bare/u-boot"
115+
push_command=(git -C "${SRC}/cache/git-bare/u-boot" push "--force" "--verbose" "${target_repo_url}" "u-boot-${BRANCH}-${BOARD}:${target_branch}")
116+
display_alert "Git push command: " "${push_command[*]}" "info"
117+
execute_git_push
118+
fi
119+
120+
}
121+
122+
function determine_git_push_details() {
123+
if [[ -n "${PUSH_TO_GITHUB}" ]]; then
124+
PUSH_TO_REPO="git@github.com:${PUSH_TO_GITHUB}.git"
125+
display_alert "Will push to GitHub" "${PUSH_TO_REPO}" "info"
126+
fi
127+
128+
if [[ -n "${PUSH_TO_REPO}" ]]; then
129+
do_push="yes"
130+
declare ymd vendor_lc
131+
ymd="$(date +%Y%m%d)"
132+
vendor_lc="$(tr '[:upper:]' '[:lower:]' <<< "${VENDOR}" | tr ' ' '_')" # lowercase ${VENDOR} and replace spaces with underscores
133+
target_branch="${vendor_lc}-${1}-${ymd}${PUSH_BRANCH_POSTFIX:-""}"
134+
target_repo_url="${PUSH_TO_REPO}"
135+
display_alert "Will push to Git" "${target_repo_url} branch ${target_branch}" "info"
136+
else
137+
display_alert "Will NOT push to Git" "use PUSH_TO_GITHUB=org/repo or PUSH_TO_REPO=<url> to push" "info"
138+
fi
139+
}
140+
141+
function execute_git_push() {
142+
display_alert "Pushing to ${target_branch}" "${target_repo_url}" "info"
143+
# @TODO: do NOT allow shallow trees here, we need the full history to be able to push
144+
GIT_SSH_COMMAND="ssh -o GlobalKnownHostsFile=/dev/null -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" "${push_command[@]}"
145+
display_alert "Done pushing to ${target_branch}" "${target_repo_url}" "info"
126146
}

0 commit comments

Comments
 (0)