Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: changelog #311

Merged
merged 1 commit into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/labels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
- name: release/bug
description: bug pr recoded in new release
color: d73a4a
- name: release/feature
- name: release/feature-changed
description: feature pr recoded in new release
color: 0075ca
- name: release/feature-new
description: feature pr recoded in new release
color: 0075ca
- name: release/none
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/call-release-changelog.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ name: Call Release Changelog

env:
SCRIPT_PATH: "./tools/scripts/changelog.sh"
LABEL_FEATURE: "release/feature"
LABEL_FEATURE: "release/feature-new"
LABEL_CHANGED: "release/feature-changed"
LABEL_BUG: "release/bug"
DEST_BRANCH: github_pages
DEST_DIRECTORY: 'changelogs/'
Expand Down Expand Up @@ -82,6 +83,7 @@ jobs:
run: |
set -x
export LABEL_FEATURE=${{ env.LABEL_FEATURE }}
export LABEL_CHANGED=${{ env.LABEL_CHANGED }}
export LABEL_BUG=${{ env.LABEL_BUG }}
export PROJECT_REPO=${{ github.repository }}
export GH_TOKEN=${{ github.token }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr-label-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
types: [opened, labeled, unlabeled, synchronize]

env:
LEASE_ONE_OF_LABELS: "release/bug release/feature release/none pr/robot_update"
LEASE_ONE_OF_LABELS: "release/bug release/feature-new release/feature-changed release/none pr/robot_update"
FORBID_LABELS: "pr/not-ready not-ready"

jobs:
Expand Down
38 changes: 19 additions & 19 deletions docs/develop/release.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@

* update version in '/VERSION'

* a version tag should be set on right branch. The version should go with
* a version tag should be set on right branch. The version should go with

* v0.1.0-rc0
* v0.1.0-rc0

* v0.1.0-rc1
* v0.1.0-rc1

* v0.1.0

* v0.1.1

* v0.1.2

* v0.2.0-rc0

* v0.2.0
* v0.1.0
* v0.1.1
* v0.1.2
* v0.2.0-rc0
* v0.2.0

## push a version tag

Expand All @@ -34,19 +34,19 @@ If a tag vx.x.x is pushed , the following steps will automatically run:

4. generate the changelog by historical PR labeled as "pr/release/*"

submit the changelog file to directory 'changelogs' of branch 'github_pages', with PR labeled as "pr/release/robot_update_githubpage".
submit the changelog file to directory 'changelogs' of branch 'github_pages', with PR labeled as "pr/release/robot_update_githubpage".

changelogs is generated by historical PR label:
changelogs is generated by historical PR label:

label "pr/release/feature-new" to be classified to "New Features"
label "release/feature-new" to be classified to "New Features"

label "pr/release/feature-changed" to be classified to "Changed Features"
label "release/feature-changed" to be classified to "Changed Features"

label "pr/release/feature-bug" to be classified to "Fixes"
label "release/bug" to be classified to "Fixes"

5. build the chart package with the pushed tag, and submit a PR to branch 'github_pages'
5. build the chart package with the pushed tag, and submit a PR to branch 'github_pages'

you cloud get the chart with command `helm repo add $REPO_NAME https://spidernet-io.github.io/$REPO_NAME `
you cloud get the chart with command `helm repo add $REPO_NAME https://kdoctor-io.github.io/$REPO_NAME `

6. submit '/docs' to '/docs' of branch 'github_pages'

Expand Down
83 changes: 61 additions & 22 deletions tools/scripts/changelog.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/bin/bash

# Copyright 2022 Authors of spidernet-io
# Copyright 2022 Authors of kdoctor-io
# SPDX-License-Identifier: Apache-2.0

# usage:
# GH_TOKEN=${{ github.token }} LABEL_FEATURE="release/feature-new" LABEL_BUG="release/bug" PROJECT_REPO="spidernet-io/spiderpool" changelog.sh ./ v0.3.6
# GH_TOKEN=${{ github.token }} LABEL_FEATURE="release/feature-new" LABEL_BUG="release/bug" PROJECT_REPO="spidernet-io/spiderpool" changelog.sh ./ v0.3.6 v0.3.5
# GH_TOKEN=${{ github.token }} LABEL_FEATURE="release/feature-new" LABEL_CHANGED="release/feature-changed" LABEL_BUG="release/bug" PROJECT_REPO="xxx/xxx" changelog.sh ./ v0.3.6
# GH_TOKEN=${{ github.token }} LABEL_FEATURE="release/feature-new" LABEL_CHANGED="release/feature-changed" LABEL_BUG="release/bug" PROJECT_REPO="xxx/xxx" changelog.sh ./ v0.3.6 v0.3.5


CURRENT_DIR_PATH=$(cd `dirname $0`; pwd)
Expand All @@ -16,23 +16,29 @@ set -o errexit
set -o nounset
set -o pipefail

#required
# optional
OUTPUT_DIR=${1}
#required
# required
DEST_TAG=${2}
# optional
START_TAG=${3:-""}

#required
LABEL_FEATURE=${LABEL_FEATURE}
#required
LABEL_BUG=${LABEL_BUG}
#required
PROJECT_REPO=${PROJECT_REPO}

LABEL_FEATURE=${LABEL_FEATURE:-"release/feature-new"}
LABEL_CHANGED=${LABEL_BUG:-"release/feature-changed"}
LABEL_BUG=${LABEL_BUG:-"release/bug"}
PROJECT_REPO=${PROJECT_REPO:-""}
[ -n "$PROJECT_REPO" ] || { echo "miss PROJECT_REPO"; exit 1 ; }
[ -n "${GH_TOKEN}" ] || { echo "error, miss GH_TOKEN"; exit 1 ; }

( cd ${OUTPUT_DIR} ) || { echo "error, OUTPUT_DIR '${OUTPUT_DIR}' is not a valid directory" ; exit 1 ; }
OUTPUT_DIR=$(cd ${OUTPUT_DIR}; pwd)
echo "generate changelog to directory ${OUTPUT_DIR}"
cd ${OUTPUT_DIR}

# change to root for git cli
cd ${PROJECT_ROOT_PATH}

#============================

ORIGIN_START_TAG=${START_TAG}
if [ -z "${START_TAG}" ] ; then
Expand Down Expand Up @@ -101,32 +107,52 @@ echo "DEST_TAG=${DEST_TAG}"
echo "START_TAG=${START_TAG}"

# check whether tag START_TAG exists
ALL_PR_INFO=""
ALL_COMMIT=""
if [ -z "${ORIGIN_START_TAG}" ] && (( START_X == 0 )) && (( START_Y == 0 )) && (( START_Z == 0 )); then
ALL_PR_INFO=`git log ${DEST_TAG} --reverse --merges --oneline` \
ALL_COMMIT=`git log ${DEST_TAG} --reverse --oneline | awk '{print $1}' | tr '\n' ' ' ` \
|| { echo "error, failed to get PR for tag ${DEST_TAG} " ; exit 1 ; }
else
ALL_PR_INFO=`git log ${START_TAG}..${DEST_TAG} --reverse --merges --oneline` \
ALL_COMMIT=`git log ${START_TAG}..${DEST_TAG} --reverse --oneline | awk '{print $1}' | tr '\n' ' ' ` \
|| { echo "error, failed to get PR for tag ${DEST_TAG} " ; exit 1 ; }
fi
echo "ALL_COMMIT: ${ALL_COMMIT}"

ALL_PR_NUM=` grep -oE " Merge pull request #[0-9]+ " <<< "$ALL_PR_INFO" | grep -oE "[0-9]+" `
TOTAL_COUNT=` wc -l <<< "${ALL_PR_NUM}" `

TOTAL_COUNT="0"
PR_LIST=""
#
FEATURE_PR=""
CHANGED_PR=""
FIX_PR=""
for PR in ${ALL_PR_NUM} ; do
for COMMIT in ${ALL_COMMIT} ; do
# API RATE LIMIT
# https://docs.github.com/en/rest/overview/resources-in-the-rest-api?apiVersion=2022-11-28#rate-limiting
# When using GITHUB_TOKEN, the rate limit is 1,000 requests per hour per repository
# GitHub Enterprise Cloud's rate limit applies, and the limit is 15,000 requests per hour per repository.
COMMIT_INFO=` curl -s -H "Accept: application/vnd.github.groot-preview+json" -H "Authorization: Bearer ${GH_TOKEN}" https://api.github.com/repos/${PROJECT_REPO}/commits/${COMMIT}/pulls `
PR=` jq -r '.[].number' <<< "${COMMIT_INFO}" `
[ -n "${PR}" ] || { echo "warning, failed to find PR number for commit ${COMMIT} " ; echo "${COMMIT_INFO}" ; echo "" ; continue ; }
if grep " ${PR} " <<< " ${PR_LIST} " &>/dev/null ; then
continue
else
PR_LIST+=" ${PR} "
fi
(( TOTAL_COUNT+=1 ))
INFO=` gh pr view ${PR} `
TITLE=` grep -E "^title:[[:space:]]+" <<< "$INFO" | sed -E 's/title:[[:space:]]+//' `
LABELS=` grep -E "^labels:[[:space:]][^\[]" <<< "$INFO" | sed -E 's/labels://' | tr ',' ' ' ` || true
#
PR_URL="https://github.com/${PROJECT_REPO}/pull/${PR}"
#
if grep -E "[[:space:]]${LABEL_FEATURE}[[:space:]]" <<< " ${LABELS} " &>/dev/null ; then
echo "get new feature PR ${PR}"
FEATURE_PR+="* ${TITLE} : [PR ${PR}](${PR_URL})
"
elif grep -E "[[:space:]]${LABEL_CHANGED}[[:space:]]" <<< " ${LABELS} " &>/dev/null ; then
echo "get changed feature PR ${PR}"
CHANGED_PR+="* ${TITLE} : [PR ${PR}](${PR_URL})
"
elif grep -E "[[:space:]]${LABEL_BUG}[[:space:]]" <<< " ${LABELS} " &>/dev/null ; then
echo "get bug fix PR ${PR}"
FIX_PR+="* ${TITLE} : [PR ${PR}](${PR_URL})
"
fi
Expand All @@ -141,7 +167,7 @@ echo "***" >> ${FILE_CHANGELOG}
echo "" >> ${FILE_CHANGELOG}
#
if [ -n "${FEATURE_PR}" ]; then
echo "## Feature" >> ${FILE_CHANGELOG}
echo "## New Feature" >> ${FILE_CHANGELOG}
echo "" >> ${FILE_CHANGELOG}
while read LINE ; do
echo "${LINE}" >> ${FILE_CHANGELOG}
Expand All @@ -151,6 +177,17 @@ if [ -n "${FEATURE_PR}" ]; then
echo "" >> ${FILE_CHANGELOG}
fi
#
if [ -n "${CHANGED_PR}" ]; then
echo "## Changed Feature" >> ${FILE_CHANGELOG}
echo "" >> ${FILE_CHANGELOG}
while read LINE ; do
echo "${LINE}" >> ${FILE_CHANGELOG}
echo "" >> ${FILE_CHANGELOG}
done <<< "${CHANGED_PR}"
echo "***" >> ${FILE_CHANGELOG}
echo "" >> ${FILE_CHANGELOG}
fi
#
if [ -n "${FIX_PR}" ]; then
echo "## Fix" >> ${FILE_CHANGELOG}
echo "" >> ${FILE_CHANGELOG}
Expand All @@ -162,8 +199,10 @@ if [ -n "${FIX_PR}" ]; then
echo "" >> ${FILE_CHANGELOG}
fi
#
echo "## Totoal PR" >> ${FILE_CHANGELOG}
echo "## Totoal " >> ${FILE_CHANGELOG}
echo "" >> ${FILE_CHANGELOG}
echo "Pull request number: ${TOTAL_COUNT}" >> ${FILE_CHANGELOG}
echo "" >> ${FILE_CHANGELOG}
echo "[ ${TOTAL_COUNT} PR](https://github.com/${PROJECT_REPO}/compare/${START_TAG}...${DEST_TAG})" >> ${FILE_CHANGELOG}
echo "[ Commits ](https://github.com/${PROJECT_REPO}/compare/${START_TAG}...${DEST_TAG})" >> ${FILE_CHANGELOG}
echo "--------------------"
echo "generate changelog to ${FILE_CHANGELOG}"
Loading