-
-
Notifications
You must be signed in to change notification settings - Fork 44
150 lines (119 loc) · 4.29 KB
/
shared_library_nuget.yml
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
146
147
148
149
150
name: SharedLibraryCore NuGet
on:
push:
branches: [ develop, release/pre, master ]
paths:
- SharedLibraryCore/**
- Data/**
- .github/workflows/shared_library_nuget.yml
pull_request:
branches: [ develop ]
paths:
- SharedLibraryCore/**
- Data/**
env:
outputDirectory: ${{ github.workspace}}/nuget
jobs:
update_revision_number:
runs-on: ubuntu-latest
outputs:
revision_number: ${{ steps.revision.outputs.revision_number }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Restore cache
id: cache
uses: actions/cache@v4
with:
path: cache_dir
key: revision-number-nuget
- name: Get current date
id: date
run: echo "current_date=$(date +'%Y-%m-%d')" >> $GITHUB_ENV
- name: Check and update revision number
id: revision
run: |
FILENAME=cache_dir/revision_number.txt
DATEFILE=cache_dir/previous_date.txt
mkdir -p cache_dir
if [ -f "$DATEFILE" ]; then
prev_date=$(cat "$DATEFILE")
rev_number=$(cat "$FILENAME")
else
prev_date=""
rev_number=0
fi
if [ "$current_date" = "$prev_date" ]; then
rev_number=$((rev_number + 1))
else
rev_number=1
fi
echo "New revision number: $rev_number"
echo $rev_number > "$FILENAME"
echo $current_date > "$DATEFILE"
echo "revision_number=$rev_number" >> $GITHUB_OUTPUT
- name: Save cache
uses: actions/cache@v4
with:
path: cache_dir
key: revision-number-nuget
make_version:
runs-on: ubuntu-latest
needs: [ update_revision_number ]
outputs:
build_num: ${{ steps.generate_build_number.outputs.build_num }}
env:
revisionNumber: ${{ needs.update_revision_number.outputs.revision_number }}
steps:
- name: Make build number
id: generate_build_number
run: |
build_num=$(date +'%Y.%-m.%-d').${{ env.revisionNumber }}
echo "build_num=$build_num" >> $GITHUB_OUTPUT
echo "Build number is $build_num"
build_pack:
runs-on: ubuntu-latest
needs: [ make_version ]
env:
buildNumber: ${{ needs.make_version.outputs.build_num }}
packageTag: ${{ github.event_name == 'pull_request' && '-beta' || '-preview' }}
buildConfiguration: Prerelease
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build data
run: dotnet build **/Data.csproj -c ${{env.buildConfiguration}} /p:Version=${{ env.buildNumber }} --no-restore
- name: Build SLC
run: dotnet build **/SharedLibraryCore.csproj -c ${{env.buildConfiguration}} /p:Version=${{ env.buildNumber }} --no-restore
- name: Pack SLC
run: dotnet pack **/SharedLibraryCore.csproj -c ${{env.buildConfiguration}} -p:PackageVersion=${{ env.buildNumber }}${{ env.packageTag }} -o ${{ env.outputDirectory }} --no-restore
- name: Publish nuget package artifact
uses: actions/upload-artifact@v4
with:
name: SharedLibraryCore-${{ env.buildNumber }}
path: ${{ env.outputDirectory }}/*.nupkg
publish:
runs-on: ubuntu-latest
needs: [ make_version, build_pack ]
environment: prerelease
if: ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/release/pre' || github.ref == 'refs/heads/develop' }}
steps:
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: SharedLibraryCore-${{ needs.make_version.outputs.build_num }}
path: ${{ env.outputDirectory }}
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Publish NuGet package
run: |
for file in ${{ env.outputDirectory }}/*.nupkg; do
dotnet nuget push "$file" --api-key "${{ secrets.NUGET_APIKEY }}" --source https://api.nuget.org/v3/index.json --skip-duplicate
done