Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
sonic-build committed Oct 10, 2022
2 parents 217fa81 + 9b2b8e3 commit e376c8e
Show file tree
Hide file tree
Showing 18 changed files with 340 additions and 10 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Github actions README
This is an introduction about auto-cherry-pick workflow.
take 202205 branch for example:
1. pr_cherrypick_prestep:
```mermaid
graph
Start(Origin PR) --> A{merged?}
A -- NO --> STOP
A -- YES --> A1{Approved<br> for 202205<br> Branch?}
A1 -- NO --> STOP
A1 -- YES --> A2(pr_cherrypick_prestep)
B(pr_cherrypick_prestep)
B --> B1{cherry pick<br>conflict?}
B1 -- YES --> B2(Add tag:<br>Cherry Pick Confclit_202205) --> B3(Add comment:<br>refer author code conflict) --> STOP1(STOP)
B1 -- NO --> B4(Create New PR) -- success --> B5(New PR add tag:<br> automerge) --> B6(New PR add comment:<br>Origin PR link) --> B7(Origin PR add tag:<br>Created PR to 202205 Branch) --> B8(Origin PR add comment:<br>New PR link)
B4 -- fail --> STOP1
```

2. automerge:
```mermaid
graph
Start(PR azp finished successfully) --> A{author:<br>mssonicbld?}
A -- NO --> STOP
A -- YES --> B{tag:<br>automerge?} -- YES --> C(Merge PR)
B -- NO --> STOP
```

3. pr_cherrypick_poststep:
```mermaid
graph
A(PR is Merged) --> B{tag:<br>automerge?}
B -- YES --> B1{author:<br>mssonicbld?}
B1 -- YES --> B2{"title starts:<br>[action] [PR:123]"}
B2 -- YES --> C(Origin PR remove tag:<br> Created PR to 202205 Branch) --> D(Origin PR add tag:<br> Included in 202205 Branch)
B -- NO --> STOP
B1 -- NO --> STOP
B2 -- NO --> STOP
```
49 changes: 49 additions & 0 deletions .github/workflows/pr_cherrypick_poststep.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: PostCherryPick
on:
pull_request_target:
types:
- closed
branches:
- '20*'

jobs:
post_cherry_pick:
if: github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'automerge') && github.event.pull_request.head.user.login == 'mssonicbld' && startsWith(github.event.pull_request.title, '[action]')
runs-on: ubuntu-latest
steps:
- name: Debug
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo $GITHUB_CONTEXT | jq
- name: Checkout
uses: actions/checkout@v3
with:
persist-credentials: false
- name: Main
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
TOKEN: ${{ secrets.TOKEN }}
run: |
set -e
pr_url=$(echo $GITHUB_CONTEXT | jq -r ".event.pull_request._links.html.href")
pr_id=$(echo $GITHUB_CONTEXT | jq -r ".event.number")
base_ref=$(echo $GITHUB_CONTEXT | jq -r ".base_ref")
echo ${TOKEN} | gh auth login --with-token
title=$(echo $GITHUB_CONTEXT | jq -r ".event.pull_request.title")
origin_pr_id=$(echo $title | grep -Eo "\[action\] \[PR:[0-9]*\]" | grep -Eo "[0-9]*")
origin_pr_url=$(echo $pr_url | sed "s/$pr_id/$origin_pr_id/")
echo =============================
echo pr_url: $pr_url
echo pr_id: $pr_id
echo base_ref: $base_ref
echo title: $title
echo origin_pr_id: $origin_pr_id
echo origin_pr_url: $origin_pr_url
echo =============================
# Add label
if [[ "$origin_pr_id" == "" ]];then
echo "original PR didn't found."
exit 1
fi
gh pr edit $origin_pr_url --add-label "Included in ${base_ref} Branch"
gh pr edit $origin_pr_url --remove-label "Created PR to ${base_ref} Branch,Request for ${base_ref} Branch,Approved for ${base_ref} Branch"
136 changes: 136 additions & 0 deletions .github/workflows/pr_cherrypick_prestep.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
name: PreCherryPick
on:
pull_request_target:
types:
- labeled
- closed
branches:
- master

