1+ name : Draft Release from PR
2+
3+ on :
4+ push :
5+ branches :
6+ - master
7+
8+ permissions :
9+ contents : write
10+ pull-requests : read
11+
12+ jobs :
13+ draft-release :
14+ runs-on : ubuntu-latest
15+
16+ steps :
17+ - name : Checkout repository
18+ uses : actions/checkout@v4
19+
20+ - name : Get last merged PR
21+ env :
22+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
23+ run : |
24+ gh pr list \
25+ --state merged \
26+ --base master \
27+ --limit 1 \
28+ --json number,title,body,labels \
29+ > pr.json
30+
31+ PR_NUM=$(jq -r '.[0].number // "none"' pr.json)
32+ PR_TITLE=$(jq -r '.[0].title // "none"' pr.json)
33+ echo "Found merged PR: #$PR_NUM - $PR_TITLE"
34+
35+ - name : Get latest release version
36+ env :
37+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
38+ run : |
39+ LAST_TAG=$(gh release list --limit 1 --json tagName -q '.[0].tagName')
40+
41+ if [[ -z "$LAST_TAG" || "$LAST_TAG" == "null" ]]; then
42+ echo "No existing release found. A release tag is required to calculate the next version."
43+ exit 1
44+ fi
45+
46+ echo "Found latest release: $LAST_TAG"
47+ echo "LAST_TAG=$LAST_TAG" >> $GITHUB_ENV
48+
49+ - name : Calculate next version from labels
50+ run : |
51+ V="${LAST_TAG#v}"
52+
53+ MAJOR=$(echo $V | cut -d. -f1)
54+ MINOR=$(echo $V | cut -d. -f2)
55+ PATCH=$(echo $V | cut -d. -f3)
56+
57+ LABELS=$(jq -r '.[0].labels[].name' pr.json)
58+ echo "Found labels: $LABELS"
59+
60+ if echo "$LABELS" | grep -q "major"; then
61+ echo "Bumping MAJOR version"
62+ MAJOR=$((MAJOR+1))
63+ MINOR=0
64+ PATCH=0
65+ elif echo "$LABELS" | grep -q "minor"; then
66+ echo "Bumping MINOR version"
67+ MINOR=$((MINOR+1))
68+ PATCH=0
69+ else
70+ echo "Bumping PATCH version"
71+ PATCH=$((PATCH+1))
72+ fi
73+
74+ echo "Calculated next version: v$MAJOR.$MINOR.$PATCH"
75+ echo "VERSION=v$MAJOR.$MINOR.$PATCH" >> $GITHUB_ENV
76+
77+ - name : Create DRAFT release using PR BODY
78+ env :
79+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
80+ run : |
81+ PR_BODY=$(jq -r '.[0].body // ""' pr.json)
82+
83+ echo "Creating draft release..."
84+ echo "Version: $VERSION"
85+
86+ gh release create "$VERSION" \
87+ --draft \
88+ --title "$VERSION" \
89+ --notes "$PR_BODY"
90+
91+ echo "Draft release created successfully!"
0 commit comments