blob: e7f4b7c9a0bde59faec890bc54a3c7e324625516 [file] [log] [blame]
kelvin.zhang2219b412022-03-04 16:44:41 +08001#!/bin/bash
2#
3# Copyright (c) 2021-2022 Amlogic, Inc. All rights reserved.
4#
5# SPDX-License-Identifier: MIT
6#
7
8if [ -n "$GIT_CHERRY_PICK" ]; then
9 [ -z "$CURRENT_MANIFEST_FILE" ] && CURRENT_MANIFEST_FILE="manifest.xml"
10 [ ! -f $CURRENT_MANIFEST_FILE ] && repo manifest -r -o $CURRENT_MANIFEST_FILE
11
Kelvin Zhangb2630702022-04-20 11:22:32 +080012 while IFS= read -r line
kelvin.zhang2219b412022-03-04 16:44:41 +080013 do
14 pattern=":29418/"
15 for keyword in $line; do
16 if [[ $keyword == *$pattern* ]]; then
17 GIT_PROJECT=`echo ${keyword#*${pattern}} | sed 's/\"//g' | sed 's/\/>//g'`
18 break;
19 fi
20 done
21
Kelvin Zhangb6cbb072022-04-26 14:19:35 +080022 echo -e "\n-------- Applying manual patch on Project $GIT_PROJECT --------"
kelvin.zhang2219b412022-03-04 16:44:41 +080023 keyline=`grep "name=\"$GIT_PROJECT\"" $CURRENT_MANIFEST_FILE`
24
25 for keyword in $keyline; do
26 if [[ $keyword == path=* ]]; then
27 repo_path=`echo ${keyword#*path=} | sed 's/\"//g'`
28 break;
29 fi
30 done
31
32 if [ -d "$repo_path" ]; then
33 pushd $repo_path > /dev/null
34 cmd=`echo $line | sed -e 's/ssh:\/\/.*@scgit.amlogic.com/ssh:\/\/scgit.amlogic.com/'`
35 eval $cmd
36 if [ "$?" -ne 0 ]; then
Kelvin Zhangcceacda2022-05-23 09:34:34 +080037 git status
38 git log -1
39 echo -e "-------- Failed to apply patch! --------"
kelvin.zhang2219b412022-03-04 16:44:41 +080040 exit 1
41 fi
42 popd > /dev/null
43 else
44 echo "No such directory! $repo_path"
45 exit 1
46 fi
Kelvin Zhangb6cbb072022-04-26 14:19:35 +080047 echo -e "-------- Done --------\n"
Kelvin Zhangb2630702022-04-20 11:22:32 +080048 done <<< "$GIT_CHERRY_PICK"
kelvin.zhang2219b412022-03-04 16:44:41 +080049fi
Kelvin Zhang0322c7e2022-04-25 18:19:41 +080050
51if [ -n "$MANUAL_GERRIT_CHANGE_NUMBER" ]; then
52 GERRIT_SERVER="scgit.amlogic.com"
53 GERRIT_PORT="29418"
54 GERRIT_QUERY_RESULT="changes.txt"
55 ssh -p $GERRIT_PORT $GERRIT_SERVER gerrit query --format=JSON --current-patch-set status:open change:$GERRIT_CHANGE_NUMBER > $GERRIT_QUERY_RESULT
56 GERRIT_PROJECT=$(jq -r '.project // empty' $GERRIT_QUERY_RESULT)
57 GERRIT_CHANGE_REF=$(jq -r '.currentPatchSet.ref // empty' $GERRIT_QUERY_RESULT)
58
59 [ -z "$CURRENT_MANIFEST_FILE" ] && CURRENT_MANIFEST_FILE="manifest.xml"
60 [ ! -f $CURRENT_MANIFEST_FILE ] && repo manifest -r -o $CURRENT_MANIFEST_FILE
61
Kelvin Zhangb6cbb072022-04-26 14:19:35 +080062 echo -e "\n-------- Applying manual patch on Project $GERRIT_PROJECT --------"
Kelvin Zhang0322c7e2022-04-25 18:19:41 +080063 keyline=`grep "name=\"$GERRIT_PROJECT\"" $CURRENT_MANIFEST_FILE`
64
65 for keyword in $keyline; do
66 if [[ $keyword == path=* ]]; then
67 repo_path=`echo ${keyword#*path=} | sed 's/\"//g'`
68 break;
69 fi
70 done
71
72 if [ -d "$repo_path" ]; then
73 pushd $repo_path > /dev/null
74 git fetch ssh://${GERRIT_SERVER}:${GERRIT_PORT}/${GERRIT_PROJECT} ${GERRIT_CHANGE_REF}
75 git cherry-pick FETCH_HEAD
76 if [ "$?" -ne 0 ]; then
Kelvin Zhangb6cbb072022-04-26 14:19:35 +080077 echo -e "-------- Applying patch failed! --------\n"
Kelvin Zhang0322c7e2022-04-25 18:19:41 +080078 exit 1
79 fi
80 popd > /dev/null
81 else
82 echo "No such directory! $repo_path"
83 exit 1
84 fi
Kelvin Zhangb6cbb072022-04-26 14:19:35 +080085 echo -e "-------- Done --------\n"
Kelvin Zhang0322c7e2022-04-25 18:19:41 +080086fi
87
88if [ -n "$MANUAL_GERRIT_TOPIC" ]; then
89 GERRIT_SERVER="scgit.amlogic.com"
90 GERRIT_PORT="29418"
91 GERRIT_QUERY_RESULT="changes.txt"
92 ssh -p $GERRIT_PORT $GERRIT_SERVER gerrit query --format=JSON --current-patch-set status:open topic:$MANUAL_GERRIT_TOPIC > $GERRIT_QUERY_RESULT
93 GERRIT_PROJECTS=$(jq -r '.project // empty' $GERRIT_QUERY_RESULT)
94 GERRIT_CHANGE_REFS=$(jq -r '.currentPatchSet.ref // empty' $GERRIT_QUERY_RESULT)
95
96 [ -z "$CURRENT_MANIFEST_FILE" ] && CURRENT_MANIFEST_FILE="manifest.xml"
97 [ ! -f $CURRENT_MANIFEST_FILE ] && repo manifest -r -o $CURRENT_MANIFEST_FILE
Kelvin Zhang90176112022-04-26 16:22:25 +080098 echo -e "\n======== Applying manual changes ========"
Kelvin Zhang0322c7e2022-04-25 18:19:41 +080099
100 i=1
101 for GERRIT_PROJECT in $GERRIT_PROJECTS; do
Kelvin Zhang90176112022-04-26 16:22:25 +0800102 echo -e "\n-------- Applying manual patch $i on Project $GERRIT_PROJECT --------"
Kelvin Zhang0322c7e2022-04-25 18:19:41 +0800103 keyline=`grep "name=\"$GERRIT_PROJECT\"" $CURRENT_MANIFEST_FILE`
104
105 for keyword in $keyline; do
106 if [[ $keyword == path=* ]]; then
107 repo_path=`echo ${keyword#*path=} | sed 's/\"//g'`
108 break;
109 fi
110 done
111
112 if [ -d "$repo_path" ]; then
113 GERRIT_CHANGE_REF=$(echo $GERRIT_CHANGE_REFS | awk "{print \$$i}")
114 pushd $repo_path > /dev/null
115 git fetch ssh://${GERRIT_SERVER}:${GERRIT_PORT}/${GERRIT_PROJECT} ${GERRIT_CHANGE_REF}
116 git cherry-pick FETCH_HEAD
117 if [ "$?" -ne 0 ]; then
Kelvin Zhangcceacda2022-05-23 09:34:34 +0800118 git status
119 git log -1
Kelvin Zhang90176112022-04-26 16:22:25 +0800120 echo -e "-------- Failed to apply patch! --------"
Kelvin Zhang0322c7e2022-04-25 18:19:41 +0800121 exit 1
122 fi
123 popd > /dev/null
124 else
125 echo "No such directory! $repo_path"
126 exit 1
127 fi
Kelvin Zhang90176112022-04-26 16:22:25 +0800128 echo -e "-------- Done --------"
Kelvin Zhang0322c7e2022-04-25 18:19:41 +0800129 i=$((i+1))
130 done
Kelvin Zhangb6cbb072022-04-26 14:19:35 +0800131
132 i=$((i-1))
Kelvin Zhang90176112022-04-26 16:22:25 +0800133 [[ "$i" -eq 1 ]] && echo -e "\n======== Applied $i patch for $MANUAL_GERRIT_TOPIC ========\n"
134 [[ "$i" -gt 1 ]] && echo -e "\n======== Applied $i patches for $MANUAL_GERRIT_TOPIC ========\n"
Kelvin Zhang0322c7e2022-04-25 18:19:41 +0800135fi