This repository has been archived by the owner on Jan 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
235 additions
and
179 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
on: | ||
workflow_call: | ||
inputs: | ||
user: | ||
type: string | ||
description: 'User name' | ||
default: 'github-actions[bot]' | ||
secrets: | ||
GITHUB_TOKEN: | ||
description: 'GITHUB_TOKEN' | ||
required: true | ||
|
||
permissions: | ||
contents: write | ||
issues: write | ||
pull-requests: write | ||
|
||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
name: "Release Manager" | ||
|
||
jobs: | ||
create-target: | ||
runs-on: ubuntu-latest | ||
# 日付ベースでリリースを作成 | ||
name: "Create branch, tag, and PR" | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: git config | ||
run: | | ||
git config --local user.email "${{ inputs.user }}@users.noreply.github.com" | ||
git config --local user.name "${{ inputs.user }}" | ||
# 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: next_target_version | ||
- name: beta 0 | ||
run: echo "result=${{ steps.next_target_version.outputs.result }}-beta.0" >> $GITHUB_OUTPUT | ||
id: next_release_version | ||
# バージョンをpackage.jsonに書き込み | ||
- name: Write version | ||
run: | | ||
jq '.version = "${{ steps.next_release_version.outputs.result }}"' package.json > package.json.tmp && mv package.json.tmp package.json | ||
jq '.version = "${{ steps.next_release_version.outputs.result }}"' 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.next_target_version.outputs.result }}/' CHANGELOG.md | ||
# release/ブランチとタグを作成 | ||
- name: Commit version | ||
run: | | ||
git commit -am "Bump version to ${{ steps.next_release_version.outputs.result }}" | ||
git push origin HEAD:release/${{ steps.next_target_version.outputs.result }} | ||
git tag "${{ steps.next_release_version.outputs.result }}" | ||
git push origin "${{ steps.next_release_version.outputs.result }}" | ||
# リリースを作成 | ||
- name: Create release | ||
run: | | ||
gh release create "${{ steps.next_release_version.outputs.result }}" --prerelease --title "${{ steps.next_release_version.outputs.result }}" --notes "${{ steps.changelog.outputs.changelog }}" | ||
# PRを作成 | ||
- name: Create PR | ||
run: | | ||
gh pr create --draft --title "Release: ${{ steps.next_target_version.outputs.result }}" --body "${{ steps.changelog.outputs.changelog }}" --head release/${{ steps.next_target_version.outputs.result }} --base ${{ github.ref_name }} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
on: | ||
workflow_call: | ||
inputs: | ||
pr_number: | ||
type: string | ||
description: 'PR number' | ||
required: true | ||
user: | ||
type: string | ||
description: 'User name' | ||
default: 'github-actions[bot]' | ||
secrets: | ||
GITHUB_TOKEN: | ||
description: 'GITHUB_TOKEN' | ||
required: true | ||
|
||
permissions: | ||
contents: write | ||
issues: write | ||
pull-requests: write | ||
|
||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
name: "Release Manager" | ||
|
||
jobs: | ||
dispatch-prerelease: | ||
runs-on: ubuntu-latest | ||
if: ${{ inputs.pr_number != '' }} | ||
# 開いているリリースのパッチバージョンを上げる | ||
name: "Dispatch Pre-release" | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: git config | ||
run: | | ||
git config --local user.email "${{ inputs.user }}@users.noreply.github.com" | ||
git config --local user.name "${{ inputs.user }}" | ||
# pr_numberからPR情報を取得 | ||
- name: Get PR | ||
run: | | ||
PR_JSON=$(gh pr view ${{ inputs.pr_number }} --json isDraft,headRefName) | ||
echo "PR_IS_DRAFT=$(echo $PR_JSON | jq -r '.isDraft')" >> $GITHUB_OUTPUT | ||
echo "PR_HEAD_REF=$(echo $PR_JSON | jq -r '.headRefName')" >> $GITHUB_OUTPUT | ||
id: get_pr | ||
# checkout PR | ||
- uses: actions/checkout@v4 | ||
with: | ||
ref: ${{ steps.get_pr.outputs.PR_HEAD_REF }} | ||
# 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 | ||
# current_versionを加工してtarget_versionを取得 | ||
- name: Get target version | ||
uses: actions/script@v7 | ||
env: | ||
CURRENT_VERSION: ${{ steps.get_current_version.outputs.current_version }} | ||
with: | ||
script: | | ||
return process.env.CURRENT_VERSION.split('-')[0]; | ||
result-encoding: string | ||
id: next_target_version | ||
# バージョンをインクリメント | ||
- name: Increment version | ||
uses: actions/script@v7 | ||
env: | ||
CURRENT_VERSION: ${{ steps.get_current_version.outputs.current_version }} | ||
PR_IS_DRAFT: steps.get_pr.outputs.PR_IS_DRAFT | ||
with: | ||
script: | | ||
const [major, minor, _patch, _pre] = process.env.CURRENT_VERSION.split('.'); | ||
const pre = Number(_pre); | ||
if (Number.isNaN(pre)) { | ||
console.error('Invalid pre version', year, month, process.env.CURRENT_VERSION, major, minor, _patch); | ||
throw new Error('Invalid pre version'); | ||
} | ||
if (process.env.PR_IS_DRAFT == 'true') { | ||
if (_patch.endsWith('beta')) { | ||
return `${major}.${minor}.${_patch}.${pre + 1}`; | ||
} | ||
return `${major}.${minor}.${_patch.split('-')[0]}-beta.${pre + 1}`; | ||
} | ||
if (_patch.endsWith('rc')) { | ||
return `${major}.${minor}.${_patch}.${pre + 1}`; | ||
} | ||
return `${major}.${minor}.${_patch.split('-')[0]}-rc.${pre + 1}`; | ||
result-encoding: string | ||
id: next_release_version | ||
# バージョンをpackage.jsonに書き込み | ||
- name: Write version | ||
run: | | ||
jq '.version = "${{ steps.next_release_version.outputs.result }}"' package.json > package.json.tmp && mv package.json.tmp package.json | ||
jq '.version = "${{ steps.next_release_version.outputs.result }}"' packages/misskey-js/package.json > packages/misskey-js/package.json.tmp && mv packages/misskey-js/package.json.tmp packages/misskey-js/package.json | ||
# release/ブランチとタグを作成 | ||
- name: Commit version | ||
run: | | ||
git commit -am "Bump version to ${{ steps.next_release_version.outputs.result }}" | ||
git push origin HEAD:release/${{ steps.next_target_version.outputs.result }} | ||
git tag "${{ steps.next_release_version.outputs.result }}" | ||
git push origin "${{ steps.next_release_version.outputs.result }}" | ||
# CHANGELOG.mdのUnreleasedの内容を取得 | ||
- name: Get changelog | ||
run: | | ||
{ | ||
echo 'changelog<<EOF' | ||
sed -n '/## ${{ steps.next_target_version.outputs.result }}/,/^## /p' CHANGELOG.md | sed -e 1d -e '$d' | ||
echo EOF | ||
} >> $GITHUB_OUTPUT | ||
id: changelog | ||
# リリースを作成 | ||
- name: Create release | ||
run: | | ||
gh release create "${{ steps.next_release_version.outputs.result }}" --prerelease --title "${{ steps.next_release_version.outputs.result }}" --notes "${{ steps.changelog.outputs.changelog }}" | ||
# PRのnotesを更新 | ||
- name: Update PR | ||
run: | | ||
gh pr edit ${{ inputs.pr_number }} --body "${{ steps.changelog.outputs.changelog }}" |
Oops, something went wrong.