Skip to content

Commit

Permalink
Merge pull request #519 from NUTFes/feature/imaimai/auto-release-labe…
Browse files Browse the repository at this point in the history
…ling

自動リリース機能と自動ラベリング機能の実装
  • Loading branch information
imaimai17468 authored Apr 9, 2023
2 parents 0214113 + 2f709cc commit 7e52796
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 0 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/auto-labeling.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Automatically labeling pull request.

on:
pull_request:
types: [opened]

jobs:
auto-labeling-pr:
runs-on: ubuntu-latest

env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v2

# ラベル名を取得する
- name: Get label name
id: label_name
run: |
branch_type=$(echo ${{github.head_ref}} | cut -d "/" -f1)
if [ $branch_type == 'feature' ]; then
label_name=$(echo "enhancement")
elif [ $branch_type == 'fix' ] || [ $branch_type == 'hotfix' ]; then
label_name=$(echo "bug")
else
label_name=""
fi
echo "::set-output name=label_name::$label_name"
# PRにラベルを付与する
- name: Auto labeling
if: ${{ steps.label_name.outputs.label_name }}
run: |
number=$(echo $GITHUB_REF | sed -e 's/[^0-9]//g')
gh pr edit $number --add-label ${{ steps.label_name.outputs.label_name }}
49 changes: 49 additions & 0 deletions .github/workflows/auto-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Create release tag and release note.

on:
push:
branches: [ main ]

jobs:
create-release-tag:
runs-on: ubuntu-latest

env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TZ: 'Asia/Tokyo'

steps:
- uses: actions/checkout@v2

# 前回のりリースタグを取得する
- name: Get previous tag
id: pre_tag
run: |
echo "::set-output name=pre_tag::$(curl -H 'Accept: application/vnd.github.v3+json' -H 'Authorization: token ${{ secrets.GITHUB_TOKEN }}' https://api.github.com/repos/${{ github.repository }}/releases/latest | jq -r .tag_name)"
# タグを生成する 「{YYYY.MM.DD}-{当日リリース回数}」
- name: Generate release tag
id: release_tag
run: |
today=$(date +'%Y.%m.%d')
pre_release_date=$(echo ${{ steps.pre_tag.outputs.pre_tag }} | awk -F'-' '{print $1}')
pre_release_count=$(echo ${{ steps.pre_tag.outputs.pre_tag }} | awk -F'-' '{print $2}')
if [[ ! $pre_release_date = $today ]]; then
echo "init count"
pre_release_count=0
fi
echo "::set-output name=release_tag::$today-$(($pre_release_count + 1))"
# 前回リリースからの差分をもとに、リリースノートの本文を生成する
- name: Generate release note
id: release_note
run: |
echo "::set-output name=release_note::$(curl -X POST -H 'Accept: application/vnd.github.v3+json' -H 'Authorization: token ${{ secrets.GITHUB_TOKEN }}' https://api.github.com/repos/${{ github.repository }}/releases/generate-notes -d '{"tag_name":"${{ steps.release_tag.outputs.release_tag }}", "previous_tag_name":"${{ steps.pre_tag.outputs.pre_tag }}"}' | jq .body | sed 's/"//g')"
# タグを切り、リリースノートを作成する
- name: Create Release
run: |
curl -X POST \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-d "{ \"tag_name\": \"${{ steps.release_tag.outputs.release_tag }}\", \"name\": \"${{ steps.release_tag.outputs.release_tag }}\", \"body\": \"${{ steps.release_note.outputs.release_note }}\"}" \
https://api.github.com/repos/${{ github.repository }}/releases
15 changes: 15 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
changelog:
exclude:
# リリースノートから除外したいユーザー
authors:
- github-actions
categories:
- title: New Features 🎉
labels:
- "enhancement"
- title: Bug Fix 💊
labels:
- "bug"
- title: Other Changes 🛠
labels:
- "*"
1 change: 1 addition & 0 deletions test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test dayo

0 comments on commit 7e52796

Please sign in to comment.