jobs:
pre_cherry_pick:
if: github.event.pull_request.merged == true && ( (github.event.action == 'closed' && contains(join(github.event.pull_request.labels.*.name, ','), 'Approved for 20')) || (github.event.action == 'labeled' && startsWith(github.event.label.name, 'Approved for 20')) )
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
persist-credentials: false
- name: Debug
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo $GITHUB_CONTEXT | jq
- name: Main
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
TOKEN: ${{ secrets.TOKEN }}
run: |
set -e
sha=$(echo $GITHUB_CONTEXT | jq -r ".event.pull_request.merge_commit_sha")
pr_id=$(echo $GITHUB_CONTEXT | jq -r ".event.number")
pr_url=$(echo $GITHUB_CONTEXT | jq -r ".event.pull_request._links.html.href")
repository=$(echo $GITHUB_CONTEXT | jq -r ".repository")
labels=$(echo $GITHUB_CONTEXT | jq -r ".event.pull_request.labels[].name")
author=$(echo $GITHUB_CONTEXT | jq -r ".event.pull_request.base.user.login")
branches=$(git branch -a --list 'origin/20????' | awk -F/ '{print$3}' | grep -E "202[0-9]{3}")
if [[ $(echo $GITHUB_CONTEXT | jq -r ".event.action") == "labeled" ]];then
labels=$(echo $GITHUB_CONTEXT | jq -r ".event.label.name")
fi
title=$(echo $GITHUB_CONTEXT | jq -r ".event.pull_request.title")
echo =============================
echo SHA: $sha
echo PRID: $pr_id
echo pr_url: $pr_url
echo repository: $repository
echo branches: $branches
echo labels:
echo "$labels"
echo ${TOKEN} | gh auth login --with-token
echo author: $author
echo title: $title
echo =============================
git config user.name mssonicbld
git config user.email sonicbld@microsoft.com
git config credential.https://git.luolix.top.username mssonicbld
git remote add mssonicbld https://mssonicbld:${TOKEN}@github.com/mssonicbld/sonic-buildimage
git fetch mssonicbld
git remote -vv
cherry_pick(){
set -e
local create_pr=''
while read label
do
echo label: $label
if [[ "$label" == "Approved for $branch Branch" ]];then
create_pr=1
fi
if [[ "$label" == "Created PR to $branch Branch" ]];then
echo "already has tag: Created PR to $branch Branch, return"
return 0
fi
if [[ "$label" == "Included in $branch Branch" ]];then
echo "already has tag: Included in $branch Branch, return"
return 0
fi
if [[ "$label" == "Cherry Pick Conflict_$branch" ]];then
echo "already has tag: Cherry Pick Conflict_$branch, return"
return 0
fi
done <<< "$labels"
if [[ "$create_pr" != "1" ]];then
echo "Didn't find 'Approved for $branch Branch' tag."
return 0
fi
# Begin to cherry-pick PR
git cherry-pick --abort 2>/dev/null || true
git clean -xdff 2>/dev/null || true
git reset HEAD --hard || true
git checkout -b $branch --track origin/$branch
git status | grep "working tree clean"
if ! git cherry-pick $sha;then
echo 'cherry-pick failed.'
git cherry-pick --abort
git status | grep "working tree clean"
# Add label
gh pr edit $pr_url --add-label "Cherry Pick Conflict_$branch"
echo 'Add label "Cherry Pick Conflict_$branch" success'
gh pr comment $pr_url --body "@${author} PR conflicts with $branch branch"
echo 'Add commnet "@${author} PR conflicts with $branch branch"'
else
# Create PR to release branch
git push mssonicbld HEAD:$branch-${pr_id} -f
result=$(gh pr create -R ${repository} -H mssonicbld:$branch-${pr_id} -B $branch -t "[action] [PR:$pr_id] $title" -b '' 2>&1)
echo $result | grep "already exists" && { echo $result; return 0; }
echo $result | grep github.com || { echo $result; return 1; }
new_pr_rul=$(echo $result | grep github.com)
echo new_pr_rul: $new_pr_rul
# Add label to old PR
gh pr edit $pr_url --add-label "Created PR to $branch Branch"
echo Add label Created PR to $branch Branch
# Add comment to old PR
gh pr comment $pr_url --body "Cherry-pick PR to $branch: ${new_pr_rul}"
echo Add comment to old PR
# Add label to new PR
gh pr edit $new_pr_rul --add-label "automerge"
echo Add label automerge to new PR
# Add comment to new PR
gh pr comment $new_pr_rul --body "Original PR: ${pr_url}"
echo Add comment to new PR
fi
}
for branch in $branches
do
echo -------------------------------------------
echo Begin to parse Branch: $branch
cherry_pick
done
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,17 @@
"index": 0,
"phy_id" : 1,
"system_lanes": [200,201],
"line_lanes": [206]
"line_lanes": [206],
"system_tx_fir_pre2": [1,1],
"system_tx_fir_pre1": [-5,-5],
"system_tx_fir_main": [14,14],
"system_tx_fir_post1": [0,0],
"system_tx_fir_post2": [0,0],
"line_tx_fir_pre2": [0],
"line_tx_fir_pre1": [-1],
"line_tx_fir_main": [13],
"line_tx_fir_post1": [-5],
"line_tx_fir_post2": [0]
},
{
"name": "Ethernet4",
Expand Down
10 changes: 10 additions & 0 deletions dockers/docker-fpm-frr/bgp_regex.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@
"tag": "bgp-state",
"regex": "Peer .default\\|([0-9a-f:.]*[0-9a-f]*). admin state is set to .(up|down).",
"params": [ "ip", "status" ]
},
{
"tag": "zebra-no-buff",
"regex": "No buffer space available",
"params": []
},
{
"tag": "notification",
"regex": "NOTIFICATION: (received|sent) (?:to|from) neighbor ([0-9a-f:.]*[0-9a-f+]*)\\s*.* (\\d*)\/(\\d*)",
"params": [ "is-sent", "ip", "major-code", "minor-code" ]
}
]

