Create Draft Release #6
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 Draft Release | |
on: | |
workflow_dispatch: | |
inputs: | |
bump: | |
description: "Use PATCH for fixes, use MINOR for new features and use MAJOR for breaking changes" | |
type: choice | |
options: | |
- patch | |
- minor | |
- major | |
required: true | |
jobs: | |
build: | |
if: ${{ github.actor != 'dependabot'}} | |
runs-on: ubuntu-latest | |
outputs: | |
release: ${{ steps.prerelease.outputs.release }} | |
steps: | |
# Checkout the repository | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Read Node.js version from .nvmrc | |
id: node_version | |
run: echo "NODE_VERSION=$(cat .nvmrc)" >> $GITHUB_ENV | |
- name: Set up Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: ${{ env.NODE_VERSION }} | |
# Fetch tags to determine the latest version | |
- name: Fetch all tags | |
run: git fetch --tags | |
- name: Calculate next version | |
id: next_version | |
run: | | |
# Get the latest tag, default to v0.0.0 if no tags exist | |
LATEST_TAG=$(git describe --tags $(git rev-list --tags --max-count=1) 2>/dev/null || echo "v0.0.0") | |
# Extract major, minor, and patch from the tag | |
VERSION=${LATEST_TAG#v} | |
IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION" | |
# Determine which part to bump based on the input variable | |
if [ "${{ inputs.bump }}" = "major" ]; then | |
MAJOR=$((MAJOR + 1)) | |
MINOR=0 | |
PATCH=0 | |
elif [ "${{ inputs.bump }}" = "minor" ]; then | |
MINOR=$((MINOR + 1)) | |
PATCH=0 | |
elif [ "${{ inputs.bump }}" = "patch" ]; then | |
PATCH=$((PATCH + 1)) | |
else | |
echo "Invalid bump input: ${{ inputs.bump }}" | |
exit 1 | |
fi | |
# Create the new version string | |
NEW_TAG="v${MAJOR}.${MINOR}.${PATCH}" | |
NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}" | |
# Set the new version in the GitHub environment | |
echo "NEW_TAG=$NEW_TAG" >> $GITHUB_ENV | |
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV | |
echo "New version: $NEW_VERSION" | |
- name: Update package.json version | |
id: update_package_version | |
run: | | |
# Update the version in the root package.json | |
jq ".version = \"${NEW_VERSION}\"" package.json > package.json.tmp && mv package.json.tmp package.json | |
# Update the version in all packages inside the packages folder | |
for package_json in packages/*/package.json; do | |
if [ -f "$package_json" ]; then | |
echo "Updating version in $package_json to ${NEW_VERSION}" | |
jq ".version = \"${NEW_VERSION}\"" "$package_json" > "${package_json}.tmp" && mv "${package_json}.tmp" "$package_json" | |
else | |
echo "No package.json found in $package_json" | |
fi | |
done | |
- uses: pnpm/action-setup@v4 | |
- name: Install dependencies | |
run: pnpm install | |
- name: Build And Test | |
id: build-and-test | |
run: | | |
pnpm build | |
- name: Commit changes | |
run: | | |
# Configure Git | |
git config user.name "github-actions[bot]" | |
git config user.email "github-actions[bot]@users.noreply.github.com" | |
# Commit and push the changes | |
git add . | |
git commit -m "Bump version to ${NEW_TAG}" | |
git push origin HEAD:main | |
git tag $NEW_TAG | |
git push origin $NEW_TAG | |
# Create a draft release | |
- name: Create GitHub draft release | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
gh release create "$NEW_VERSION" \ | |
--draft \ | |
--generate-notes |