-
Notifications
You must be signed in to change notification settings - Fork 1
89 lines (72 loc) · 2.55 KB
/
Copy pathcicd.yml
File metadata and controls
89 lines (72 loc) · 2.55 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
name: Build, Test, and Deploy NuGet Package
on:
push:
branches:
- master
pull_request:
branches:
- master
workflow_dispatch:
jobs:
build:
name: Build and Test
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 9.0.x
- name: Install dependencies
run: dotnet restore
- name: Build solution
run: dotnet build --configuration Release --no-restore
- name: Run tests
run: dotnet test --configuration Release --no-build --verbosity normal --collect:"XPlat Code Coverage"
env:
DOTNET_CLI_TELEMETRY_OPTOUT: true
deploy:
name: Publish to NuGet
needs: build
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master'
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0 # Fetch full history to access tags
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 9.0.x
- name: Install dependencies
run: dotnet restore
- name: Generate version
id: version
run: |
VERSION=$(git describe --tags --abbrev=0 || echo "1.0.0")
PATCH=$(echo "$VERSION" | awk -F. '{print $3}')
NEW_PATCH=$((PATCH+1))
NEW_VERSION=$(echo "$VERSION" | awk -F. '{print $1"."$2}')".$NEW_PATCH"
echo "version=$NEW_VERSION" >> $GITHUB_ENV
echo "Generated version: $NEW_VERSION"
- name: Update NuGet version
run: |
sed -i "s/<PackageVersion>.*<\/PackageVersion>/<PackageVersion>${{ env.version }}<\/PackageVersion>/g" src/DateTimeRange/DateTimeRange.csproj
- name: Build solution
run: dotnet build --configuration Release --no-restore
- name: Pack NuGet package
run: dotnet pack src/DateTimeRange/DateTimeRange.csproj --configuration Release --output ./nupkg
- name: Create and push new Git tag
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag ${{ env.version }}
git push origin ${{ env.version }}
- name: Push NuGet package
env:
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
run: dotnet nuget push "./nupkg/*.nupkg" --api-key $NUGET_API_KEY --source https://api.nuget.org/v3/index.json