4 changes: 3 additions & 1 deletion dockers/docker-sonic-mgmt/Dockerfile.j2
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ RUN pip install cffi==1.12.0 \
celery[redis]==4.4.7 \
msrest==0.6.21 \
python-dateutil \
azure-storage-blob==12.9.0 \
&& git clone https://github.com/p4lang/scapy-vxlan.git \
&& cd scapy-vxlan \
&& python setup.py install \
Expand Down Expand Up @@ -255,7 +256,8 @@ RUN python3 -m pip install setuptools-rust \
scapy==2.4.5 \
celery[redis]==4.4.7 \
msrest==0.6.21 \
python-dateutil
python-dateutil \
azure-storage-blob==12.9.0

# Deactivating a virtualenv
ENV PATH="$BACKUP_OF_PATH"
7 changes: 7 additions & 0 deletions files/build_templates/dhcp_relay_regex.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"tag": "dhcp-relay-discard",
"regex": "Discarding packet received on ([a-zA-Z0-9-_]*) interface that has no IPv4 address assigned.",
"params": [ "ifname" ]
}
]
7 changes: 7 additions & 0 deletions files/build_templates/dockerd_regex.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"tag": "invalid-freelist",
"regex": "invalid freelist",
"params": []
}
]
26 changes: 25 additions & 1 deletion files/build_templates/events_info.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"proclist": [
{
"name": "monit",
"parse_json": "monit_regex.json"
"parse_json": "monit_regex.json"
},
{
"name": "sshd",
Expand All @@ -12,6 +12,30 @@
{
"name": "systemd",
"parse_json": "systemd_regex.json"
},
{
"name": "dhcp_relay",
"parse_json": "dhcp_relay_regex.json"
},
{
"name": "syncd",
"parse_json": "syncd_regex.json"
},
{
"name": "kernel",
"parse_json": "kernel_regex.json"
},
{
"name": "dockerd",
"parse_json": "dockerd_regex.json"
},
{
"name": "arista",
"parse_json": "seu_regex.json"
},
{
"name": "python3",
"parse_json": "seu_regex.json"
}
]
}
7 changes: 7 additions & 0 deletions files/build_templates/kernel_regex.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"tag": "event-kernel",
"regex": "(write failed|Write protected|Remounting filesystem read-only|zlib decompression failed, data probably corrupt)",
"params": [ "fail_type:ret=(arg==\"write failed\")and\"write_failed\"or((arg==\"Write protected\")and\"write_protected\"or((arg==\"Remounting filesystem read-only\")and\"remount_read_only\"or((arg==\"zlib decompression failed, data probably corrupt\")and\"zlib_decompress\"or\"\")))" ]
}
]
7 changes: 7 additions & 0 deletions files/build_templates/seu_regex.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"tag": "event-seu",
"regex": "SEU error was detected",
"params": []
}
]
5 changes: 5 additions & 0 deletions files/build_templates/sonic_debian_extension.j2
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,11 @@ j2 -f json $BUILD_TEMPLATES/rsyslog_plugin.conf.j2 $BUILD_TEMPLATES/events_info.
sudo cp $BUILD_TEMPLATES/monit_regex.json $FILESYSTEM_ROOT_ETC/rsyslog.d/
sudo cp $BUILD_TEMPLATES/sshd_regex.json $FILESYSTEM_ROOT_ETC/rsyslog.d/
sudo cp $BUILD_TEMPLATES/systemd_regex.json $FILESYSTEM_ROOT_ETC/rsyslog.d/
sudo cp $BUILD_TEMPLATES/dhcp_relay_regex.json $FILESYSTEM_ROOT_ETC/rsyslog.d/
sudo cp $BUILD_TEMPLATES/syncd_regex.json $FILESYSTEM_ROOT_ETC/rsyslog.d/
sudo cp $BUILD_TEMPLATES/kernel_regex.json $FILESYSTEM_ROOT_ETC/rsyslog.d/
sudo cp $BUILD_TEMPLATES/dockerd_regex.json $FILESYSTEM_ROOT_ETC/rsyslog.d/
sudo cp $BUILD_TEMPLATES/seu_regex.json $FILESYSTEM_ROOT_ETC/rsyslog.d/

