chore: add create release pr workflow and shell script

This commit is contained in:
Tim Man
2023-11-24 14:36:29 +08:00
parent d39b9be21d
commit 0d5162c6d5
3 changed files with 100 additions and 0 deletions

32
.github/workflows/create-release-pr.yml vendored Normal file
View File

@@ -0,0 +1,32 @@
name: Create release PR
on:
workflow_dispatch:
inputs:
bump:
description: 'Version bump level'
required: true
default: patch
type: choice
options:
- patch
- minor
- major
jobs:
create-release-pr:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
cache: npm
- id: run-create-release-pr-sh
env:
BUMP: ${{ inputs.bump }}
run: |
# git config
git config user.name "GitHub Actions Bot"
git config user.email "<>"
./scripts/create-release-pr.sh

3
scripts/.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
response.json
pr-*.json
body.md

65
scripts/create-release-pr.sh Executable file
View File

@@ -0,0 +1,65 @@
#! /bin/bash
if [[ -z "$BUMP" ]]; then
echo "BUMP is required. major|minor|patch"
exit 1
fi
git fetch --all
git checkout develop
git pull
npm version $BUMP --git-tag-version=false
VERSION=$(npm pkg get version | sed 's/"//g')
TAG="v$VERSION"
BRANCH=release/$TAG
TITLE=release: $TAG
git checkout -b $BRANCH
git commit -am "$TITLE"
git merge origin/main -s ours
git push --set-upstream origin $BRANCH
gh api \ ─╯
--method POST \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/repos/{owner}/{repo}/releases \
-f tag_name=$TAG \
-f target_commitish="$BRANCH" \
-f name=$TAG \
-F draft=true \
-F prerelease=true \
-F generate_release_notes=true > release.json
cat release.json | jq -r .body > body.md
echo -e "\n\nDraft release: $(cat release.json | jq -r .html_url)" >> body.md
for b in main develop; do
gh api \
--method POST \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/repos/{owner}/{repo}/pulls \
-f title="$TITLE" \
-f body="Created by GitHub Actions Bot" \
-f head="$BRANCH to $b" \
-f base="$b" > pr-$b.json
$PR_ID=$(cat pr-$b.json | jq -r .id)
gh api \
--method PATCH \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/repos/{owner}/{repo}/pulls/$PR_ID \
-F 'body=@body.md'
# clean up temp files
# rm pr-$b.json
done
# clean up temp files
# rm release.json
# rm body.md