-
Notifications
You must be signed in to change notification settings - Fork 0
132 lines (112 loc) · 4.03 KB
/
Copy pathrelease.yml
File metadata and controls
132 lines (112 loc) · 4.03 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
name: Release
on:
workflow_dispatch:
inputs:
version:
description: 'Version to release (e.g., 2.0.1)'
required: true
type: string
branch:
description: 'Branch to release from'
required: true
default: 'main'
type: choice
options:
- main
- legacy-1.0
- experimental
release_type:
description: 'Type of release'
required: true
default: 'minor'
type: choice
options:
- major
- minor
- patch
- hotfix
jobs:
validate:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.validate.outputs.version }}
steps:
- name: Validate inputs
id: validate
run: |
VERSION="${{ github.event.inputs.version }}"
BRANCH="${{ github.event.inputs.branch }}"
# Validate version format
if [[ ! $VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+)?$ ]]; then
echo "Invalid version format: $VERSION"
exit 1
fi
# Validate branch compatibility
if [[ $BRANCH == "legacy-1.0" && ! $VERSION =~ ^1\. ]]; then
echo "Legacy branch must use 1.x.x versions"
exit 1
elif [[ $BRANCH == "main" && ! $VERSION =~ ^2\. ]]; then
echo "Main branch must use 2.x.x versions"
exit 1
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT
release:
needs: validate
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.branch }}
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup .NET
uses: actions/setup-dotnet@v4
# SDK version read from global.json
- name: Update version files
run: |
VERSION="${{ needs.validate.outputs.version }}"
BRANCH="${{ github.event.inputs.branch }}"
# Update Directory.Build.props
sed -i "s/<VersionPrefix>.*<\/VersionPrefix>/<VersionPrefix>$VERSION<\/VersionPrefix>/" Directory.Build.props
# Update LibEmiddle.csproj
sed -i "s/<Version>.*<\/Version>/<Version>$VERSION<\/Version>/" LibEmiddle/LibEmiddle.csproj
# Update protocol version if major version change
if [[ "${{ github.event.inputs.release_type }}" == "major" ]]; then
MAJOR_VERSION=$(echo $VERSION | cut -d. -f1)
sed -i "s/public const int MAJOR_VERSION = .*/public const int MAJOR_VERSION = $MAJOR_VERSION;/" LibEmiddle.Domain/Constants/ProtocolVersion.cs
fi
- name: Build and test
run: |
dotnet restore
dotnet build --configuration Release
dotnet test --configuration Release --verbosity normal
- name: Create NuGet packages
run: |
dotnet pack --configuration Release --output ./packages
- name: Commit version changes
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add .
git commit -m "Release version ${{ needs.validate.outputs.version }}" || exit 0
git push
- name: Create and push tag
run: |
git tag -a "v${{ needs.validate.outputs.version }}" -m "Release version ${{ needs.validate.outputs.version }}"
git push origin "v${{ needs.validate.outputs.version }}"
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ needs.validate.outputs.version }}
name: v${{ needs.validate.outputs.version }}
body: |
## Release v${{ needs.validate.outputs.version }}
### Installation
```
dotnet add package LibEmiddle --version ${{ needs.validate.outputs.version }}
```
### Branch: ${{ github.event.inputs.branch }}
### Type: ${{ github.event.inputs.release_type }}
draft: false
prerelease: ${{ contains(needs.validate.outputs.version, '-') }}
files: ./packages/*.nupkg