Create a release pull request #1
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
name: Create a release pull request | |
on: | |
workflow_dispatch: | |
inputs: | |
versionMajor: | |
description: "バージョン情報: major" | |
required: true | |
type: string | |
versionMinor: | |
description: "バージョン情報: minor" | |
required: true | |
type: string | |
versionPatch: | |
description: "バージョン情報: patch" | |
required: true | |
type: string | |
concurrency: | |
group: ${{ github.workflow }} | |
cancel-in-progress: true | |
jobs: | |
build: | |
if: ${{ github.ref_type == 'branch' && github.ref_name == 'develop' }} | |
runs-on: ubuntu-24.04 | |
outputs: | |
branch: ${{ steps.meta.outputs.branch }} | |
version: ${{ steps.meta.outputs.version }} | |
permissions: | |
contents: write | |
timeout-minutes: 5 | |
steps: | |
# https://github.com/actions/checkout | |
- uses: actions/checkout@v4 | |
# https://github.com/actions/setup-node | |
- uses: actions/setup-node@v4 | |
with: | |
node-version-file: .node-version | |
cache: npm | |
cache-dependency-path: ./package-lock.json | |
- name: Set version & format branch name | |
id: meta | |
env: | |
VERSION: "${{ inputs.versionMajor }}.${{ inputs.versionMinor }}.${{ inputs.versionPatch }}" | |
run: | | |
npm version "$VERSION" --no-git-tag-version | |
version=$(node -p "require('./package.json').version") | |
echo "version=$version" >> "$GITHUB_OUTPUT" | |
echo "branch=feature/$version" >> "$GITHUB_OUTPUT" | |
- name: Can release | |
env: | |
GH_TOKEN: ${{ github.token }} | |
TAG: ${{ steps.meta.outputs.version }} | |
run: bash .github/scripts/can-release.bash "$TAG" | |
- run: npm ci | |
- run: npm test | |
- run: npm run build | |
# https://github.com/actions/checkout/issues/13#issuecomment-724415212 | |
- name: Set up git user | |
run: | | |
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
git config --local user.name "github-actions[bot]" | |
- name: git add & push | |
env: | |
BRANCH: ${{ steps.meta.outputs.branch }} | |
VERSION: ${{ steps.meta.outputs.version }} | |
run: | | |
git switch --create "$BRANCH" | |
git add compiled | |
git add package.json | |
git add package-lock.json | |
git commit --message "Update $VERSION" | |
git push --set-upstream origin "$BRANCH" | |
test-action: | |
needs: build | |
uses: ./.github/workflows/test-action.yml | |
with: | |
git_ref: ${{ needs.build.outputs.branch }} | |
create-pr: | |
needs: | |
- build | |
- test-action | |
runs-on: ubuntu-24.04 | |
permissions: | |
contents: read | |
pull-requests: write | |
timeout-minutes: 5 | |
steps: | |
# https://github.com/actions/checkout | |
- uses: actions/checkout@v4 | |
with: | |
ref: ${{ needs.build.outputs.branch }} | |
- name: Generate diff notes | |
id: notes | |
env: | |
GH_TOKEN: ${{ github.token }} | |
REF_NAME: ${{ needs.build.outputs.branch }} | |
TAG: ${{ needs.build.outputs.version }} | |
run: | | |
response=$(bash .github/scripts/presume-release-notes.bash "$TAG" "$REF_NAME") | |
echo "response=$response" >> "$GITHUB_OUTPUT" | |
echo "$response" | |
- name: Create a file for pull request body | |
shell: ruby {0} | |
env: | |
NOTE: ${{ fromJson(steps.notes.outputs.response).body }} | |
URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} | |
run: | | |
text = <<"BODY" | |
Test result: "#{ENV['URL']}" | |
"#{ENV['NOTE']}" | |
BODY | |
File.open("PR_BODY", "w") { |file| | |
file.write(text) | |
} | |
- name: Create a pull request | |
env: | |
ASSIGNEE: tshion | |
BASE: released | |
GH_TOKEN: ${{ github.token }} | |
TITLE: "Update ${{ needs.build.outputs.version }}" | |
run: gh pr create --assignee "$ASSIGNEE" --base "$BASE" --title "$TITLE" --body-file PR_BODY |