Skip to content

Commit

Permalink
Merge pull request sonic-net#99 from oleksandrivantsiv/bluefield
Browse files Browse the repository at this point in the history
Merge the latest sonic-net/sonic-buildimage master branch into bluefield.
  • Loading branch information
oleksandrivantsiv authored Oct 10, 2022
2 parents 3504533 + 660a38e commit f00c204
Show file tree
Hide file tree
Showing 73 changed files with 1,375 additions and 711 deletions.
2 changes: 1 addition & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Write a short (one line) summary that describes the changes in this
pull request for inclusion in the changelog:
-->

#### Ensure to add label/tag for the feature raised. example - [PR#2174](https://github.com/sonic-net/sonic-utilities/pull/2174) where, Generic Config and Update feature has been labelled as GCU.
#### Ensure to add label/tag for the feature raised. example - PR#2174 under sonic-utilities repo. where, Generic Config and Update feature has been labelled as GCU.

#### Link to config_db schema for YANG module changes
<!--
Expand Down
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-test

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://github.com.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
34 changes: 21 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ NOSTRETCH ?= 0
NOBUSTER ?= 0
NOBULLSEYE ?= 0

override Q := @
ifeq ($(QUIET),n)
override Q :=
endif
override SONIC_OVERRIDE_BUILD_VARS += $(SONIC_BUILD_VARS)
override SONIC_OVERRIDE_BUILD_VARS += Q=$(Q)
export Q SONIC_OVERRIDE_BUILD_VARS

ifeq ($(NOJESSIE),0)
BUILD_JESSIE=1
endif
Expand All @@ -29,50 +37,50 @@ PLATFORM_CHECKOUT_CMD := $(shell if [ -f $(PLATFORM_CHECKOUT_FILE) ]; then PLATF
%::
@echo "+++ --- Making $@ --- +++"
ifeq ($(NOJESSIE), 0)
EXTRA_DOCKER_TARGETS=$(notdir $@) make -f Makefile.work jessie
EXTRA_DOCKER_TARGETS=$(notdir $@) $(MAKE) -f Makefile.work jessie
endif
ifeq ($(NOSTRETCH), 0)
EXTRA_DOCKER_TARGETS=$(notdir $@) BLDENV=stretch make -f Makefile.work stretch
EXTRA_DOCKER_TARGETS=$(notdir $@) BLDENV=stretch $(MAKE) -f Makefile.work stretch
endif
ifeq ($(NOBUSTER), 0)
EXTRA_DOCKER_TARGETS=$(notdir $@) BLDENV=buster make -f Makefile.work buster
EXTRA_DOCKER_TARGETS=$(notdir $@) BLDENV=buster $(MAKE) -f Makefile.work buster
endif
ifeq ($(NOBULLSEYE), 0)
BLDENV=bullseye make -f Makefile.work $@
BLDENV=bullseye $(MAKE) -f Makefile.work $@
endif
BLDENV=bullseye make -f Makefile.work docker-cleanup
BLDENV=bullseye $(MAKE) -f Makefile.work docker-cleanup

jessie:
@echo "+++ Making $@ +++"
ifeq ($(NOJESSIE), 0)
make -f Makefile.work jessie
$(MAKE) -f Makefile.work jessie
endif

stretch:
@echo "+++ Making $@ +++"
ifeq ($(NOSTRETCH), 0)
make -f Makefile.work stretch
$(MAKE) -f Makefile.work stretch
endif

buster:
@echo "+++ Making $@ +++"
ifeq ($(NOBUSTER), 0)
make -f Makefile.work buster
$(MAKE) -f Makefile.work buster
endif

init:
@echo "+++ Making $@ +++"
make -f Makefile.work $@
$(MAKE) -f Makefile.work $@

#
# Function to invoke target $@ in Makefile.work with proper BLDENV
#
define make_work
@echo "+++ Making $@ +++"
$(if $(BUILD_JESSIE),make -f Makefile.work $@,)
$(if $(BUILD_STRETCH),BLDENV=stretch make -f Makefile.work $@,)
$(if $(BUILD_BUSTER),BLDENV=buster make -f Makefile.work $@,)
$(if $(BUILD_BULLSEYE),BLDENV=bullseye make -f Makefile.work $@,)
$(if $(BUILD_JESSIE),$(MAKE) -f Makefile.work $@,)
$(if $(BUILD_STRETCH),BLDENV=stretch $(MAKE) -f Makefile.work $@,)
$(if $(BUILD_BUSTER),BLDENV=buster $(MAKE) -f Makefile.work $@,)
$(if $(BUILD_BULLSEYE),BLDENV=bullseye $(MAKE) -f Makefile.work $@,)
endef

.PHONY: $(PLATFORM_PATH)
Expand Down
Loading

0 comments on commit f00c204

Please sign in to comment.