Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into feature/addon-storage…
Browse files Browse the repository at this point in the history
…-ctrler
  • Loading branch information
nashtsai committed Jun 6, 2023
2 parents fdbbf60 + 6771b26 commit 3ab4a11
Show file tree
Hide file tree
Showing 1,673 changed files with 186,202 additions and 39,281 deletions.
2 changes: 1 addition & 1 deletion .github/localflows/github-action-locally.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ if ! [ -x "$(which act)" ]; then
fi

# run act
act --reuse --platform self-hosted=jashbook/golang-lint:1.19-latest --workflows .github/localflows/cicd-local.yml
act --reuse --platform self-hosted=jashbook/golang-lint:1.20-latest --workflows .github/localflows/cicd-local.yml
20 changes: 20 additions & 0 deletions .github/utils/bug_stats.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

set -o errexit
set -o nounset

# requires `git` and `gh` commands, ref. https://cli.github.com/manual/installation for installation guides.

workdir=$(dirname $0)
. ${workdir}/gh_env
. ${workdir}/functions.bash

bug_report_md_file=${1}

crit_cnt=$(cat ${bug_report_md_file} | grep crit | wc -l)
major_cnt=$(cat ${bug_report_md_file} | grep major | wc -l)
minor_cnt=$(cat ${bug_report_md_file} | grep minor | wc -l)
total_cnt=$(cat ${bug_report_md_file} | wc -l)
total_cnt=$((total_cnt-2))

printf "bug stats\ntotal open: %s\ncritial: %s\nmajor: %s\nminor: %s\n" ${total_cnt} ${crit_cnt} ${major_cnt} ${minor_cnt}
37 changes: 37 additions & 0 deletions .github/utils/bugs_not_in_current_milestone.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env bash

set -o errexit
set -o nounset
set -o pipefail

# requires `git` and `gh` commands, ref. https://cli.github.com/manual/installation for installation guides.

workdir=$(dirname $0)
. ${workdir}/gh_env
. ${workdir}/functions.bash

process_issue_rows() {
for ((i = 0; i < ${item_count}; i++))
do
local issue_body=$(echo ${last_issue_list} | jq -r ".[${i}]")
local issue_id=$(echo ${issue_body} | jq -r ".number")
local url=$(echo ${issue_body} | jq -r '.html_url')
local title=$(echo ${issue_body} | jq -r '.title')
local assignees=$(echo ${issue_body} | jq -r '.assignees[]?.login')
local state=$(echo ${issue_body}| jq -r '.state')
printf "[%s](%s) #%s | %s | %s | %s \n" "${title}" "${url}" "${issue_id}" "$(join_by , ${assignees})" "${state}"
gh_update_issue_milestone ${issue_id}
done
}

item_count=100
page=1
printf "%s | %s | %s \n" "Issue Title" "Assignees" "Issue State"
echo "---|---|---"
while [ "${item_count}" == "100" ]
do
gh_get_issues "none" "kind/bug" "open" ${page}
item_count=$(echo ${last_issue_list} | jq -r '. | length')
process_issue_rows
page=$((page+1))
done
23 changes: 23 additions & 0 deletions .github/utils/create_releasing_pr.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash

set -o errexit
set -o nounset
set -o pipefail

# requires `git` and `gh` commands, ref. https://cli.github.com/manual/installation for installation guides.

workdir=$(dirname $0)
. ${workdir}/gh_env
. ${workdir}/functions.bash

set -x

git stash
git switch ${HEAD_BRANCH}
git pull
git rebase origin/${BASE_BRANCH}
git pull
git push

echo "Creating ${PR_TITLE}"
gh pr create --head ${HEAD_BRANCH} --base ${BASE_BRANCH} --title "${PR_TITLE}" --body "" --label "releasing-task"
47 changes: 47 additions & 0 deletions .github/utils/current_milestone_bugs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env bash

set -o errexit
set -o nounset
set -o pipefail

# requires `git` and `gh` commands, ref. https://cli.github.com/manual/installation for installation guides.

workdir=$(dirname $0)
. ${workdir}/gh_env
. ${workdir}/functions.bash

LABELS=${LABELS:-'kind/bug,bug'} #"severity/critical,severity/major,severity/minor,severity/normal"

print_issue_rows() {
for ((i = 0; i < ${item_count}; i++))
do
local issue_body=$(echo ${last_issue_list} | jq -r ".[${i}]")
local issue_id=$(echo ${issue_body} | jq -r ".number")
local url=$(echo ${issue_body} | jq -r '.html_url')
local title=$(echo ${issue_body} | jq -r '.title')
local assignees=$(echo ${issue_body} | jq -r '.assignees[]?.login')
local state=$(echo ${issue_body}| jq -r '.state')
local labels=$(echo ${issue_body} | jq -r '.labels[]?.name')
printf "[%s](%s) #%s | %s | %s | %s \n" "${title}" "${url}" "${issue_id}" "$(join_by , ${assignees})" "${state}" "$(join_by , ${labels})"
done
}

