diff --git a/.github/workflows/create-target.yml b/.github/workflows/create-target.yml index ec14b24..6bbe03a 100644 --- a/.github/workflows/create-target.yml +++ b/.github/workflows/create-target.yml @@ -1,3 +1,5 @@ +name: "Create release branch, tag, and PR" + on: workflow_call: inputs: @@ -14,13 +16,11 @@ permissions: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} -name: "Release Manager" - jobs: create-target: + name: "Create release branch, tag, and PR" runs-on: ubuntu-latest # 日付ベースでリリースを作成 - name: "Create branch, tag, and PR" steps: - uses: actions/checkout@v4 - name: git config diff --git a/.github/workflows/dispatch-prerelease.yml b/.github/workflows/dispatch-prerelease.yml index cca2466..a3fb66a 100644 --- a/.github/workflows/dispatch-prerelease.yml +++ b/.github/workflows/dispatch-prerelease.yml @@ -1,3 +1,5 @@ +name: "Dispatch Pre-release" + on: workflow_call: inputs: @@ -18,31 +20,13 @@ permissions: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} -name: "Release Manager" - jobs: dispatch-prerelease: + name: "Dispatch Pre-release" 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: | diff --git a/.github/workflows/merge.yml b/.github/workflows/merge.yml new file mode 100644 index 0000000..75d80fd --- /dev/null +++ b/.github/workflows/merge.yml @@ -0,0 +1,124 @@ +on: + workflow_call: + inputs: + pr_number: + type: string + description: PR number + required: true + main: + type: string + description: Main branch name + default: main + user: + type: string + description: User name + default: github-actions[bot] + +permissions: + contents: write + issues: write + pull-requests: write + +env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + +name: "Release Manager" + +jobs: + merge: + name: "Go Merge" + runs-on: ubuntu-latest + if: ${{ inputs.pr_number != '' }} + 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 + + # バージョンをpackage.jsonに書き込み + - name: Write version + run: | + jq '.version = "${{ steps.next_target_version.outputs.result }}"' package.json > package.json.tmp && mv package.json.tmp package.json + jq '.version = "${{ steps.next_target_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 "[skip ci] Release: ${{ steps.next_target_version.outputs.result }}" + git push origin HEAD:release/${{ steps.next_target_version.outputs.result }} + + - name: Try Merge + run: | + gh pr merge ${{ inputs.pr_number }} --auto + + # CHANGELOG.mdの内容を取得 + - name: Get changelog + run: | + { + echo 'changelog<> $GITHUB_OUTPUT + id: changelog + + - name: Create tag + run: | + git tag "${{ steps.next_target_version.outputs.result }}" + git push origin "${{ steps.next_target_version.outputs.result }}" + + # リリースを作成 + - name: Create release + run: | + gh release create "${{ steps.next_target_version.outputs.result }}" --title "${{ steps.next_target_version.outputs.result }}" --notes "${{ steps.changelog.outputs.changelog }}" + + # CHANGELOG.mdにUnreleasedのテンプレートを追加 + - uses: actions/checkout@v4 + with: + ref: ${{ inputs.main }} + - name: Prepend CHANGELOG template + env: + CHANGES_TEMPLATE: | + ## 202x.x.x (Unreleased) + + ### General + - + + ### Client + - + + ### Server + - + + 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 version + run: | + git commit -am "[skip ci] Update CHANGELOG.md (prepend template)" + git push origin HEAD:${{ inputs.main }} diff --git a/.github/workflows/release-with-dispatch.yml b/.github/workflows/release-with-dispatch.yml index 47bca4a..424cd73 100644 --- a/.github/workflows/release-with-dispatch.yml +++ b/.github/workflows/release-with-dispatch.yml @@ -2,6 +2,11 @@ name: "Release Manager" on: workflow_dispatch: + inputs: + merge: + type: boolean + description: 'Merge release branch' + default: false env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -24,17 +29,26 @@ jobs: echo "pr_number=$(gh pr list --limit 1 --search "head:release/ is:open" --json number --jq '.[] | .number')" >> $GITHUB_OUTPUT id: get_pr + merge: + uses: ./.github/workflows/merge.yml + needs: get-prs + if: ${{ needs.get-prs.outputs.pr_number != '' && inputs.merge == true }} + with: + pr_number: ${{ needs.get-prs.outputs.pr_number }} + main: ${{ github.ref_name }} + user: LuckyBeast + dispatch-prerelease: uses: ./.github/workflows/dispatch-prerelease.yml needs: get-prs if: ${{ needs.get-prs.outputs.pr_number != '' }} with: pr_number: ${{ needs.get-prs.outputs.pr_number }} - user: 'LuckyBeast' + user: LuckyBeast create-target: uses: ./.github/workflows/create-target.yml needs: get-prs if: ${{ needs.get-prs.outputs.pr_number == '' }} with: - user: 'LuckyBeast' + user: LuckyBeast