-
-
Notifications
You must be signed in to change notification settings - Fork 2
365 lines (325 loc) · 15.8 KB
/
csharp.yml
File metadata and controls
365 lines (325 loc) · 15.8 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
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
name: csharp
on:
push:
branches: main
paths:
- 'csharp/**'
- '.github/workflows/csharp.yml'
pull_request:
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:
findChangedCsFiles:
runs-on: ubuntu-latest
timeout-minutes: 10
outputs:
isCsFilesChanged: ${{ steps.setIsCsFilesChangedOutput.outputs.isCsFilesChanged }}
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Get changed files using defaults
id: changed-files
uses: tj-actions/changed-files@v47
- 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 == csharp/*.cs ]] || [[ $changedFile == csharp/*.csproj ]] || [[ $changedFile == csharp/*.sln ]] || [[ $changedFile == csharp/* ]] || [[ $changedFile == .github/workflows/csharp.yml ]]; then
echo "isCsFilesChanged='true'"
isCsFilesChanged='true'
break
fi
done
echo "isCsFilesChanged=${isCsFilesChanged}" >> $GITHUB_OUTPUT
echo "isCsFilesChanged: ${isCsFilesChanged}"
lint:
needs: [findChangedCsFiles]
if: ${{ needs.findChangedCsFiles.outputs.isCsFilesChanged == 'true' }}
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v6
with:
submodules: true
- name: Setup .NET SDK
uses: actions/setup-dotnet@v5
with:
dotnet-version: '8.0.x'
- name: Restore Dependencies
run: dotnet restore
- name: Check formatting
run: dotnet format --verify-no-changes --verbosity diagnostic
test:
needs: [findChangedCsFiles, lint]
if: ${{ needs.findChangedCsFiles.outputs.isCsFilesChanged == 'true' }}
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v6
with:
submodules: true
- name: Setup .NET SDK
uses: actions/setup-dotnet@v5
with:
dotnet-version: '8.0.x' # Specify your desired .NET version
- name: Restore Dependencies
run: dotnet restore
- name: Build
run: dotnet build --configuration Release --no-restore
- name: Test
run: dotnet test --configuration Release --no-build -f net8
pushToNuget:
runs-on: ubuntu-latest
timeout-minutes: 15
needs: [test]
if: ${{ needs.findChangedCsFiles.outputs.isCsFilesChanged == 'true' && github.event_name == 'push' && github.ref == 'refs/heads/main' }}
steps:
- uses: actions/checkout@v6
with:
submodules: true
- name: Setup .NET SDK
uses: actions/setup-dotnet@v5
with:
dotnet-version: '8.0.x' # Ensure this matches your project's target
- name: Check if version already published to NuGet.org
id: nuget-version-check
run: |
PACKAGE_VERSION=$(grep '<VersionPrefix>' Link.Foundation.Links.Notation/Link.Foundation.Links.Notation.csproj | sed 's/.*<VersionPrefix>\(.*\)<\/VersionPrefix>.*/\1/')
PACKAGE_ID="Link.Foundation.Links.Notation"
echo "Package: $PACKAGE_ID@$PACKAGE_VERSION"
# Check if version exists on NuGet.org
if curl -f "https://api.nuget.org/v3-flatcontainer/$PACKAGE_ID/$PACKAGE_VERSION/$PACKAGE_ID.nuspec" > /dev/null 2>&1; then
echo "Version $PACKAGE_VERSION already exists on NuGet.org"
echo "should_publish=false" >> $GITHUB_OUTPUT
else
echo "Version $PACKAGE_VERSION does not exist on NuGet.org"
echo "should_publish=true" >> $GITHUB_OUTPUT
fi
- name: Read project information
if: steps.nuget-version-check.outputs.should_publish == 'true'
run: |
export REPOSITORY_NAME=$(basename ${{ github.repository }})
wget "$SCRIPTS_BASE_URL/read_csharp_package_info.sh"
# Override path to use namespace-based directory structure
sed -i 's|Platform.$REPOSITORY_NAME/Platform.$REPOSITORY_NAME.csproj|Link.Foundation.Links.Notation/Link.Foundation.Links.Notation.csproj|g' ./read_csharp_package_info.sh
bash ./read_csharp_package_info.sh
- name: Publish NuGet package
if: steps.nuget-version-check.outputs.should_publish == 'true'
run: |
export REPOSITORY_NAME=$(basename ${{ github.repository }})
wget "$SCRIPTS_BASE_URL/push-csharp-nuget.sh"
bash ./push-csharp-nuget.sh
publishRelease:
runs-on: ubuntu-latest
needs: [pushToNuget, publishDocumentation]
if: ${{ needs.findChangedCsFiles.outputs.isCsFilesChanged == 'true' && needs.pushToNuget.result == 'success' && github.event_name == 'push' && github.ref == 'refs/heads/main' }}
steps:
- uses: actions/checkout@v6
with:
submodules: true
- name: Setup .NET SDK
uses: actions/setup-dotnet@v5
with:
dotnet-version: '8.0.x' # Ensure this matches your project's target
- 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"
# Debug: Check apt lock status
echo "=== APT lock debug ==="
lsof /var/lib/dpkg/lock-frontend 2>/dev/null || echo "No process holding dpkg lock"
ps aux | grep -i apt || echo "No apt processes found"
# Wait for any running apt processes to finish
while sudo fuser /var/lib/dpkg/lock-frontend >/dev/null 2>&1; do
echo "Waiting for other apt process to finish..."
sleep 5
done
# Add retry logic for apt operations in the script
sed -i 's/sudo apt-get install/sudo apt-get install --fix-missing -y/g' ./read_csharp_package_info.sh
# Override path to use namespace-based directory structure
sed -i 's|Platform.$REPOSITORY_NAME/Platform.$REPOSITORY_NAME.csproj|Link.Foundation.Links.Notation/Link.Foundation.Links.Notation.csproj|g' ./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"
# Override the tag format to use version_language instead of language_version
PACKAGE_VERSION=$(<CSHARP_PACKAGE_VERSION.txt)
PACKAGE_RELEASE_NOTES=$(<CSHARP_PACKAGE_RELEASE_NOTES.txt)
PACKAGE_URL="https://www.nuget.org/packages/Link.Foundation.Links.Notation/$PACKAGE_VERSION"
TAG="${PACKAGE_VERSION}_csharp"
RELEASE_NAME="[C#] $PACKAGE_VERSION"
RELEASE_BODY="$PACKAGE_URL
$PACKAGE_RELEASE_NOTES"
./publish-release.sh "$TAG" "$RELEASE_NAME" "$RELEASE_BODY"
generatePdfWithCode:
runs-on: ubuntu-latest
needs: [test]
if: ${{ needs.findChangedCsFiles.outputs.isCsFilesChanged == 'true' && github.event_name == 'push' && github.ref == 'refs/heads/main' }}
steps:
- uses: actions/checkout@v6
with:
submodules: true
- name: Setup .NET SDK
uses: actions/setup-dotnet@v5
with:
dotnet-version: '8.0.x' # Ensure this matches your project's target
- name: Install dependencies for PDF generation
run: |
sudo apt-get update
sudo apt-get install -y texlive texlive-lang-cyrillic texlive-latex-extra python3-pygments ghostscript python-is-python3
- 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"
# Debug: Show downloaded files and their encoding
echo "=== Downloaded files debug ==="
ls -la *.py *.sh
file format-csharp-files.py
hexdump -C format-csharp-files.py | head -5
# Remove BOM (Byte Order Mark) if present
sed -i '1s/^\xEF\xBB\xBF//' ./format-csharp-files.py
# Replace python-pygments with python3-pygments and python2 with python3
sed -i 's/python-pygments/python3-pygments/g' ./generate-csharp-pdf.sh
sed -i 's/python2/python3/g' ./format-csharp-document.sh
# Fix Python 3 compatibility in format-csharp-files.py
sed -i 's/reload(sys)/importlib.reload(sys)/g' ./format-csharp-files.py
sed -i '1i import importlib' ./format-csharp-files.py
# Also remove sys.setdefaultencoding which doesn't exist in Python 3
sed -i '/sys.setdefaultencoding/d' ./format-csharp-files.py
# Fix paths: the project uses Link.Foundation.Links.Notation namespace, not Platform.$REPOSITORY_NAME
# Also fix the ./csharp/ prefix since the script runs from the csharp/ working directory
sed -i 's|\./csharp/Platform\.\$REPOSITORY_NAME|./Link.Foundation.Links.Notation|g' ./format-csharp-document.sh
# Fix the PDF output filename to match the documented link name
sed -i 's|_site/Platform\.\$REPOSITORY_NAME\.pdf|_site/Link.Foundation.Links.Notation.pdf|g' ./generate-csharp-pdf.sh
# Debug: Show file after fixes
echo "=== After fixes ==="
file format-csharp-files.py
head -5 format-csharp-files.py
echo "=== format-csharp-document.sh after fixes ==="
cat ./format-csharp-document.sh
echo "=== generate-csharp-pdf.sh after fixes ==="
cat ./generate-csharp-pdf.sh
bash ./generate-csharp-pdf.sh
- name: Upload PDF artifact
uses: actions/upload-artifact@v4
with:
name: csharp-pdf
path: csharp/_site/Link.Foundation.Links.Notation.pdf
retention-days: 1
publishDocumentation:
runs-on: ubuntu-latest
needs: [test, generatePdfWithCode]
if: ${{ needs.findChangedCsFiles.outputs.isCsFilesChanged == 'true' && github.event_name == 'push' && github.ref == 'refs/heads/main' }}
steps:
- uses: actions/checkout@v6
with:
submodules: true
- name: Download PDF artifact
uses: actions/download-artifact@v4
with:
name: csharp-pdf
path: csharp/pdf-artifact
- name: Setup .NET SDK
uses: actions/setup-dotnet@v5
with:
dotnet-version: '8.0.x' # Ensure this matches your project's target
- name: Install dependencies for documentation
run: |
# Install docfx using dotnet tool instead of nuget
sudo apt-get update
sudo apt-get install -y mono-complete || echo "Mono installation not required"
# Install docfx as a dotnet global tool
dotnet tool install -g docfx
# Add dotnet tools to PATH
echo "~/.dotnet/tools" >> $GITHUB_PATH
- 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"
# Debug: Check if docfx is available
echo "=== DocFX availability debug ==="
which docfx || echo "docfx not found in PATH"
dotnet tool list -g | grep docfx || echo "docfx not installed as global tool"
# Replace nuget commands and mono calls with docfx directly
sed -i 's/sudo apt-get install.*nuget.*/echo "Skipping nuget installation"/g' ./publish-csharp-docs.sh
sed -i 's/nuget install docfx.console.*$/echo "Skipping docfx installation via nuget"/g' ./publish-csharp-docs.sh
sed -i 's/mono.*docfx.exe.*docfx.json/docfx docfx.json/g' ./publish-csharp-docs.sh
# Also replace the line that directly calls nuget install without sudo apt-get
sed -i 's/^nuget install docfx.console.*$/echo "Skipping docfx installation via nuget"/g' ./publish-csharp-docs.sh
# Remove --force flag as it's not supported in DocFX 2.78.3
sed -i 's/^docfx docfx.json --force$/docfx docfx.json/g' ./publish-csharp-docs.sh
# Copy generated PDF into _site after DocFX generates documentation
sed -i '/^docfx docfx.json$/a cp -v "$GITHUB_WORKSPACE/csharp/pdf-artifact/Link.Foundation.Links.Notation.pdf" _site/ 2>/dev/null || echo "PDF artifact not found, skipping"' ./publish-csharp-docs.sh
# Clean up ALL build artifacts to avoid conflicts
echo "=== Cleaning up ALL build artifacts ==="
find . -type d -name "obj" -exec rm -rf {} + 2>/dev/null || true
find . -type d -name "bin" -exec rm -rf {} + 2>/dev/null || true
rm -rf _site 2>/dev/null || true
# Debug: Show project structure
echo "=== Project structure debug ==="
find . -name "*.csproj" -o -name "*.sln" | head -10
echo "Current directory: $(pwd)"
ls -la
# Skip the build - the test job already validated it builds correctly
# DocFX will build what it needs internally
# Debug: Show modified script
echo "=== Modified script debug ==="
cat ./publish-csharp-docs.sh
# Debug: Check PATH and docfx availability before running script
echo "=== PATH debug ==="
echo "PATH: $PATH"
export PATH="$HOME/.dotnet/tools:$PATH"
echo "Updated PATH: $PATH"
which docfx || echo "docfx still not found"
# Ensure the script uses the updated PATH
export PATH="$HOME/.dotnet/tools:$PATH"
# Debug: Test docfx before running script
echo "=== DocFX test ==="
docfx --version || echo "DocFX version command failed"
docfx --help | head -5 || echo "DocFX help command failed"
# Fix DocFX target framework to match our project
echo "=== Fixing DocFX target framework ==="
sed -i 's/"TargetFramework": "netstandard2.0"/"TargetFramework": "net8"/g' docfx.json
# Debug: Show updated docfx.json content
echo "=== DocFX configuration (after fix) ==="
cat docfx.json || echo "No docfx.json found"
echo "=== Running documentation script ==="
bash -x ./publish-csharp-docs.sh 2>&1 | tee docfx_output.log
SCRIPT_EXIT_CODE=$?
if [ $SCRIPT_EXIT_CODE -ne 0 ]; then
echo "=== Script failed with exit code $SCRIPT_EXIT_CODE ==="
echo "Last 100 lines of output:"
tail -100 docfx_output.log || echo "No log file"
echo "=== Checking if documentation was still generated ==="
if [ -d "_site" ]; then
echo "✅ _site directory exists, continuing with deployment despite errors"
ls -la _site/ | head -10
else
echo "❌ No _site directory found, documentation generation completely failed"
exit 1
fi
else
echo "✅ Script completed successfully"
fi
echo "=== Final documentation check ==="
ls -la _site/ 2>/dev/null || echo "No _site directory found"