-
Notifications
You must be signed in to change notification settings - Fork 11
74 lines (64 loc) · 2.92 KB
/
Copy pathpr-version.yml
File metadata and controls
74 lines (64 loc) · 2.92 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
name: PR Version Preview
on:
pull_request:
# Re-run the version calculation when labels are added or when new commits are pushed
types: [opened, synchronize, labeled, reopened, edited]
branches: [main]
permissions:
pull-requests: write
contents: read
jobs:
preview-version:
# Only run for local PRs
if: github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-latest
steps:
# Checkout full history and all tags
- uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
# Get latest tag and calculate next version
- name: Get latest tag and bump type
id: version
run: |
# Be defensive and robust: use awk to split version numbers and always quote $GITHUB_OUTPUT
git fetch --tags || true
current=$(git describe --tags --abbrev=0 2>/dev/null || true)
if [ -z "$current" ]; then
echo "No tags found, defaulting to 0.0.0"
current="0.0.0"
fi
# Remove leading 'v' then extract parts using awk
ver=${current#v}
major=$(printf "%s" "$ver" | awk -F. '{print $1+0}')
minor=$(printf "%s" "$ver" | awk -F. '{print $2+0}')
patch=$(printf "%s" "$ver" | awk -F. '{print $3+0}')
# Determine bump type from PR labels (safe interpolation)
LABELS="${{ join(github.event.pull_request.labels.*.name, ' ') }}"
if printf "%s" "$LABELS" | grep -q "major"; then
major=$((major+1)); minor=0; patch=0; type="major"
elif printf "%s" "$LABELS" | grep -q "minor"; then
minor=$((minor+1)); patch=0; type="minor"
else
patch=$((patch+1)); type="patch"
fi
next="${major}.${minor}.${patch}"
# Safely write outputs
if [ -n "$GITHUB_OUTPUT" ]; then
# Write all outputs in one redirect to avoid multiple open/close
{
printf '%s\n' "current=$current" "next=$next" "type=$type"
} >> "$GITHUB_OUTPUT"
else
# Fallback to printing if GITHUB_OUTPUT not available (for local debugging)
echo "current=$current"
echo "next=$next"
echo "type=$type"
fi
- name: Comment version preview
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ github.event.pull_request.number }}
body: |
**Next version:** **${{ steps.version.outputs.next }}**