Skip to content

Commit 25e319e

Browse files
committed
Add a build and release Github Action
1 parent 5cc6c85 commit 25e319e

1 file changed

Lines changed: 60 additions & 0 deletions

File tree

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Build and Release
2+
3+
env:
4+
DOTNET_VERSION: '8.x'
5+
NUGET_SOURCE_URL: 'https://api.nuget.org/v3/index.json'
6+
BUILD_DIRECTORY: '${{ github.workspace }}/build'
7+
8+
on:
9+
push:
10+
tags:
11+
- 'v*.*.*'
12+
13+
jobs:
14+
build-and-release:
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- name: Checkout Repository
19+
uses: actions/checkout@v2
20+
21+
- name: Get Version
22+
id: get_version
23+
run: |
24+
echo "tag=${GITHUB_REF_NAME}" >> $GITHUB_OUTPUT
25+
echo "version=${GITHUB_REF_NAME#v}" >> $GITHUB_OUTPUT
26+
27+
- name: Get Project Metadata
28+
id: get_project_meta
29+
run: |
30+
name=$(echo '${{ github.repository }}' | cut -d '/' -f 2)
31+
32+
echo "name=${name}" >> $GITHUB_OUTPUT
33+
echo "path=${name}/${name}.csproj" >> $GITHUB_OUTPUT
34+
35+
- name: Setup .NET
36+
uses: actions/setup-dotnet@v3.2.0
37+
with:
38+
dotnet-version: ${{ env.DOTNET_VERSION }}
39+
40+
- name: Restore Packages
41+
run: dotnet restore ${{ steps.get_project_meta.outputs.path }}
42+
43+
- name: Build Project
44+
run: dotnet build ${{ steps.get_project_meta.outputs.path }} /p:ContinuousIntegrationBuild=true --no-restore --configuration Release
45+
46+
- name: Pack Project
47+
run: dotnet pack ${{ steps.get_project_meta.outputs.path }} --no-restore --no-build --configuration Release --include-symbols -p:PackageVersion=${{ steps.get_version.outputs.version }} --output ${{ env.BUILD_DIRECTORY }}
48+
49+
- name: Push Package
50+
env:
51+
NUGET_AUTH_TOKEN: ${{ secrets.NUGET_AUTH_TOKEN }}
52+
run: dotnet nuget push ${{ env.BUILD_DIRECTORY }}/*.nupkg -k $NUGET_AUTH_TOKEN -s ${{ env.NUGET_SOURCE_URL }}
53+
54+
- name: Create Release
55+
uses: softprops/action-gh-release@v1
56+
with:
57+
token: ${{ secrets.GITHUB_TOKEN }}
58+
name: ${{ steps.get_version.outputs.tag }}
59+
body: ${{ github.event.head_commit.message }}
60+
files: '${{ env.BUILD_DIRECTORY }}/*'

0 commit comments

Comments
 (0)