-
Notifications
You must be signed in to change notification settings - Fork 0
137 lines (115 loc) · 4.05 KB
/
update-version.yml
File metadata and controls
137 lines (115 loc) · 4.05 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
name: Update Version and Changelog
on:
workflow_dispatch:
inputs:
version_type:
description: 'Version bump type'
required: true
default: 'patch'
type: choice
options:
- patch
- minor
- major
prerelease:
description: 'Is this a prerelease?'
required: false
default: false
type: boolean
jobs:
update-version:
name: Update Project Version
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
- name: Install GitVersion
uses: gittools/actions/gitversion/setup@v0.10.2
with:
versionSpec: '5.x'
- name: Determine version
id: gitversion
uses: gittools/actions/gitversion/execute@v0.10.2
with:
useConfigFile: true
- name: Create new version
id: version
run: |
CURRENT_VERSION="${{ steps.gitversion.outputs.majorMinorPatch }}"
IFS='.' read -ra VERSION_PARTS <<< "$CURRENT_VERSION"
MAJOR=${VERSION_PARTS[0]}
MINOR=${VERSION_PARTS[1]}
PATCH=${VERSION_PARTS[2]}
case "${{ github.event.inputs.version_type }}" in
"major")
MAJOR=$((MAJOR + 1))
MINOR=0
PATCH=0
;;
"minor")
MINOR=$((MINOR + 1))
PATCH=0
;;
"patch")
PATCH=$((PATCH + 1))
;;
esac
NEW_VERSION="$MAJOR.$MINOR.$PATCH"
if [ "${{ github.event.inputs.prerelease }}" == "true" ]; then
NEW_VERSION="$NEW_VERSION-alpha.$(date +%Y%m%d%H%M%S)"
fi
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "New version will be: $NEW_VERSION"
- name: Update project files
run: |
# Update all .csproj files with new version
find . -name "*.csproj" -not -path "./packages/*" | xargs sed -i "s/<Version>.*<\/Version>/<Version>${{ steps.version.outputs.NEW_VERSION }}<\/Version>/g"
# Add version to project files if not exists
for file in $(find . -name "*.csproj" -not -path "./packages/*"); do
if ! grep -q "<Version>" "$file"; then
sed -i '/<PropertyGroup>/a\ <Version>${{ steps.version.outputs.NEW_VERSION }}</Version>' "$file"
fi
done
- name: Update changelog
run: |
# Create backup of changelog
cp changelog.md changelog.md.bak
# Get current date
CURRENT_DATE=$(date +"%Y-%m-%d")
# Create new changelog entry
cat > changelog_temp.md << EOF
# Changelog
## [${{ steps.version.outputs.NEW_VERSION }}] - $CURRENT_DATE
### Added
- Version bump to ${{ steps.version.outputs.NEW_VERSION }}
EOF
# Append rest of changelog (skip first line)
tail -n +2 changelog.md >> changelog_temp.md
# Replace original
mv changelog_temp.md changelog.md
- name: Commit changes
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add .
git commit -m "chore: bump version to ${{ steps.version.outputs.NEW_VERSION }}"
git tag -a "v${{ steps.version.outputs.NEW_VERSION }}" -m "Release version ${{ steps.version.outputs.NEW_VERSION }}"
git push origin HEAD
git push origin --tags
- name: Create release
if: github.event.inputs.prerelease != 'true'
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ steps.version.outputs.NEW_VERSION }}
name: Release ${{ steps.version.outputs.NEW_VERSION }}
draft: false
prerelease: ${{ github.event.inputs.prerelease == 'true' }}
generate_release_notes: true
token: ${{ secrets.GITHUB_TOKEN }}