Skip to content

create_release_pr

create_release_pr #6

name: create_release_pr
on:
workflow_dispatch:
inputs:
release-version:
description: 'select release semantic version'
required: true
type: choice
options:
- 'patch'
- 'minor'
- 'major'
jobs:
create-release-pr:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 16
# GitHub Actionsとしてgitアカウントを設定
- name: Git configuration
run: |
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --global user.name "GitHub Actions"
# アップデート後のバージョンを環境変数にセット
- name: Get new version
id: new-version
run: |
echo "NEW_VERSION=$(npm --no-git-tag-version version ${{ env.RELEASE_VERSION }})" >> $GITHUB_ENV
env:
RELEASE_VERSION: ${{ github.event.inputs.release-version }}
# package.jsonのバージョンをアップデートしてコミット
- name: Update package.json version
run: |
git add package.json
git commit -m "chore: release ${{ env.NEW_VERSION }}"
- name: Generate GitHub App Token
uses: tibdex/github-app-token@v1
id: generate-token
with:
app_id: ${{ secrets.RELEASE_APP_ID }}
private_key: ${{ secrets.RELEASE_APP_PRIVATE_KEY }}
- name: Create Pull Request
id: cpr
uses: peter-evans/create-pull-request@v5
with:
branch: release/${{ env.NEW_VERSION }}
title: release ${{ env.NEW_VERSION }}
labels: release
# GITHUB_TOKENでは権限が足りなくPR生成後に他のワークフローがトリガーされないため、GitHub App Tokenを使用
# @see: https://github.com/peter-evans/create-pull-request/issues/48#issuecomment-536184102
token: ${{ steps.generate-token.outputs.token }}
- name: Enable Pull Request Automerge
run: gh pr merge --merge --auto "${{ steps.cpr.outputs.pull-request-number }}"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}