count_total=0
item_count=100
page=1
echo ""
printf "%s | %s | %s | %s \n" "Issue Title" "Assignees" "Issue State" "Labels"
echo "---|---|---|---"
while [ "${item_count}" == "100" ]
do
gh_get_issues ${MILESTONE_ID} "${LABELS}" "open" ${page}
item_count=$(echo ${last_issue_list} | jq -r '. | length')
print_issue_rows
page=$((page+1))
count_total=$((count_total + item_count))
done

if [ -n "$DEBUG" ]; then
echo ""
echo "total items: ${count_total}"
fi
72 changes: 36 additions & 36 deletions .github/utils/feature_triage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,44 @@ set -o errexit
set -o nounset
set -o pipefail

REMOTE_URL=$(git config --get remote.origin.url)
OWNER=$(dirname ${REMOTE_URL} | awk -F ":" '{print $2}')
REPO=$(basename -s .git ${REMOTE_URL})
MILESTONE_ID=${MILESTONE_ID:-5}
# requires `git`, `gh`, and `jq` commands, ref. https://cli.github.com/manual/installation for installation guides.

# GH list issues API ref: https://docs.github.com/en/rest/issues/issues?apiVersion=2022-11-28#list-repository-issues
ISSUE_LIST=$(gh api \
--header 'Accept: application/vnd.github+json' \
--method GET \
/repos/${OWNER}/${REPO}/issues \
-F per_page=100 \
-f milestone=${MILESTONE_ID} \
-f labels=kind/feature \
-f state=all)

ROWS=$(echo ${ISSUE_LIST}| jq -r '. | sort_by(.state,.number)| .[].number')
workdir=$(dirname $0)
. ${workdir}/gh_env
. ${workdir}/functions.bash

print_issue_rows() {
for ((i = 0; i < ${item_count}; i++))
do
local issue_body=$(echo ${last_issue_list} | jq -r ".[${i}]")
local issue_id=$(echo ${issue_body} | jq -r ".number")
local url=$(echo ${issue_body} | jq -r '.html_url')
local title=$(echo ${issue_body} | jq -r '.title')
local assignees=$(echo ${issue_body} | jq -r '.assignees[]?.login')
local state=$(echo ${issue_body}| jq -r '.state')
local labels=$(echo ${issue_body} | jq -r '.labels[]?.name')
pr_url=$(echo ${issue_body} | jq -r '.pull_request?.url')
if [ "$pr_url" == "null" ]; then
pr_url="N/A"
fi
printf "[%s](%s) #%s | %s | %s | %s| | \n" "${title}" "${url}" "${issue_id}" "$(join_by , ${assignees})" "${state}" "${pr_url}"
done
}

