-
Notifications
You must be signed in to change notification settings - Fork 1
167 lines (158 loc) · 5.4 KB
/
csharp.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
name: csharp
on:
push:
branches: main
paths:
- 'csharp/**'
- '.github/workflows/csharp.yml'
env:
NUGETTOKEN: ${{ secrets.NUGET_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SCRIPTS_BASE_URL: https://raw.githubusercontent.com/linksplatform/Scripts/main/MultiProjectRepository
defaults:
run:
working-directory: csharp
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
with:
submodules: true
- name: Test
run: |
dotnet test -c Release -f net8
pushNuGetPackageToGitHubPackageRegistry:
needs: test
runs-on: ubuntu-latest
steps:
# 1. Checkout the repository
- uses: actions/checkout@v3
with:
submodules: true
# 2. Setup .NET SDK
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: '8.0.x' # Specify your required .NET version
# 3. Restore dependencies
- name: Restore dependencies
run: dotnet restore
# 4. Build the project
- name: Build
run: dotnet build --configuration Release --no-restore
# 5. Pack the project into a NuGet package
- name: Pack
run: dotnet pack --configuration Release --no-restore --output ./nupkgs
# 6. Add GitHub Package Registry as a NuGet source
- name: Add GitHub Package Registry as NuGet Source
run: |
dotnet nuget add source "https://nuget.pkg.github.com/linksplatform/index.json" \
--name "GitHub" \
--username "linksplatform" \
--password "${{ secrets.GITHUB_TOKEN }}" \
--store-password-in-clear-text
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# 7. Push the NuGet package to GitHub Package Registry
- name: Push NuGet Package to GitHub Package Registry
run: |
dotnet nuget push ./nupkgs/*.nupkg \
--source "GitHub" \
--api-key "${{ secrets.GITHUB_TOKEN }}"
env:
NUGET_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
pusnToNuget:
runs-on: ubuntu-latest
needs: test
steps:
- uses: actions/checkout@v1
with:
submodules: true
- name: Read project information
run: |
export REPOSITORY_NAME=$(basename ${{ github.repository }})
wget "$SCRIPTS_BASE_URL/read_csharp_package_info.sh"
bash ./read_csharp_package_info.sh
- name: Publish NuGet package
run: |
export REPOSITORY_NAME=$(basename ${{ github.repository }})
wget "$SCRIPTS_BASE_URL/push-csharp-nuget.sh"
bash ./push-csharp-nuget.sh
publiseRelease:
runs-on: ubuntu-latest
needs: test
steps:
- uses: actions/checkout@v1
with:
submodules: true
- name: Read project information
if: ${{ github.event_name == 'push' }}
run: |
export REPOSITORY_NAME=$(basename ${{ github.repository }})
wget "$SCRIPTS_BASE_URL/read_csharp_package_info.sh"
bash ./read_csharp_package_info.sh
- name: Publish release
run: |
export REPOSITORY_NAME=$(basename ${{ github.repository }})
wget "$SCRIPTS_BASE_URL/publish-release.sh"
chmod +x ./publish-release.sh
wget "$SCRIPTS_BASE_URL/publish-csharp-release.sh"
bash ./publish-csharp-release.sh
findChangedCsFiles:
runs-on: ubuntu-latest
needs: test
outputs:
isCsFilesChanged: ${{ steps.setIsCsFilesChangedOutput.outputs.isCsFilesChanged }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Get changed files using defaults
id: changed-files
uses: tj-actions/changed-files@v21
- name: Set output isCsFilesChanged
id: setIsCsFilesChangedOutput
run: |
isCsFilesChanged='false'
echo "Changed files: ${{ steps.changed-files.outputs.all_changed_files }}"
for changedFile in ${{ steps.changed-files.outputs.all_changed_files }}; do
if [[ $changedFile == *.cs ]]
then
echo "isCsFilesChanged='true'"
isCsFilesChanged='true'
fi
done
echo "::set-output name=isCsFilesChanged::${isCsFilesChanged}"
echo "isCsFilesChanged: ${isCsFilesChanged}"
generatePdfWithCode:
runs-on: ubuntu-latest
needs: [findChangedCsFiles]
if: ${{ needs.findChangedCsFiles.outputs.isCsFilesChanged == 'true' }}
steps:
- uses: actions/checkout@v1
with:
submodules: true
- name: Generate PDF with code
run: |
export REPOSITORY_NAME=$(basename ${{ github.repository }})
wget "$SCRIPTS_BASE_URL/format-csharp-files.py"
wget "$SCRIPTS_BASE_URL/format-csharp-document.sh"
wget "$SCRIPTS_BASE_URL/generate-csharp-pdf.sh"
bash ./generate-csharp-pdf.sh
publishDocumentation:
runs-on: ubuntu-latest
needs: [findChangedCsFiles]
if: ${{ needs.findChangedCsFiles.outputs.isCsFilesChanged == 'true' }}
steps:
- uses: actions/checkout@v1
with:
submodules: true
- name: Publish documentation to gh-pages branch
run: |
export REPOSITORY_NAME=$(basename ${{ github.repository }})
wget "$SCRIPTS_BASE_URL/docfx.json"
wget "$SCRIPTS_BASE_URL/filter.yml"
wget "$SCRIPTS_BASE_URL/toc.yml"
wget "$SCRIPTS_BASE_URL/publish-csharp-docs.sh"
bash ./publish-csharp-docs.sh