-
Notifications
You must be signed in to change notification settings - Fork 6
146 lines (123 loc) · 4.34 KB
/
Copy pathversion.yml
File metadata and controls
146 lines (123 loc) · 4.34 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
name: Version Bump
on:
push:
branches:
- main
paths:
- ".changeset/**"
- '!.changeset/README.md'
jobs:
bump-version:
runs-on: ubuntu-latest
permissions:
contents: write # needed to commit the version bump and push the branch
pull-requests: write # needed to open the release PR
steps:
- name: Checkout repository
uses: actions/checkout@v7
- name: Set up Java
uses: actions/setup-java@v5
with:
distribution: temurin
java-version: 17
- name: Detect change types and build PR body
id: detect
run: |
FILES=$(find .changeset -maxdepth 1 -type f ! -name README.md)
if [ -z "$FILES" ]; then
echo "No changeset files found"
echo "found=false" >> "$GITHUB_OUTPUT"
exit 0
fi
echo "found=true" >> "$GITHUB_OUTPUT"
# Initialize variables
TYPE_PRIORITY=0
BODY=""
for FILE in $FILES; do
echo "Processing $FILE"
FILE_TYPE=$(grep '^type:' "$FILE" | awk '{print $2}')
case "$FILE_TYPE" in
patch) PRIORITY=1 ;;
minor) PRIORITY=2 ;;
major) PRIORITY=3 ;;
*) echo "Unknown type: $FILE_TYPE"; exit 1 ;;
esac
if [ $PRIORITY -gt $TYPE_PRIORITY ]; then
TYPE_PRIORITY=$PRIORITY
TYPE=$FILE_TYPE
fi
CONTENT=$(sed '/^type:/d' "$FILE" | sed '/^---$/d')
BODY="$BODY\n\n$CONTENT"
done
echo "TYPE=$TYPE" >> $GITHUB_ENV
echo "BODY<<EOF" >> $GITHUB_ENV
echo -e "$BODY" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
echo "Final detected type: $TYPE"
echo "PR body:"
echo -e "$BODY"
VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
# Split the version by dots
IFS='.' read -r major minor patch <<< "$VERSION"
case "$TYPE" in
patch)
new_version="$major.$minor.$((patch+1))"
mvn versions:set -DnewVersion="$new_version" -DgenerateBackupPoms=false
;;
minor)
new_version="$major.$((minor+1)).0"
mvn versions:set -DnewVersion="$new_version" -DgenerateBackupPoms=false
;;
major)
new_version="$((major+1)).0.0"
mvn versions:set -DnewVersion="$new_version" -DgenerateBackupPoms=false
;;
*)
echo "Unknown type: $TYPE"; exit 1
;;
esac
mvn versions:commit
- name: Get new project version
id: get-version
if: steps.detect.outputs.found == 'true'
run: |
VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "New version: $VERSION"
- name: Update CHANGELOG.md
if: steps.detect.outputs.found == 'true'
run: |
ENTRY_FILE=$(mktemp)
printf "## %s\n%s\n\n" "$VERSION" "$BODY" > "$ENTRY_FILE"
awk -v newfile="$ENTRY_FILE" '
BEGIN { fm=0; done=0 }
{
print
if ($0 == "---") {
fm++
if (fm == 2 && !done) {
print ""
while ((getline line < newfile) > 0) print line
done=1
}
}
}
' CHANGELOG.md > /tmp/CHANGELOG.new
mv /tmp/CHANGELOG.new CHANGELOG.md
# bump the index in the frontmatter to match the new entry count
sed -i "0,/^index: [0-9]*/s//index: $(( $(grep -c '^## ' CHANGELOG.md) ))/" CHANGELOG.md
- name: Delete changeset files
if: steps.detect.outputs.found == 'true'
run: |
find .changeset -type f ! -name 'README.md' -delete
echo "Removed processed changeset files."
- name: Create Pull Request
if: steps.detect.outputs.found == 'true'
uses: peter-evans/create-pull-request@v8
with:
base: main
commit-message: "chore: release v${{ env.VERSION }}"
branch: changeset
title: "Release v${{ env.VERSION }}"
body: ${{ env.BODY }}
labels: version