count_total=0
item_count=100
page=1
echo ""
printf "%s | %s | %s | %s | %s | %s\n" "Feature Title" "Assignees" "Issue State" "Code PR Merge Status" "Feature Doc. Status" "Extra Notes"
echo "---|---|---|---|---|---"
for ROW in $ROWS
do
ISSUE_ID=$(echo $ROW | awk -F "," '{print $1}')
# GH get issue API ref: https://docs.github.com/en/rest/issues/issues?apiVersion=2022-11-28#get-an-issue
ISSUE_BODY=$(gh api \
--header 'Accept: application/vnd.github+json' \
--method GET \
/repos/${OWNER}/${REPO}/issues/${ISSUE_ID})
URL=$(echo $ISSUE_BODY| jq -r '.url')
TITLE=$(echo $ISSUE_BODY| jq -r '.title')
ASSIGNEES=$(echo $ISSUE_BODY| jq -r '.assignees[]?.login')
ASSIGNEES_PRINTABLE=
for ASSIGNEE in $ASSIGNEES
do
ASSIGNEES_PRINTABLE="${ASSIGNEES_PRINTABLE},${ASSIGNEE}"
done
ASSIGNEES_PRINTABLE=${ASSIGNEES_PRINTABLE#,}
STATE=$(echo $ISSUE_BODY| jq -r '.state')
PR=$(echo $ISSUE_BODY| jq -r '.pull_request?.url')
printf "[%s](%s) #%s | %s | %s | | | \n" "$TITLE" $URL $ISSUE_ID "$ASSIGNEES_PRINTABLE" "$STATE"
done
while [ "${item_count}" == "100" ]
do
gh_get_issues ${MILESTONE_ID} "kind/feature" "all" ${page}
item_count=$(echo ${last_issue_list} | jq -r '. | length')
print_issue_rows
page=$((page+1))
count_total=$((count_total + item_count))
done

echo ""
echo "total items: ${count_total}"
112 changes: 112 additions & 0 deletions .github/utils/functions.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# bash functions

DEBUG=${DEBUG:-}
# requires `gh` command, ref. https://cli.github.com/manual/installation for installation guides.

gh_get_issues () {
# @arg milestone - Milestone ID, if the string none is passed, issues without milestones are returned.
# @arg labels - A list of comma separated label names, processed as OR query.
# @arg state - Can be one of: open, closed, all; Default: open.
# @arg page - Cardinal value; Default: 1
# @result $last_issue_list - contains JSON result
declare milestone="$1" labels="$2" state="${3:-open}" page="${4:-1}"
local label_filter=""
IFS=',' read -ra label_items <<< "${labels}"
for i in "${label_items[@]}"; do
label_filter="${label_filter} -f labels=${i}"
done
_gh_get_issues ${milestone} "${label_filter}" ${state} ${page}
}

gh_get_issues_with_and_labels () {
# @arg milestone - Milestone ID, if the string none is passed, issues without milestones are returned.
# @arg labels - A list of comma separated label names, processed as AND query.
# @arg state - Can be one of: open, closed, all; Default: open.
# @arg page - Cardinal value; Default: 1
# @result $last_issue_list - contains JSON result
declare milestone="$1" labels="$2" state="${3:-open}" page="${4:-1}"
_gh_get_issues ${milestone} "-f labels=${labels}" ${state} ${page}
}

_gh_get_issues () {
# @arg milestone - Milestone ID, if the string none is passed, issues without milestones are returned.
# @arg label_filter - Label fileter query params.
# @arg state - Can be one of: open, closed, all; Default: open.
# @arg page - Cardinal value; Default: 1
# @result $last_issue_list - contains JSON result
declare milestone="$1" label_filter="$2" state="${3:-open}" page="${4:-1}"

# GH list issues API ref: https://docs.github.com/en/rest/issues/issues?apiVersion=2022-11-28#list-repository-issues
local cmd="gh api \
--method GET \
--header 'Accept: application/vnd.github+json' \
--header 'X-GitHub-Api-Version: 2022-11-28' \
/repos/${OWNER}/${REPO}/issues \
-F per_page=100 \
-F page=${page} \
-f milestone=${milestone} \
${label_filter} \
-f state=${state}"
if [ -n "$DEBUG" ]; then echo $cmd; fi
last_issue_list=`eval ${cmd} 2> /dev/null`
}


gh_get_issue_body() {
# @arg issue_id - Github issue ID
# @result last_issue_body
# @result last_issue_url
# @result last_issue_title
# @result last_issue_state
# @result last_issue_assignees - multi-lines items
declare issue_id="$1"

local issue_body=$(gh api \
--method GET \
--header 'Accept: application/vnd.github+json' \
--header 'X-GitHub-Api-Version: 2022-11-28' \
/repos/${OWNER}/${REPO}/issues/${issue_id})
local url=$(echo ${issue_body} | jq -r '.url')
local title=$(echo ${issue_body} | jq -r '.title')
local assignees=$(echo ${issue_body} | jq -r '.assignees[]?.login')
local state=$(echo ${issue_body}| jq -r '.state')
last_issue_body="${issue_body}"
last_issue_url="${url}"
last_issue_title="${title}"
last_issue_state="${state}"
last_issue_assignees=${assignees}
}

gh_update_issue_milestone() {
# @arg issue_id - Github issue ID
# @arg milestone - Milestone ID, if the string none is passed, issues without milestones are returned.
# @result last_issue_resp
declare issue_id="$1" milestone_id="${2:-}"

if [ -z "$milestone_id" ]; then
milestone_id=${MILESTONE_ID}
fi

local req_data="{\"milestone\":$milestone_id}"

if [ -n "$DEBUG" ]; then echo "req_data=$req_data"; fi

local gh_token=$(gh auth token)
local resp=$(curl \
--location \
--request PATCH \
--header 'Accept: application/vnd.github+json' \
--header 'X-GitHub-Api-Version: 2022-11-28' \
--header "Authorization: Bearer ${gh_token}" \
--data "${req_data}" \
https://api.github.com/repos/${OWNER}/${REPO}/issues/${issue_id})

last_issue_resp=${resp}
}

function join_by {
local d=${1-} f=${2-}
if shift 2; then
printf %s "$f" "${@/#/$d}"
fi
}
46 changes: 46 additions & 0 deletions .github/utils/generate_kbcli_sha256.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env python3
# -*- coding:utf-8 -*-

# generate kbcli sha256 notes
# 1. open each *.sha256.txt in target direct
# 2. get the contain of the file
# 3. render the template

import os
import sys
from datetime import date
from string import Template

release_note_template_path = "docs/release_notes/template.md"

def main(argv: list[str]) -> None:
"""
:param: the kbcli version
:param: the sha256 files direct
:return None
"""
kbcli_version = argv[1]
sha256_direct = argv[2]
release_note_template_path = "docs/release_notes/kbcli_template.md"
release_note_path = f"docs/release_notes/{kbcli_version}/kbcli.md"

template = ""
try:
with open(release_note_template_path, "r") as file:
template = file.read()
except FileNotFoundError as e:
print(f"template {release_note_template_path} not found, IGNORED")

with open(release_note_path,'a') as f_dest:
f_dest.write(Template(template).safe_substitute(
kbcli_version = kbcli_version[1:],
today = date.today().strftime("%Y-%m-%d"),
))
for file in os.listdir(sha256_direct):
with open(os.path.join(sha256_direct, file),"r") as f:
f_dest.write(f.read())
f_dest.write('\n')
print("Done")

if __name__ == "__main__":
main(sys.argv)
Loading

0 comments on commit 3ab4a11

Please sign in to comment.