diff --git a/.github/workflows/create-release-pr.yml b/.github/workflows/create-release-pr.yml new file mode 100644 index 000000000..da7cbe181 --- /dev/null +++ b/.github/workflows/create-release-pr.yml @@ -0,0 +1,33 @@ +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 "<>" + cd scripts + ./create-release-pr.sh diff --git a/scripts/.gitignore b/scripts/.gitignore new file mode 100644 index 000000000..62c82f717 --- /dev/null +++ b/scripts/.gitignore @@ -0,0 +1,3 @@ +release.json +pr-*.json +body.md diff --git a/scripts/create-release-pr.sh b/scripts/create-release-pr.sh new file mode 100755 index 000000000..84e3721d7 --- /dev/null +++ b/scripts/create-release-pr.sh @@ -0,0 +1,74 @@ +#! /bin/bash + +if [[ -z "$BUMP" ]]; then + echo "BUMP is required. major|minor|patch" + exit 1 +fi + +echo -e "\n--- Prepare for $BUMP release branch ---" + +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 + +echo -e "\n--- Create draft release for $TAG ---" + +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 + echo -e "\n--- Create PR to $b ---" + + 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 to $b" \ + -f body="Created by GitHub Actions Bot" \ + -f head="$BRANCH" \ + -f base="$b" > pr-$b.json + + echo -e "\n--- Update PR to $b with description ---" + + PR_ID=$(cat pr-$b.json | jq -r .number) + + 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 + +echo -e "\n--- Done ---" +# clean up temp files +# rm release.json +# rm body.md