-
Notifications
You must be signed in to change notification settings - Fork 5
91 lines (73 loc) · 2.46 KB
/
draft-release-from-pr.yml
File metadata and controls
91 lines (73 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
name: Draft Release from PR
on:
push:
branches:
- master
permissions:
contents: write
pull-requests: read
jobs:
draft-release:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Get last merged PR
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh pr list \
--state merged \
--base master \
--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: ${{ secrets.GITHUB_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 release found. A release tag is required to calculate the next version."
exit 1
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: ${{ secrets.GITHUB_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!"