Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENG-3325] chore: add create release pr workflow and shell script #686

Merged
merged 7 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .github/workflows/create-release-pr.yml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions scripts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
release.json
pr-*.json
body.md
74 changes: 74 additions & 0 deletions scripts/create-release-pr.sh
Original file line number Diff line number Diff line change
@@ -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
Loading