This repository has been archived by the owner on Jan 17, 2024. It is now read-only.
Release Manager #50
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
on: | |
workflow_dispatch: | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
CHANGES_TEMPLATE: | | |
## 202x.x.x (Unreleased) | |
### General | |
- | |
### Client | |
- | |
### Server | |
- | |
name: "Release Manager" | |
jobs: | |
get-prs: | |
runs-on: ubuntu-latest | |
outputs: | |
pr_number: ${{ steps.get_prs.outputs.value }} | |
steps: | |
- uses: actions/checkout@v4 | |
# headがrelease/かつopenのPRを1つ取得 | |
- name: Get PRs | |
run: "gh pr list --state open --head release/ --json number --jq '.[] | .number'" | |
id: get_prs | |
create-release: | |
permissions: | |
contents: write | |
pull-requests: write | |
needs: get-prs | |
runs-on: ubuntu-latest | |
if: ${{ needs.get-prs.outputs.pr_number == '' }} | |
# 日付ベースでリリースを作成 | |
name: "Create Release" | |
steps: | |
- uses: actions/checkout@v4 | |
# jqでpackage.jsonから現在のバージョンを取得 | |
- name: Get current version | |
run: | | |
jq -r '.version' package.json | |
echo "current_version=$(jq -r '.version' package.json)" >> $GITHUB_OUTPUT | |
id: get_current_version | |
# バージョンをインクリメント | |
- name: Increment version | |
uses: actions/script@v7 | |
env: | |
CURRENT_VERSION: ${{ steps.get_current_version.outputs.current_version }} | |
with: | |
script: | | |
const now = new Date(); | |
const year = now.toLocaleDateString('en-US', { year: 'numeric', timeZone: 'Asia/Tokyo' }); | |
const month = now.toLocaleDateString('en-US', { month: 'numeric', timeZone: 'Asia/Tokyo' }); | |
const [major, minor, _patch] = process.env.CURRENT_VERSION.split('.'); | |
const patch = Number(_patch.split('-')[0]); | |
if (Number.isNaN(patch)) { | |
console.error('Invalid patch version', year, month, process.env.CURRENT_VERSION, major, minor, _patch); | |
throw new Error('Invalid patch version'); | |
} | |
if (year !== major || month !== minor) { | |
return `${year}.${month}.0`; | |
} else { | |
return `${major}.${minor}.${patch + 1}`; | |
} | |
result-encoding: string | |
id: increment_version | |
- name: beta 0 | |
run: echo "next=${{ steps.increment_version.outputs.result }}-beta.0" >> $GITHUB_OUTPUT | |
id: next_version | |
# バージョンをpackage.jsonに書き込み | |
- name: Write version | |
run: | | |
jq '.version = "${{ steps.next_version.outputs.next }}"' package.json > package.json.tmp && mv package.json.tmp package.json | |
jq '.version = "${{ steps.next_version.outputs.next }}"' packages/misskey-js/package.json > packages/misskey-js/package.json.tmp && mv packages/misskey-js/package.json.tmp packages/misskey-js/package.json | |
# CHANGELOG.mdのUnreleasedの内容を後で使うために取得 | |
- name: Get changelog | |
run: | | |
{ | |
echo 'changelog<<EOF' | |
sed -n '/## 202x.x.x (Unreleased)/,/^## /p' CHANGELOG.md | sed -e 1d -e '$d' | |
echo EOF | |
} >> $GITHUB_OUTPUT | |
id: changelog | |
# CHANGELOG.mdのバージョンの書き換え | |
- name: Modify CHANGELOG.md | |
run: | | |
sed -i 's/## 202x.x.x (Unreleased)/## ${{ steps.increment_version.outputs.result }}/' CHANGELOG.md | |
# バージョンとタグをコミット・プッシュ | |
- name: Commit version | |
run: | | |
git config --local user.email "[email protected]" | |
git config --local user.name "LuckyBeast" | |
if (git diff --shortstat | grep '[0-9]'); then \ | |
git commit -am "Bump version to ${{ steps.next_version.outputs.next }}" | |
git tag "${{ steps.next_version.outputs.next }}" | |
git push origin HEAD:${{ github.ref_name }} | |
git push origin "${{ steps.next_version.outputs.next }}" | |
git push origin HEAD:release/${{ steps.next_version.outputs.next }} | |
fi | |
# リリースを作成 | |
- name: Create release | |
run: | | |
gh release create "${{ steps.next_version.outputs.next }}"" --prerelease --title "${{ steps.next_version.outputs.next }}" --notes "${{ steps.changelog.outputs.changelog }}" | |
# CHANGELOG.mdにUnreleasedを追加 | |
# 環境変数から挿入する部分: https://qiita.com/sahayan/items/8658992f0f48eb5d2bc4 | |
- name: Modify CHANGELOG.md | |
run: | | |
sed -i "1i $(echo "${CHANGES_TEMPLATE}" | sed -r 's/$/\\n/' | while IFS= read -r line; do echo -n "$line"; done)" CHANGELOG.md | |
- name: Commit CHANGELOG mofdification | |
run: | | |
if (git diff --shortstat | grep '[0-9]'); then \ | |
git commit -am "Update CHANGELOG.md (prepend Unreleased)" | |
git push origin HEAD:${{ github.ref_name }} | |
fi |