-
Notifications
You must be signed in to change notification settings - Fork 2
149 lines (125 loc) · 5.5 KB
/
bump.yml
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
147
148
149
name: Increment Version
on:
workflow_dispatch:
inputs:
next-version:
description: 'override with custom version number'
required: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
jobs:
bump:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Run bash script
shell: bash
run: |
# Gather new git history from after the last release
git log --format="%s" > log.txt
touch subjects.txt
touch types.txt
while IFS= read -r LINE; do
# Read line until colon symbol ( : )
SUBJECT_TYPE=$(echo $LINE | awk -F: '{print $1}')
# Stop iterating git log when reaching latest release
if [[ $SUBJECT_TYPE == 'release' ]]; then
break
fi
# Else continue saving subjects and commit types
echo "- $LINE" >> subjects.txt
echo $SUBJECT_TYPE >> types.txt
done < log.txt
# Save current release's version
VERSION=$(cat pyproject.toml | grep -m 1 "version" | grep -o '[0-9]\+\.[0-9]\+\.[0-9]\+')
IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION"
# Decide if programmatically finding next version or if manually provided one by user
METHOD="manual"
NEXT="${{ github.event.inputs.next-version }}"
if [[ -z "$NEXT" ]]; then
METHOD="programmatic"
# Determine which version number to bump
BUMP_TYPE="nv" # Meaning non-versioning commit, or affecting something outside the API. Basically ignore the types: build, chore, ci, docs, perf, refactor, revert, style, test.
while IFS= read -r TYPE; do
if [[ "$TYPE" == "BREAK" ]]; then
BUMP_TYPE="major"
break
elif [[ "$BUMP_TYPE" != "minor" ]]; then
if [[ "$TYPE" == "feat" ]]; then
BUMP_TYPE="minor"
elif [[ "$TYPE" == "fix" ]]; then
BUMP_TYPE="patch"
fi
fi
done < types.txt
# Get version number for next release
if [ "$BUMP_TYPE" == "major" ]; then
# Backwards incompatible API changes
NEXT="$((MAJOR+1)).0.0"
elif [ "$BUMP_TYPE" == "minor" ]; then
# Backwards compatible API additions/changes
NEXT="$MAJOR.$((MINOR+1)).0"
elif [ "$BUMP_TYPE" == "patch" ]; then
echo "No patch versioning allowed in Sant Lipi. See CONTRIBUTING.md to learn more. Exiting workflow action."
exit 1
else
NEXT=$VERSION
fi
fi
if [[ "$VERSION" != "$NEXT" ]]; then
# Create body of Pull Request
cp subjects.txt body.txt
echo "### History" >> body.txt
echo "" >> body.txt
echo "Next: $NEXT ($METHOD)" >> body.txt
echo "Latest: $VERSION" >> body.txt
echo "### Release" >> body.txt
# tac reverses lines
tac subjects.txt > changelog.txt
BODY=$(tac body.txt)
# Clean up files
rm log.txt
rm subjects.txt
rm types.txt
rm body.txt
# Bump version in pyproject.toml, glyphs file, packages, and changelog.
sed -i "s/version = \"$VERSION\"/version = \"$NEXT\"/" pyproject.toml
sed -i "s/\"version\": \"$VERSION\"/\"version\": \"$NEXT\"/" packages/npm/sant-lipi/package.json
sed -i "s/version: $VERSION/version: $NEXT/" packages/pubdev/sant_lipi/pubspec.yaml
#
IFS='.' read -r NEXT_MAJOR NEXT_MINOR NEXT_PATCH <<< "$NEXT"
#
GLYPHS_MINOR_VERSION=$(printf "%03d" $MINOR)
GLYPHS_VERSION_STRING="$MAJOR.$GLYPHS_MINOR_VERSION"
#
GLYPHS_MINOR_NEXT=$(printf "%03d" $NEXT_MINOR)
GLYPHS_NEXT_STRING="$NEXT_MAJOR.$GLYPHS_MINOR_NEXT"
#
sed -i "s/value = \"Version $GLYPHS_VERSION_STRING/value = \"Version $GLYPHS_NEXT_STRING/" sources/SantLipi.glyphs
sed -i "s/versionMajor = $MAJOR/versionMajor = $NEXT_MAJOR/" sources/SantLipi.glyphs
sed -i "s/versionMinor = $MINOR/versionMinor = $NEXT_MINOR/" sources/SantLipi.glyphs
#
sed -i "1s/^/## $NEXT\n\n\n/" CHANGELOG.md
sed -i '2r changelog.txt' CHANGELOG.md
rm changelog.txt
# Set up git config for github-actions bot
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
# Set author to the user running workflow
AUTHOR="${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>"
# Checkout new branch
git checkout -B "release-$NEXT"
# Commit files
git add pyproject.toml
git add packages/npm/sant-lipi/package.json
git add packages/pubdev/sant_lipi/pubspec.yaml
git add sources/SantLipi.glyphs
git add CHANGELOG.md
git commit -m "release: increment version from $VERSION to $NEXT" --author="$AUTHOR"
# Push branch
git push --set-upstream origin "release-$NEXT" --atomic
# Open Pull Request
gh pr create --base "main" --title "release: increment version from $VERSION to $NEXT" --body "$BODY"
fi