Skip to content

Generated CLI #4147 (#27) #23

Generated CLI #4147 (#27)

Generated CLI #4147 (#27) #23

name: Draft Release from PR
on:
push:
branches:
- main
permissions:
contents: write
pull-requests: read
jobs:
draft-release:
if: "!startsWith(github.event.head_commit.message, 'dump new version ')"
runs-on: ubuntu-latest
steps:
- name: Generate GitHub App token
id: generate-token
uses: actions/create-github-app-token@v2
with:
app-id: ${{ vars.CLI_GENERATION_APP_ID }}
private-key: ${{ secrets.CLI_GENERATION_APP_PRIVATE_KEY }}
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ steps.generate-token.outputs.token }}
- name: Get last merged PR
env:
GH_TOKEN: ${{ steps.generate-token.outputs.token }}
run: |
gh pr list \
--state merged \
--base main \
--limit 1 \
--json number,title,body,labels \
> pr.json
PR_NUM=$(jq -r '.[0].number // "none"' pr.json)
PR_TITLE=$(jq -r '.[0].title // "none"' pr.json)
echo "Found merged PR: #$PR_NUM - $PR_TITLE"
- name: Get latest release version
env:
GH_TOKEN: ${{ steps.generate-token.outputs.token }}
run: |
LAST_TAG=$(gh release list --limit 1 --json tagName -q '.[0].tagName')
if [[ -z "$LAST_TAG" || "$LAST_TAG" == "null" ]]; then
echo "No existing releases found. Defaulting to v1.0.0 as the base version."
LAST_TAG="v1.0.0"
fi
echo "Found latest release: $LAST_TAG"
echo "LAST_TAG=$LAST_TAG" >> $GITHUB_ENV
- name: Calculate next version from labels
run: |
V="${LAST_TAG#v}"
MAJOR=$(echo $V | cut -d. -f1)
MINOR=$(echo $V | cut -d. -f2)
PATCH=$(echo $V | cut -d. -f3)
LABELS=$(jq -r '.[0].labels[].name' pr.json)
echo "Found labels: $LABELS"
if echo "$LABELS" | grep -q "major"; then
echo "Bumping MAJOR version"
MAJOR=$((MAJOR+1))
MINOR=0
PATCH=0
elif echo "$LABELS" | grep -q "minor"; then
echo "Bumping MINOR version"
MINOR=$((MINOR+1))
PATCH=0
else
echo "Bumping PATCH version"
PATCH=$((PATCH+1))
fi
echo "Calculated next version: v$MAJOR.$MINOR.$PATCH"
echo "VERSION=v$MAJOR.$MINOR.$PATCH" >> $GITHUB_ENV
- name: Create DRAFT release using PR BODY
env:
GH_TOKEN: ${{ steps.generate-token.outputs.token }}
run: |
PR_BODY=$(jq -r '.[0].body // ""' pr.json)
echo "Creating draft release..."
echo "Version: $VERSION"
gh release create "$VERSION" \
--draft \
--title "$VERSION" \
--notes "$PR_BODY"
echo "Draft release created successfully!"