Repository navigation
145 lines (129 loc) · 5.1 KB
/
Copy pathsdk-release.yml
File metadata and controls
145 lines (129 loc) · 5.1 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
name: Cortex Package Release Pipeline
on:
pull_request:
types: [closed]
branches:
- 'v*/main'
jobs:
build-and-publish:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: '9.0.x'
- name: Check if PR was merged
id: check_merge
run: |
if [ "${{ github.event.pull_request.merged }}" = "true" ]; then
echo "merged=true" >> $GITHUB_OUTPUT
else
echo "merged=false" >> $GITHUB_OUTPUT
fi
- name: Determine version increment
id: versioning
if: ${{ steps.check_merge.outputs.merged == 'true' }}
run: |
labels=$(echo '${{ toJSON(github.event.pull_request.labels) }}' | jq -r '.[].name')
echo "PR labels: $labels"
increment="patch"
if echo "$labels" | grep -q "feature"; then
increment="minor"
fi
echo "increment=$increment" >> $GITHUB_OUTPUT
- name: Get current version
id: get_version
if: ${{ steps.check_merge.outputs.merged == 'true' }}
run: |
branchName='${{ github.ref_name }}' # e.g., v1/main
echo "Branch name: $branchName"
if [[ $branchName =~ ^v([0-9]+)/main$ ]]; then
majorVersion="${BASH_REMATCH[1]}"
echo "Major version: $majorVersion"
git fetch --tags
latestTag=$(git tag --list "v$majorVersion.*.*" | sort -V | tail -n1)
if [ -n "$latestTag" ]; then
currentVersion="${latestTag#v}"
else
currentVersion="$majorVersion.0.0"
fi
else
echo "Branch name does not match expected pattern"
exit 1
fi
echo "Current version: $currentVersion"
echo "major=$majorVersion" >> $GITHUB_OUTPUT
echo "currentVersion=$currentVersion" >> $GITHUB_OUTPUT
- name: Bump version
id: bump_version
if: ${{ steps.check_merge.outputs.merged == 'true' }}
run: |
increment='${{ steps.versioning.outputs.increment }}'
currentVersion='${{ steps.get_version.outputs.currentVersion }}'
IFS='.' read -ra versionParts <<< "$currentVersion"
major=${versionParts[0]}
minor=${versionParts[1]}
patch=${versionParts[2]}
if [ "$increment" == 'minor' ]; then
minor=$((minor + 1))
patch=0
elif [ "$increment" == 'patch' ]; then
patch=$((patch + 1))
else
echo "Unknown increment type: $increment"
exit 1
fi
newVersion="$major.$minor.$patch"
echo "New version: $newVersion"
echo "newVersion=$newVersion" >> $GITHUB_OUTPUT
- name: Install xmlstarlet
if: ${{ steps.check_merge.outputs.merged == 'true' }}
run: sudo apt-get install -y xmlstarlet
- name: Update project versions
if: ${{ steps.check_merge.outputs.merged == 'true' }}
run: |
newVersion='${{ steps.bump_version.outputs.newVersion }}'
find . -name '*.csproj' -not -path '*/Cortex.Tests/*' | while read csproj; do
echo "Updating version in $csproj"
xmlstarlet ed -P -L -u "//Project/PropertyGroup/Version" -v "$newVersion" "$csproj" || \
xmlstarlet ed -P -L -s "//Project/PropertyGroup" -t elem -n "Version" -v "$newVersion" "$csproj"
done
- name: Build solution
if: ${{ steps.check_merge.outputs.merged == 'true' }}
run: dotnet build --configuration Release
- name: Pack projects
if: ${{ steps.check_merge.outputs.merged == 'true' }}
run: |
dotnet pack --configuration Release --no-build --output ./artifacts
- name: Publish to NuGet
if: ${{ steps.check_merge.outputs.merged == 'true' }}
env:
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
run: |
dotnet nuget push ./artifacts/*.nupkg --api-key $NUGET_API_KEY --source https://api.nuget.org/v3/index.json
- name: Configure Git
if: ${{ steps.check_merge.outputs.merged == 'true' }}
run: |
git config user.name "GitHub Actions"
git config user.email "actions@github.com"
- name: Create Git tag
if: ${{ steps.check_merge.outputs.merged == 'true' }}
run: |
newVersion='${{ steps.bump_version.outputs.newVersion }}'
git tag -a "v$newVersion" -m "Release v$newVersion"
git push origin "v$newVersion"
- name: Create GitHub Release
if: ${{ steps.check_merge.outputs.merged == 'true' }}
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: "v${{ steps.bump_version.outputs.newVersion }}"
release_name: "v${{ steps.bump_version.outputs.newVersion }}"
draft: false
prerelease: false
body: "Release of version v${{ steps.bump_version.outputs.newVersion }}"