{"id":1172,"date":"2022-05-16T17:45:16","date_gmt":"2022-05-16T09:45:16","guid":{"rendered":"https:\/\/www.yinyubo.com\/?p=1172"},"modified":"2022-05-16T17:54:50","modified_gmt":"2022-05-16T09:54:50","slug":"1","status":"publish","type":"post","link":"https:\/\/www.yinyubo.com\/?p=1172","title":{"rendered":"\u901a\u8fc7\u5de5\u5177\u6765\u89c4\u8303\u4ee3\u7801\u63d0\u4ea4\u4e0e\u53d1\u5e03\u65e5\u5fd7"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u80cc\u666f<\/h2>\n\n\n\n<p>1.\u56e0\u4e3a\u6211\u4eec\u7684\u73b0\u573a\u7248\u672c\u53d1\u5e03\u662f\u6bd4\u8f83\u9891\u7e41\u7684\uff0c\u5173\u4e8e\u672c\u6b21\u53d1\u5e03\u4e3a\u4e86\u89e3\u51b3\u4ec0\u4e48\u95ee\u9898\uff0c\u4fee\u590d\u4e86\u4ec0\u4e48BUG\u3002\u8fd9\u4e2a\u5168\u9760\u9879\u76ee\u7ecf\u7406\u81ea\u89c9\uff0c\u5e76\u4e0d\u662f\u6bcf\u6b21\u53d1\u5e03\u90fd\u6709\u5199\uff0c\u4e5f\u4e0d\u4e00\u5b9a\u6bcf\u6b21\u90fd\u80fd\u5199\u7684\u5168\uff0c\u6211\u60f3\u6709\u4e00\u4e2a\u80fd\u515c\u5e95\u7684\u673a\u5236\u3002<\/p>\n\n\n\n<p>2.\u8fd9\u4e2a\u65f6\u5019\u6211\u60f3\u8d77\u4e86github\u53d1\u5e03\u7248\u672c\u65f6\u6709\u4e00\u4e2a\u201cauto-generate release notes\u201d\u529f\u80fd\uff0c\u5b83\u901a\u8fc7&nbsp;git logs&nbsp;\u547d\u4ee4\uff0c\u5c06\u4e24\u6b21\u7248\u672c\u53d8\u5316\u4e4b\u95f4\u7684git message\u4fe1\u606f\u5bfc\u51fa\u6210markdown\u683c\u5f0f\u7684\u6587\u6863\uff0c\u5982\u679c\u6211\u4eec\u7684gitea\u6709\u8fd9\u6837\u4e00\u4e2a\u5de5\u5177\uff0c\u90a3\u5c31\u592a\u68d2\u4e86.<\/p>\n\n\n\n<p>3.\u5728gitea\u5b98\u7f51\u548cgithub\u4e0a\u8fdb\u884c\u4e86\u67e5\u9605\uff0c\u53d1\u73b0gitea\u76ee\u524d\u4e0d\u6253\u7b97\u6284\u8fd9\u4e2a\u529f\u80fd\uff0c\u672a\u6765\u4e5f\u4e0d\u4f1a\u505a\uff0c\u800c\u6211\u4eec\u7684git\u670d\u52a1\u7aef\u7528\u7684\u662fgitea\uff0c\u4e8e\u662f\u6211\u60f3\u901a\u8fc7drone CI\u6d41\u6c34\u7ebf\u6765\u5b9e\u73b0\u8fd9\u4e2a\u529f\u80fd<\/p>\n\n\n\n<p>4.\u901a\u8fc7\u67e5\u9605\uff0c\u6211\u53d1\u73b0nodejs\u6709\u4e00\u4e2a\u5f88\u706b\u7684\u5de5\u5177<a href=\"https:\/\/github.com\/conventional-changelog\/standard-version\">https:\/\/github.com\/conventional-changelog\/standard-version<\/a>&nbsp;\u80fd\u591f\u5b8c\u6210\u8fd9\u4ef6\u4e8b\uff0c\u53ea\u8981\u6211\u4eec\u5f00\u53d1\u4eba\u5458\u63d0\u4ea4\u7684 git message\u662f\u7b26\u5408<a href=\"https:\/\/www.conventionalcommits.org\/\">https:\/\/www.conventionalcommits.org\/<\/a>\u548c<a href=\"https:\/\/semver.org\/\">https:\/\/semver.org\/<\/a>\u89c4\u8303\u7684\u5373\u53ef<\/p>\n\n\n\n<p>5.\u6839\u636e\u8fd9\u4e2a\u89c4\u8303\uff0c\u627e\u5230vscode\u91cc\u6709\u4e00\u4e2a\u63d2\u4ef6&#8221;Conventional Commits&#8221;\u5de5\u5177\u662f\u975e\u5e38\u5951\u5408\u7684<\/p>\n\n\n\n<p>6.\u7ed3\u5c40\u662f\u6211\u4eec\u7684\u5f00\u53d1\u4eba\u5458\uff0c\u53ea\u9700\u8981\u5728vscode\u4e0a\u5b89\u88c5\u597d\u8fd9\u4e2a&#8221;Conventional Commits&#8221;\u5de5\u5177\uff0c\u5e76\u4e14\u6839\u636e\u5de5\u5177\u63d0\u793a\u6765\u63d0\u4ea4\u4ee3\u7801\uff0c\u540e\u7eed\u5c31\u53ef\u4ee5\u81ea\u52a8\u751f\u6210changelog\u4e86\uff0c\u4ece\u800c\u8fbe\u5230\u6807\u51c6\u5316\u201c\u4ee3\u7801\u63d0\u4ea4\u201d\u548c\u201c\u53d1\u5e03\u65e5\u5fd7\u201d\u7684\u76ee\u7684<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u6548\u679c\u56fe<\/h2>\n\n\n\n<p>\u4e0b\u9762\u8fd9\u4e2aChangelog\u7531\u53d1\u5e03\u4e4b\u540e\u7684\u6d41\u6c34\u7ebf\u81ea\u52a8\u751f\u6210<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"945\" height=\"632\" src=\"https:\/\/www.yinyubo.com\/wp-content\/uploads\/2022\/05\/image.png\" alt=\"\" class=\"wp-image-1173\" srcset=\"https:\/\/www.yinyubo.com\/wp-content\/uploads\/2022\/05\/image.png 945w, https:\/\/www.yinyubo.com\/wp-content\/uploads\/2022\/05\/image-300x201.png 300w, https:\/\/www.yinyubo.com\/wp-content\/uploads\/2022\/05\/image-768x514.png 768w\" sizes=\"auto, (max-width: 945px) 100vw, 945px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u5f00\u53d1\u4eba\u5458\u505a\u4ec0\u4e48<\/h2>\n\n\n\n<p>\u5728vscode\u91cc\u4e0b\u8f7d\u8be5\u63d2\u4ef6\uff0c\u63d2\u4ef6\u6269\u5c55ID vivaxy.vscode-conventional-commits<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"358\" height=\"228\" src=\"https:\/\/www.yinyubo.com\/wp-content\/uploads\/2022\/05\/image-1.png\" alt=\"\" class=\"wp-image-1174\" srcset=\"https:\/\/www.yinyubo.com\/wp-content\/uploads\/2022\/05\/image-1.png 358w, https:\/\/www.yinyubo.com\/wp-content\/uploads\/2022\/05\/image-1-300x191.png 300w\" sizes=\"auto, (max-width: 358px) 100vw, 358px\" \/><\/figure>\n\n\n\n<p>\u63d0\u4ea4\u4ee3\u7801\u7684\u65f6\u5019\uff0c\u6309\u7167\u5de5\u5177\u63d0\u793a\u4e00\u8def\u9009\u62e9\u5373\u53ef<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"378\" src=\"https:\/\/www.yinyubo.com\/wp-content\/uploads\/2022\/05\/image-3-1024x378.png\" alt=\"\" class=\"wp-image-1180\" srcset=\"https:\/\/www.yinyubo.com\/wp-content\/uploads\/2022\/05\/image-3-1024x378.png 1024w, https:\/\/www.yinyubo.com\/wp-content\/uploads\/2022\/05\/image-3-300x111.png 300w, https:\/\/www.yinyubo.com\/wp-content\/uploads\/2022\/05\/image-3-768x283.png 768w, https:\/\/www.yinyubo.com\/wp-content\/uploads\/2022\/05\/image-3.png 1307w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u8fd0\u7ef4\u4eba\u5458\u505a\u4ec0\u4e48<\/h2>\n\n\n\n<p>\u6839\u636ehttps:\/\/github.com\/conventional-changelog\/standard-version\u5e93\u6765\u7f16\u5199\u4e00\u4e2a\u7b80\u5355\u7684\u6d41\u6c34\u7ebf\u5de5\u5177<\/p>\n\n\n\n<p>\u8fd9\u91cc\u6211\u7528\u7684\u4ee3\u7801\u662fpython\uff0c\u6d41\u6c34\u7ebf\u8fd0\u884c\u73af\u5883\u662fDroneCI\uff0cgit\u670d\u52a1\u7aef\u662fgitea<\/p>\n\n\n\n<p>\u5e9f\u8bdd\u4e0d\u591a\u8bf4\uff0c\u4e0b\u9762\u76f4\u63a5\u4e0a\u4ee3\u7801\uff0c\u53ef\u4ee5\u901a\u8fc7 docker build\u547d\u4ee4<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker build -t drone-changelog-plugin:1.0.1 .<\/code><\/pre>\n\n\n\n<p>\u53bb\u5236\u4f5cdrone\u7684\u6d41\u6c34\u7ebf\u955c\u50cf<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"357\" height=\"224\" src=\"https:\/\/www.yinyubo.com\/wp-content\/uploads\/2022\/05\/image-2.png\" alt=\"\" class=\"wp-image-1178\" srcset=\"https:\/\/www.yinyubo.com\/wp-content\/uploads\/2022\/05\/image-2.png 357w, https:\/\/www.yinyubo.com\/wp-content\/uploads\/2022\/05\/image-2-300x188.png 300w\" sizes=\"auto, (max-width: 357px) 100vw, 357px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">main.py<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>import os\nimport shutil\n\nimport requests\n\n\ndef search_tag_info(git_url,token, repo):\n    '''\n    \u641c\u7d22git\u4e0a\u7684tag\u4fe1\u606f\n    :param git_url: git \u7684\u5730\u5740\n    :param token: git \u7684access token\n    :param repo: git \u5f85\u67e5\u8be2\u7684git\u4ed3\u5e93\u4fe1\u606f\n    :return: tag\u4fe1\u606f\u96c6\u5408\n    '''\n    url = \"https:\/\/\"+git_url+\"\/api\/v1\/repos\/\" + repo + \"\/releases\"\n    headers = {'accept': 'application\/json',\n               'Authorization': 'token ' + token,\n               'Content-Type': 'application\/json'\n               }\n    response = requests.get(url, headers=headers)\n    tag_list = response.json()\n    return tag_list\n\n\ndef modify_tag_body(git_url,token, repo, tag_id, body):\n    '''\n    \u4fee\u6539git\u4ed3\u5e93\u7684tag\u91cc\u7684\u5185\u5bb9\n    :param git_url: git \u7684\u5730\u5740\n    :param token: git \u7684access token\n    :param repo: git \u5f85\u67e5\u8be2\u7684git\u4ed3\u5e93\u4fe1\u606f\n    :param tag_id: git tag\u7684id\u4fe1\u606f\n    :param body: \u9700\u8981\u4fee\u6539\u7684\u5185\u5bb9\uff0c\u4e00\u822c\u662fchangelog.md\u6587\u4ef6\n    :return:\n    '''\n    url = \"https:\/\/\"+git_url+\"\/api\/v1\/repos\/\" + repo + \"\/releases\/\" + str(tag_id)\n    headers = {'accept': 'application\/json',\n               'Authorization': 'token ' + token,\n               'Content-Type': 'application\/json'\n               }\n    body = {\n        \"body\": body\n    }\n    response = requests.patch(url, json=body, headers=headers)\n\n\nif __name__ == '__main__':\n    print(os.environ)\n    tag = os.environ&#91;\"DRONE_TAG\"]\n    branch = os.environ&#91;\"DRONE_REPO_BRANCH\"]\n    username = os.environ&#91;\"DRONE_NETRC_USERNAME\"]\n    password = os.environ&#91;\"DRONE_NETRC_PASSWORD\"]\n    git_repo = os.environ&#91;\"DRONE_REPO\"]\n    git_token = os.environ&#91;\"PLUGIN_TOKEN\"]\n    src_file = \"\/lzw\/.versionrc\"\n    dst_foleder = os.environ&#91;\"DRONE_WORKSPACE\"]\n    git_url= os.environ&#91;\"PLUGIN_GIT_SERVER\"]\n    shutil.copy(src_file, dst_foleder)\n\n    # \u83b7\u53d6\u5f53\u524d\u4ed3\u5e93\u91cc\u6240\u6709\u7684tag\u4fe1\u606f\n    tag_info_list = search_tag_info(git_url,git_token, git_repo)\n    # \u83b7\u53d6\u6700\u65b0\u7684\u4e00\u4e2atag\n    now_tag = tag_info_list&#91;0]\n    # \u83b7\u53d6\u6240\u6709\u7684tag\u4fe1\u606f\uff0c\u8fd9\u4e2a\u5730\u65b9\u662f\u56e0\u4e3astandard-version\u7684\u7279\u6027\uff0c\n    # \u8981\u83b7\u53d6\u6240\u6709\u7684tag\u4fe1\u606f\uff0c\u518d\u5220\u6389\u5f53\u524d\u7684tag\u4fe1\u606f\uff0c\n    # \u518d\u4f7f\u7528standard-version \u91cd\u65b0\u751f\u6210\u4e00\u4e2atag\u4fe1\u606f\n    os.system(\"git remote set-url origin https:\/\/'\" + username + \"':'\" + password + \"'@\"+git_url+\"\/\" + git_repo)\n    os.system(\"git fetch --all\")\n    os.system(\"git tag -d \" + tag)\n    cmd = 'standard-version --tag-prefix \"\" --release-as ' + tag\n    print(cmd)\n    os.system(cmd)\n    # standard-version\u547d\u4ee4\u4f1a\u4ea7\u751f\u4e00\u4e2aCHANGELOG.md\u6587\u4ef6\n    with open('CHANGELOG.md', encoding='utf-8') as f:\n        line = f.read()\n    print(\"tag len is:\" + str(len(tag_info_list)))\n    # \u5224\u65ad\u4e00\u4e0b\u76ee\u524d\u6709\u51e0\u4e2atag,\u5206\u5272\u4fdd\u7559\u6700\u65b0\u7684git tag \u53d8\u66f4\u4fe1\u606f\n    if len(tag_info_list) &gt; 1:\n        pre = tag_info_list&#91;1]\n        list = line.split(\" \" + pre&#91;'tag_name'] + \" \")\n        # print(list&#91;0])\n        now_content = list&#91;0]\n    else:\n        now_content = line\n    # \u628aCHANGELOG.md\u4e2d\u672c\u6b21\u53d8\u66f4\u7684\u4f20\u5230git\u7684tag\u4fe1\u606f\u91cc\n    modify_tag_body(git_url,git_token, git_repo, now_tag&#91;'id'], now_content)\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Dockerfile<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>FROM python:3.9-buster\nLABEL maintainer=\"357244849@qq.com\"\n\nRUN set -eux \\\n    &amp;&amp; sed -i \"s@http:\/\/ftp.debian.org@https:\/\/repo.huaweicloud.com@g\" \/etc\/apt\/sources.list \\\n    &amp;&amp; sed -i \"s@http:\/\/security.debian.org@https:\/\/repo.huaweicloud.com@g\" \/etc\/apt\/sources.list \\\n    &amp;&amp; apt-get update \\\n    &amp;&amp; apt-get install -y nodejs npm\nENV NODE_PATH=\"\/usr\/lib\/node_modules\"\nENV LANG=C.UTF-8 PYTHONUNBUFFERED=1\nRUN npm i -g standard-version\nWORKDIR \/lzw\nADD . \/lzw\nRUN pip install -r \/lzw\/requirements.txt -i https:\/\/pypi.tuna.tsinghua.edu.cn\/simple\nCMD &#91;\"python3\",\"\/lzw\/main.py\"]\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">requirements.txt<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>requests<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">.versionrc<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n  \"types\": &#91;\n    {\"type\": \"feat\",\"section\": \"Features\"},\n    {\"type\": \"fix\",\"section\": \"Bug Fixes\"},\n    {\"type\": \"docs\",\"section\": \"Documentation\" },\n    {\"type\": \"style\",\"section\": \"Styling\" },\n    {\"type\": \"refactor\",\"section\": \"Refactors\" },\n    {\"type\": \"perf\",\"section\": \"Performance\" },\n    {\"type\": \"test\",\"section\": \"Tests\" },\n    {\"type\": \"build\",\"section\": \"Build System\" },\n    {\"type\": \"ci\",\"section\": \"CI\" },\n    {\"type\": \"chore\",\"section\": \"Chore\",\"hidden\":true },\n    {\"type\": \"revert\",\"section\": \"Reverts\" }\n  ]\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u5982\u4f55\u5d4c\u5165\u5230DroneCI\u6d41\u6c34\u7ebf\u5462<\/h2>\n\n\n\n<p>\u5728drone.yml\u6587\u4ef6\u91cc\u5d4c\u5165\u5982\u4e0byml\u5373\u53ef<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>---\nkind: pipeline\ntype: kubernetes\nname: tag\nsteps:\n  - name: generator change log\n    image: drone-changelog-plugin:1.0.1\n    settings:\n      token: XXXXXX\n      git_url: XXXXXX\ntrigger:\n  event:\n    - tag<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u80cc\u666f 1.\u56e0\u4e3a\u6211\u4eec\u7684\u73b0\u573a\u7248\u672c\u53d1\u5e03\u662f\u6bd4\u8f83\u9891\u7e41\u7684\uff0c\u5173\u4e8e\u672c\u6b21\u53d1\u5e03\u4e3a\u4e86\u89e3\u51b3\u4ec0\u4e48\u95ee\u9898\uff0c\u4fee\u590d\u4e86\u4ec0\u4e48BUG\u3002\u8fd9\u4e2a\u5168\u9760\u9879\u76ee\u7ecf\u7406 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-1172","post","type-post","status-publish","format-standard","hentry","category-k8s"],"_links":{"self":[{"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/posts\/1172","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1172"}],"version-history":[{"count":5,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/posts\/1172\/revisions"}],"predecessor-version":[{"id":1182,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/posts\/1172\/revisions\/1182"}],"wp:attachment":[{"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1172"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1172"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1172"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}