# Install custom-built monit package and SONiC configuration files
sudo dpkg --root=$FILESYSTEM_ROOT -i $debs_path/monit_*.deb || \
Expand Down
7 changes: 7 additions & 0 deletions files/build_templates/syncd_regex.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"tag": "syncd-failure",
"regex": "(MMU ERR Type|L3 route add failed with error|Assertion failed|Received switch event|SER Parity Check Error)",
"params": [ "fail_type:ret=(arg==\"Received switch event\")and\"switch_event\"or((arg==\"Assertion Failed\")and\"assert\"or((arg==\"SER Parity Check Error\")and\"parity_check\"or((arg==\"MMU ERR Type\")and\"mmu_err\"or((arg==\"route add failed\")and\"route_add_failed\"or\"\"))))" ]
}
]
7 changes: 6 additions & 1 deletion files/build_templates/systemd_regex.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
{
"tag": "event-stopped-ctr",
"regex": "Stopped ([a-zA-Z-_\\s]*) container",
"params": [ "ctr-name" ]
"params": [ "ctr_name" ]
},
{
"tag": "watchdog-timeout",
"regex": "(?:watchdog|Watchdog) timeout .limit.([0-9])min.",
"params": [ "limit" ]
}
]
2 changes: 1 addition & 1 deletion files/image_config/monit/container_checker
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def publish_events(lst):
params = swsscommon.FieldValueMap()

for ctr in lst:
params["name"] = ctr;
params["ctr_name"] = ctr;
swsscommon.event_publish(events_handle, EVENTS_PUBLISHER_TAG, params)

swsscommon.events_deinit_publisher(events_handle)
Expand Down
Loading

0 comments on commit e376c8e

Please sign in to comment.