From ea7ca5760d38299dcaa674223b4daa29dc59efe3 Mon Sep 17 00:00:00 2001 From: k-tanaka-v Date: Wed, 21 Feb 2024 11:19:36 +0900 Subject: [PATCH] =?UTF-8?q?#176=20release-x.y.z=E3=81=AE=E3=82=BF=E3=82=B0?= =?UTF-8?q?=E3=81=8C=E3=81=A4=E3=81=84=E3=81=9F=E3=81=A8=E3=81=8D=E3=81=AE?= =?UTF-8?q?=E3=81=BF=E8=87=AA=E5=8B=95=E3=81=A7=E3=83=AA=E3=83=AA=E3=83=BC?= =?UTF-8?q?=E3=82=B9=E3=83=8E=E3=83=BC=E3=83=88=E3=82=92=E4=BD=9C=E6=88=90?= =?UTF-8?q?=E3=81=99=E3=82=8B=E8=A8=AD=E5=AE=9A=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/release.yml | 107 ++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..9b0099e --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,107 @@ +name: Release +on: + push: + tags: + - 'release-v*.*.*' +jobs: + release: + runs-on: ubuntu-latest + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + steps: + - name: Check out code from GitHub + uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Get the pushed release tag + id: get_pushed_tag + run: | + echo ::set-output name=tag::${{ github.ref }} + echo ::set-output name=tag_short::$(echo ${{ github.ref }} | grep -ioP '/\K[^/]+$') + - name: Get the latest release tag + id: get_latest_release + run: | + result=$(gh release view --json tagName) + echo $result + if [ $result -eq "release not found" ]; then + LATEST_RELEASE_TAG="" + else + LATEST_RELEASE_TAG=$(echo $result | jq -r .tagName) + fi + + echo "::set-output name=tag::${LATEST_RELEASE_TAG}" + echo "::set-output name=tag_short::$(echo $LATEST_RELEASE_TAG | grep -ioP '/\K[^/]+$')" + - name: Create a release note + id: get_release_note + run: | + previous_tag=${{ steps.get_latest_release.outputs.tag }} + pushed_tag=${{ steps.get_pushed_tag.outputs.tag }} + + # リリースノートの内容を保存する変数 + BUG_PR_LIST="" + ENHANCEMENT_PR_LIST="" + OTHER_PR_LIST="" + + # PRマージ時のコメントからPR番号を抽出 + pr_num_list=$(git log --pretty=format:"%s" $previous_tag..$pushed_tag | grep -oP 'Merge pull request #\K\d+') + + while read pr; do + echo "PR: #$pr" + # プルリクエスト情報を取得 ------------------------------------------------- + pr_info=$(gh pr view --json number,title,body $pr) + number=$(echo $pr_info | jq -r '.number') + title=$(echo $pr_info | jq -r '.title') + echo -e "title: $title" + + # issueからラベルを取得して分類 -------------------------------------------- + # プルリクエスト情報からissue番号を抽出 + body=$(echo $pr_info | jq -r '.body') + issue=$(echo $body | grep -ioP 'close #\K\d+' | head -1) + if [ -z "$issue" ]; then + issue=$(echo $title | grep -ioP '#\K\d+' | head -1) + fi + if [ -z "$issue" ]; then + # issueが見つからない場合はOtherに分類 + echo "issue not found" + OTHER_PR_LIST+="- $title\n" + echo "" + continue + fi + echo -e "issue: #$issue" + + # issueの情報を取得 + issue_info=$(gh issue view --json number,title,labels $issue) + labels=$(echo $issue_info | jq -r '.labels[].name') + echo -e "labels: $labels" + + # ラベルで分類 + if echo "$labels" | grep -q "bug"; then + BUG_PR_LIST+="- $title\n" + elif echo "$labels" | grep -q "enhancement"; then + ENHANCEMENT_PR_LIST+="- $title\n" + else + OTHER_PR_LIST+="- $title\n" + fi + echo "" + done < <(echo "$pr_num_list") + + # リリースノートの内容を出力 + cat < release_note.txt + ## Enhancements + $(echo -e $ENHANCEMENT_PR_LIST) + ## Bug fixes + $(echo -e $BUG_PR_LIST) + ## Other + $(echo -e $OTHER_PR_LIST) + EOF + - name: Create a release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ steps.get_pushed_tag.outputs.tag_short }} + release_name: ${{ steps.get_pushed_tag.outputs.tag_short }} + body_path: release_note.txt + draft: false + prerelease: false