1+ name : Release
2+
3+ on :
4+ push :
5+ branches : [ main ]
6+ workflow_dispatch :
7+
8+ permissions :
9+ contents : write
10+ packages : write
11+ pull-requests : write
12+
13+ jobs :
14+ release :
15+ runs-on : ubuntu-latest
16+ if : github.event_name == 'push' && github.ref == 'refs/heads/main'
17+
18+ steps :
19+ - name : Checkout
20+ uses : actions/checkout@v4
21+ with :
22+ fetch-depth : 0
23+ token : ${{ secrets.GITHUB_TOKEN }}
24+
25+ - name : Check for existing tags
26+ id : check_tags
27+ run : |
28+ if git describe --tags --abbrev=0 2>/dev/null; then
29+ echo "has_tags=true" >> $GITHUB_OUTPUT
30+ echo "Found existing tags"
31+ else
32+ echo "has_tags=false" >> $GITHUB_OUTPUT
33+ echo "No tags found - will create initial release"
34+ fi
35+
36+ - name : Get next version
37+ id : get_version
38+ uses : mathieudutour/github-tag-action@v6.2
39+ with :
40+ github_token : ${{ secrets.GITHUB_TOKEN }}
41+ release_branches : main
42+ pre_release_branches : develop
43+ dry_run : true
44+ default_bump : ${{ steps.check_tags.outputs.has_tags == 'false' && 'major' || 'false' }}
45+ custom_release_rules : |
46+ breaking:major,
47+ feat:minor,
48+ fix:patch,
49+ perf:patch,
50+ revert:patch,
51+ docs:patch:README,
52+ refactor:patch,
53+ test:false,
54+ style:false,
55+ chore:false,
56+ ci:false
57+
58+ - name : Check if should release
59+ id : should_release
60+ run : |
61+ if [[ "${{ steps.get_version.outputs.new_version }}" != "" ]]; then
62+ echo "new_release=true" >> $GITHUB_OUTPUT
63+ echo "New version will be: ${{ steps.get_version.outputs.new_version }}"
64+ else
65+ echo "new_release=false" >> $GITHUB_OUTPUT
66+ echo "No new version to release"
67+ fi
68+
69+ - name : Setup .NET
70+ if : steps.should_release.outputs.new_release == 'true'
71+ uses : actions/setup-dotnet@v4
72+ with :
73+ dotnet-version : ' 9.0.x'
74+
75+ - name : Update version in csproj files
76+ if : steps.should_release.outputs.new_release == 'true'
77+ run : |
78+ VERSION=${{ steps.get_version.outputs.new_version }}
79+ find . -name "*.csproj" -type f | while read -r file; do
80+ if grep -q "<Version>" "$file"; then
81+ sed -i "s|<Version>.*</Version>|<Version>${VERSION}</Version>|g" "$file"
82+ fi
83+ done
84+
85+ - name : Restore dependencies
86+ if : steps.should_release.outputs.new_release == 'true'
87+ run : dotnet restore
88+
89+ - name : Build
90+ if : steps.should_release.outputs.new_release == 'true'
91+ run : dotnet build --configuration Release --no-restore
92+
93+ - name : Test
94+ if : steps.should_release.outputs.new_release == 'true'
95+ run : dotnet test --configuration Release --no-build --verbosity normal
96+
97+ - name : Pack
98+ if : steps.should_release.outputs.new_release == 'true'
99+ run : |
100+ dotnet pack src/TechnicalAnalysis.Common/TechnicalAnalysis.Common.csproj --configuration Release --no-build --output ./artifacts
101+ dotnet pack src/TechnicalAnalysis.Functions/TechnicalAnalysis.Functions.csproj --configuration Release --no-build --output ./artifacts
102+ dotnet pack src/TechnicalAnalysis.Candles/TechnicalAnalysis.Candles.csproj --configuration Release --no-build --output ./artifacts
103+
104+ - name : Install NuGet validator
105+ if : steps.should_release.outputs.new_release == 'true'
106+ run : dotnet tool update Meziantou.Framework.NuGetPackageValidation.Tool --global
107+
108+ - name : Validate NuGet packages
109+ if : steps.should_release.outputs.new_release == 'true'
110+ run : |
111+ for file in ./artifacts/*.nupkg; do
112+ echo "Validating $file"
113+ meziantou.validate-nuget-package "$file"
114+ done
115+
116+ - name : Generate changelog
117+ if : steps.should_release.outputs.new_release == 'true'
118+ id : changelog
119+ uses : TriPSs/conventional-changelog-action@v6
120+ with :
121+ github-token : ${{ secrets.GITHUB_TOKEN }}
122+ skip-commit : true
123+ output-file : false
124+
125+ - name : Create tag
126+ if : steps.should_release.outputs.new_release == 'true'
127+ uses : mathieudutour/github-tag-action@v6.2
128+ with :
129+ github_token : ${{ secrets.GITHUB_TOKEN }}
130+ custom_tag : ${{ steps.get_version.outputs.new_version }}
131+
132+ - name : Push to NuGet
133+ if : steps.should_release.outputs.new_release == 'true'
134+ run : |
135+ dotnet nuget push ./artifacts/*.nupkg \
136+ --api-key ${{ secrets.NUGET_API_KEY }} \
137+ --source https://api.nuget.org/v3/index.json \
138+ --skip-duplicate
139+
140+ - name : Create GitHub Release
141+ if : steps.should_release.outputs.new_release == 'true'
142+ uses : softprops/action-gh-release@v2
143+ with :
144+ tag_name : v${{ steps.get_version.outputs.new_version }}
145+ name : Release v${{ steps.get_version.outputs.new_version }}
146+ body : ${{ steps.changelog.outputs.clean_changelog }}
147+ files : |
148+ ./artifacts/*.nupkg
149+ ./artifacts/*.snupkg
150+ draft : false
151+ prerelease : false
152+ env :
153+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
0 commit comments