|
| 1 | +name: Release |
| 2 | +on: |
| 3 | + push: |
| 4 | + tags: |
| 5 | + - 'release-v*.*.*' |
| 6 | +jobs: |
| 7 | + release: |
| 8 | + runs-on: ubuntu-latest |
| 9 | + env: |
| 10 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 11 | + steps: |
| 12 | + - name: Check out code from GitHub |
| 13 | + uses: actions/checkout@v3 |
| 14 | + with: |
| 15 | + fetch-depth: 0 |
| 16 | + - name: Get the pushed release tag |
| 17 | + id: get_pushed_tag |
| 18 | + run: | |
| 19 | + echo ::set-output name=tag::${{ github.ref }} |
| 20 | + echo ::set-output name=tag_short::$(echo ${{ github.ref }} | grep -ioP '/\K[^/]+$') |
| 21 | + - name: Get the latest release tag |
| 22 | + id: get_latest_release |
| 23 | + run: | |
| 24 | + result=$(gh release view --json tagName) |
| 25 | + echo $result |
| 26 | + if [ $result -eq "release not found" ]; then |
| 27 | + LATEST_RELEASE_TAG="" |
| 28 | + else |
| 29 | + LATEST_RELEASE_TAG=$(echo $result | jq -r .tagName) |
| 30 | + fi |
| 31 | +
|
| 32 | + echo "::set-output name=tag::${LATEST_RELEASE_TAG}" |
| 33 | + echo "::set-output name=tag_short::$(echo $LATEST_RELEASE_TAG | grep -ioP '/\K[^/]+$')" |
| 34 | + - name: Create a release note |
| 35 | + id: get_release_note |
| 36 | + run: | |
| 37 | + previous_tag=${{ steps.get_latest_release.outputs.tag }} |
| 38 | + pushed_tag=${{ steps.get_pushed_tag.outputs.tag }} |
| 39 | +
|
| 40 | + # リリースノートの内容を保存する変数 |
| 41 | + BUG_PR_LIST="" |
| 42 | + ENHANCEMENT_PR_LIST="" |
| 43 | + OTHER_PR_LIST="" |
| 44 | +
|
| 45 | + # PRマージ時のコメントからPR番号を抽出 |
| 46 | + pr_num_list=$(git log --pretty=format:"%s" $previous_tag..$pushed_tag | grep -oP 'Merge pull request #\K\d+') |
| 47 | +
|
| 48 | + while read pr; do |
| 49 | + echo "PR: #$pr" |
| 50 | + # プルリクエスト情報を取得 ------------------------------------------------- |
| 51 | + pr_info=$(gh pr view --json number,title,body $pr) |
| 52 | + number=$(echo $pr_info | jq -r '.number') |
| 53 | + title=$(echo $pr_info | jq -r '.title') |
| 54 | + echo -e "title: $title" |
| 55 | +
|
| 56 | + # issueからラベルを取得して分類 -------------------------------------------- |
| 57 | + # プルリクエスト情報からissue番号を抽出 |
| 58 | + body=$(echo $pr_info | jq -r '.body') |
| 59 | + issue=$(echo $body | grep -ioP 'close #\K\d+' | head -1) |
| 60 | + if [ -z "$issue" ]; then |
| 61 | + issue=$(echo $title | grep -ioP '#\K\d+' | head -1) |
| 62 | + fi |
| 63 | + if [ -z "$issue" ]; then |
| 64 | + # issueが見つからない場合はOtherに分類 |
| 65 | + echo "issue not found" |
| 66 | + OTHER_PR_LIST+="- $title\n" |
| 67 | + echo "" |
| 68 | + continue |
| 69 | + fi |
| 70 | + echo -e "issue: #$issue" |
| 71 | +
|
| 72 | + # issueの情報を取得 |
| 73 | + issue_info=$(gh issue view --json number,title,labels $issue) |
| 74 | + labels=$(echo $issue_info | jq -r '.labels[].name') |
| 75 | + echo -e "labels: $labels" |
| 76 | +
|
| 77 | + # ラベルで分類 |
| 78 | + if echo "$labels" | grep -q "bug"; then |
| 79 | + BUG_PR_LIST+="- $title\n" |
| 80 | + elif echo "$labels" | grep -q "enhancement"; then |
| 81 | + ENHANCEMENT_PR_LIST+="- $title\n" |
| 82 | + else |
| 83 | + OTHER_PR_LIST+="- $title\n" |
| 84 | + fi |
| 85 | + echo "" |
| 86 | + done < <(echo "$pr_num_list") |
| 87 | +
|
| 88 | + # リリースノートの内容を出力 |
| 89 | + cat <<EOF > release_note.txt |
| 90 | + ## Enhancements |
| 91 | + $(echo -e $ENHANCEMENT_PR_LIST) |
| 92 | + ## Bug fixes |
| 93 | + $(echo -e $BUG_PR_LIST) |
| 94 | + ## Other |
| 95 | + $(echo -e $OTHER_PR_LIST) |
| 96 | + EOF |
| 97 | + - name: Create a release |
| 98 | + id: create_release |
| 99 | + uses: actions/create-release@v1 |
| 100 | + env: |
| 101 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 102 | + with: |
| 103 | + tag_name: ${{ steps.get_pushed_tag.outputs.tag_short }} |
| 104 | + release_name: ${{ steps.get_pushed_tag.outputs.tag_short }} |
| 105 | + body_path: release_note.txt |
| 106 | + draft: false |
| 107 | + prerelease: false |
0 commit comments