1+ name : build
2+
3+ on :
4+ push :
5+ branches :
6+ - master
7+ pull_request :
8+ branches :
9+ - master
10+
11+ env :
12+ VERSION_MAJOR : 0
13+ VERSION_MINOR : 1
14+
15+ jobs :
16+ version :
17+ runs-on : ubuntu-latest
18+ outputs :
19+ version : ${{ steps.version.outputs.version }}
20+ build : ${{ steps.version.outputs.build }}
21+ revision : ${{ steps.version.outputs.revision }}
22+ steps :
23+ - name : checkout
24+ uses : actions/checkout@v3
25+ with :
26+ fetch-depth : 0
27+
28+ - name : generate version
29+ id : version
30+ shell : bash
31+ run : |
32+ BUILD_NUMBER=0
33+ REVISION=${{ github.run_number }}
34+ VERSION="${{ env.VERSION_MAJOR }}.${{ env.VERSION_MINOR }}.${BUILD_NUMBER}.${REVISION}"
35+
36+ echo "version=${VERSION}" >> $GITHUB_OUTPUT
37+ echo "build=${BUILD_NUMBER}" >> $GITHUB_OUTPUT
38+ echo "revision=${REVISION}" >> $GITHUB_OUTPUT
39+
40+ echo "Generated version: ${VERSION}"
41+ echo " - Build: ${BUILD_NUMBER}"
42+ echo " - Revision (Run Number): ${REVISION}"
43+
44+ build :
45+ needs : version
46+ strategy :
47+ matrix :
48+ include :
49+ - os : windows-latest
50+ platform : windows
51+ - os : ubuntu-latest
52+ platform : linux
53+
54+ runs-on : ${{ matrix.os }}
55+
56+ steps :
57+ - name : checkout
58+ uses : actions/checkout@v5
59+ with :
60+ fetch-depth : 0
61+
62+ - name : setup .NET
63+ uses : actions/setup-dotnet@v5
64+ with :
65+ dotnet-version : 8.0.x
66+
67+ - name : build (Linux)
68+ if : runner.os == 'Linux'
69+ run : |
70+ echo "[+] build linux"
71+ dotnet publish -r linux-x64 --self-contained=true -c Release -p:PublishDir=build /p:Version=${{ needs.version.outputs.version }} /p:FileVersion=${{ needs.version.outputs.version }} /p:AssemblyVersion=${{ needs.version.outputs.version }} /p:ProductVersion=${{ needs.version.outputs.version }}
72+
73+ - name : build (Windows)
74+ if : runner.os == 'Windows'
75+ run : |
76+ echo "[+] build windows"
77+ dotnet publish -r win-x64 --self-contained=true -c Release -p:PublishDir=build /p:Version=${{ needs.version.outputs.version }} /p:FileVersion=${{ needs.version.outputs.version }} /p:AssemblyVersion=${{ needs.version.outputs.version }} /p:ProductVersion=${{ needs.version.outputs.version }}
78+
79+ - name : collect artifacts
80+ shell : bash
81+ run : |
82+ mkdir -p artifacts
83+ cp build/* artifacts/
84+ ls -lh artifacts
85+
86+ - name : upload artifacts
87+ uses : actions/upload-artifact@v3
88+ if : github.event_name == 'push' && github.ref == 'refs/heads/master'
89+ with :
90+ name : ${{ matrix.platform }}-v${{ needs.version.outputs.version }}
91+ path : artifacts/*.*
92+
93+ release :
94+ needs : [ version , build ]
95+ runs-on : ubuntu-latest
96+ if : github.ref == 'refs/heads/master' && github.ref == 'refs/heads/master' && github.event_name == 'push'
97+ steps :
98+ - name : checkout
99+ uses : actions/checkout@v3
100+ with :
101+ fetch-depth : 0
102+
103+ - name : download artifacts
104+ uses : actions/download-artifact@v3
105+ with :
106+ path : artifacts
107+
108+ - name : create release
109+ uses : softprops/action-gh-release@v1
110+ with :
111+ tag_name : v${{ needs.version.outputs.version }}
112+ name : release v${{ needs.version.outputs.version }}
113+ generate_releases : true
114+ draft : false
115+ prerelease : true
116+ files : artifacts/*.*
117+
118+ - name : publish to NuGet
119+ if : secrets.NUGET_TOKEN != ''
120+ env :
121+ NUGET_AUTH_TOKEN : ${{ secrets.NUGET_TOKEN }}
122+ run : |
123+ echo "[+] Publishing NuGet packages with version ${{ needs.version.outputs.version }}"
124+ shopt -s globstar nullglob
125+
126+ for pkg in artifacts/**/*.nupkg; do
127+ if [[ "$pkg" == *.snupkg ]]; then
128+ continue
129+ fi
130+ echo "-> dotnet nuget push $pkg"
131+ dotnet nuget push "$pkg" \
132+ --api-key "$NUGET_AUTH_TOKEN" \
133+ --source "https://api.nuget.org/v3/index.json" \
134+ --skip-duplicate
135+ done
0 commit comments