From 92efb0ab142d64753e22a16ddedefd07d84195bb Mon Sep 17 00:00:00 2001 From: hanhxiao Date: Thu, 11 Jul 2019 17:32:13 +0800 Subject: [PATCH 1/3] bumping version to v0.0.16 --- gnes/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gnes/__init__.py b/gnes/__init__.py index 27234b57..f9f50bf2 100644 --- a/gnes/__init__.py +++ b/gnes/__init__.py @@ -15,4 +15,4 @@ # pylint: disable=low-comment-ratio -__version__ = '0.0.15' +__version__ = '0.0.16' From abba5e8a630f986275e5a452a37ee70a638f88f5 Mon Sep 17 00:00:00 2001 From: hanhxiao Date: Thu, 11 Jul 2019 19:52:05 +0800 Subject: [PATCH 2/3] ci(drone): auto release with cron job --- .drone.yml | 63 ++++++++++++++++- .github/release-template.ejs | 132 +++++++++++++++++++++++++++++++++++ gnes/__init__.py | 4 +- release.sh | 34 ++++----- 4 files changed, 213 insertions(+), 20 deletions(-) create mode 100644 .github/release-template.ejs diff --git a/.drone.yml b/.drone.yml index 80d9b392..269c06f2 100644 --- a/.drone.yml +++ b/.drone.yml @@ -99,14 +99,14 @@ steps: image: gnes/ci-base environment: GNES_ENV_SET: orange-ci - CODECOV_TOKEN_PR: - from_secret: CODECOV_TOKEN_PR + CODECOV_TOKEN: + from_secret: CODECOV_TOKEN commands: - pip install -e .[all] - pip install coverage codecov - coverage run -m unittest discover -s tests/ - coverage report --skip-covered - - codecov --token $CODECOV_TOKEN_PR + - codecov --token $CODECOV_TOKEN - name: notify the sucess on wechat work image: byrnedo/alpine-curl @@ -138,3 +138,60 @@ trigger: - master event: - push + +--- +kind: pipeline +name: default + +clone: + depth: 50 + +steps: +- name: notify the start on wechat work + image: byrnedo/alpine-curl + environment: + BOT_URL: + from_secret: BOT_URL + commands: + - export MSG_LINK=${DRONE_BUILD_LINK} + - export MSG_TITLE="⌛📜 Auto-bumping version \`$DRONE_SOURCE_BRANCH\`(\`${DRONE_BUILD_NUMBER}\`)" + - export MSG_CONTENT="click the link below to see the status" + - ./shell/push-wechatwork.sh + +- name: pip-install gnes + image: gnes/ci-base + environment: + GNES_ENV_SET: orange-ci + GITHUB_ACCESS_TOKEN: + from_secret: GITHUB_ACCESS_TOKEN + TWINE_USERNAME: + from_secret: TWINE_USERNAME + TWINE_PASSWORD: + from_secret: TWINE_PASSWORD + commands: + - ./release.sh + +- name: notify the sucess on wechat work + image: byrnedo/alpine-curl + environment: + BOT_URL: + from_secret: BOT_URL + commands: + - export MSG_LINK=$DRONE_REPO_LINK + - export MSG_TITLE="✅😃 A new version is generated!" + - export MSG_CONTENT="Github Release, Docker, PyPi will be all updated!" + - ./shell/push-wechatwork.sh + +- name: notify the failure on wechat work + image: byrnedo/alpine-curl + environment: + BOT_URL: + from_secret: BOT_URL + commands: + - export MSG_LINK=$DRONE_BUILD_LINK + - export MSG_TITLE="❌😥 Fail to generate new version!" + - export MSG_CONTENT="please inform [$DRONE_COMMIT_AUTHOR]($DRONE_COMMIT_AUTHOR_EMAIL) to modify and fix [\`$DRONE_SOURCE_BRANCH\`]($DRONE_COMMIT_LINK). click the link below to see the details." + - ./shell/push-wechatwork.sh + when: + status: + - failure \ No newline at end of file diff --git a/.github/release-template.ejs b/.github/release-template.ejs new file mode 100644 index 00000000..92cf7f0f --- /dev/null +++ b/.github/release-template.ejs @@ -0,0 +1,132 @@ +<% + +var groupCommits = [{ + name: 'feat', + show: true, + list: [] +}, { + name: 'fix', + show: true, + list: [] +}, { + name: 'refactor', + show: true, + list: [] +}, { + name: 'docs', + show: true, + list: [] +}, { + name: 'other', + show: true, + list: [] +}] + +var all_titles = {}; + +commits.forEach(function (commit) { + + var result = (commit.title).match(/^(\w*)(\((.*)\))?\: (.*)$/); + + var type = result && result[1]; + var scope = result && result[3]; + var title = result && result[4]; + + if (!(title in all_titles)) { + all_titles[title] = 1 + + if(type == 'fix' || type == 'fixed'){ + groupCommits.find(item => item.name === 'fix').list.push({ + type: type, + scope: scope, + title: title, + commit: commit + }) + } else if(type == 'feat' || type == 'feature'){ + groupCommits.find(item => item.name === 'feat').list.push({ + type: type, + scope: scope, + title: title, + commit: commit + }) + } else if(type == 'refactor'){ + groupCommits.find(item => item.name === 'refactor').list.push({ + type: type, + scope: scope, + title: title, + commit: commit + }) + } else if(type == 'docs' || type == 'doc'){ + groupCommits.find(item => item.name === 'docs').list.push({ + type: type, + scope: scope, + title: title, + commit: commit + }) + } else { + groupCommits.find(item => item.name === 'other').list.push({ + type: type, + scope: scope, + title: title, + commit: commit + }) + } + } + + +}); + + +var listCommits = function(list, key){ + +list.forEach(function (ct) { + + var type = ct.type; + var scope = ct.scope; + var title = ''; + var commit = ct.commit; + + if(type){ + if(key != 'other'){ + title = (scope? '__'+scope+'__: ':'') + ct.title; + }else{ + title = '__' + type + (scope? '('+scope+')':'') + '__ : ' + ct.title; + } + }else{ + title = commit.title; + } +%> - <% if(typeof commitHref === 'undefined' || commitHref === '') { %>[```<%=commit.sha1.slice(0,8)%>```]<% } else { %>[[```<%=commit.sha1.slice(0,8)%>```](<%=commitHref%><%=commit.sha1%>)]<%}%> __-__ <%=title%> (<%= commit.authorName %>) +<% })} +%> + +# Release Notes + +<% + + + for(var i of groupCommits){ + if(i.list.length == 0) continue; + +if (i.name === 'fix' && i.show) { %> + +### Bug fixes + +<% } else if( i.name === 'feat' && i.show) { %> + +### New Features + +<% } else if(i.name === 'refactor' && i.show) { %> + +### Code Refactoring + +<% } else if(i.name === 'docs' && i.show) { %> + +### Documentation + +<% } else if (i.name === 'other' && i.show) { %> + +### Other Improvements + +<% } + i.show && listCommits(i.list, i); +} %> \ No newline at end of file diff --git a/gnes/__init__.py b/gnes/__init__.py index f9f50bf2..c0bfd397 100644 --- a/gnes/__init__.py +++ b/gnes/__init__.py @@ -15,4 +15,6 @@ # pylint: disable=low-comment-ratio -__version__ = '0.0.16' +# do not change this line +# this is managed by git tag and replaced on every release +__version__ = '0.0.0-dev' diff --git a/release.sh b/release.sh index 5bcd170f..ef24b547 100755 --- a/release.sh +++ b/release.sh @@ -2,9 +2,10 @@ set -e -CODE_BASE='gnes/__init__.py' +INIT_FILE='gnes/__init__.py' +TMP_INIT_FILE='.__init__.py.tmp' VER_TAG='__version__ = ' -SOURCE_ORIGIN='github' +SOURCE_ORIGIN='origin' function escape_slashes { sed 's/\//\\\//g' @@ -17,7 +18,7 @@ function change_line { local NEW=$(echo "${NEW_LINE}" | escape_slashes) sed -i .bak '/'"${OLD_LINE_PATTERN}"'/s/.*/'"${NEW}"'/' "${FILE}" - mv "${FILE}.bak" /tmp/ + mv "${FILE}.bak" ${TMP_INIT_FILE} } @@ -36,10 +37,8 @@ function pub_pypi { } function pub_gittag { - git add -u - git commit -m "bumping version to $VER" - git push $SOURCE_ORIGIN master - git tag $VER + git tag $VER -m "$(cat ./CHANGELOG.md)" + git remote add $SOURCE_ORIGIN https://hanxiao:${GITHUB_ACCESS_TOKEN}@github.com/gnes-ai/gnes.git git push $SOURCE_ORIGIN $VER } @@ -54,19 +53,22 @@ fi VER=$(git tag -l | sort -V |tail -n1) printf "current version:\t\e[1;33m$VER\e[0m\n" +git-release-notes v$VER..HEAD .github/release-template.ejs > ./CHANGELOG.md + VER=$(echo $VER | awk -F. -v OFS=. 'NF==1{print ++$NF}; NF>1{$NF=sprintf("%0*d", length($NF), ($NF+1)); print}') printf "bump version to:\t\e[1;32m$VER\e[0m\n" read -p "release this version? " -n 1 -r -echo # (optional) move to a new line -if [[ $REPLY =~ ^[Yy]$ ]] -then - # write back tag to client and server code - VER_VAL=$VER_TAG"'"${VER#"v"}"'" - change_line "$VER_TAG" "$VER_VAL" $CODE_BASE - pub_pypi - pub_gittag -fi +#echo # (optional) move to a new line +#if [[ $REPLY =~ ^[Yy]$ ]] +#then +# write back tag to client and server code +VER_VAL=$VER_TAG"'"${VER#"v"}"'" +change_line "$VER_TAG" "$VER_VAL" $INIT_FILE +pub_pypi +pub_gittag +mv ${TMP_INIT_FILE} $INIT_FILE +#fi From bda562d18866f9ac8f26a4f6ea588303c80c7d53 Mon Sep 17 00:00:00 2001 From: hanhxiao Date: Thu, 11 Jul 2019 20:02:33 +0800 Subject: [PATCH 3/3] ci(drone): auto release with cron job --- .drone.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.drone.yml b/.drone.yml index 269c06f2..cdac9984 100644 --- a/.drone.yml +++ b/.drone.yml @@ -141,7 +141,7 @@ trigger: --- kind: pipeline -name: default +name: cron job auto release clone: depth: 50 @@ -194,4 +194,7 @@ steps: - ./shell/push-wechatwork.sh when: status: - - failure \ No newline at end of file + - failure + +trigger: + cron: [ nightly ] \ No newline at end of file