ci.yml 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. name: Build and Test
  2. on:
  3. push:
  4. branches: [ main, master, develop ]
  5. pull_request:
  6. branches: [ main, master ]
  7. env:
  8. DOTNET_VERSION: '8.0.x'
  9. CONFIGURATION: Release
  10. jobs:
  11. build:
  12. runs-on: windows-latest
  13. steps:
  14. - name: Checkout code
  15. uses: actions/checkout@v4
  16. - name: Setup .NET
  17. uses: actions/setup-dotnet@v4
  18. with:
  19. dotnet-version: ${{ env.DOTNET_VERSION }}
  20. - name: Restore dependencies
  21. run: dotnet restore
  22. - name: Build
  23. run: dotnet build --configuration ${{ env.CONFIGURATION }} --no-restore
  24. - name: Test
  25. run: dotnet test --configuration ${{ env.CONFIGURATION }} --no-build --verbosity normal --collect:"XPlat Code Coverage"
  26. - name: Upload coverage reports
  27. uses: codecov/codecov-action@v4
  28. with:
  29. file: '**/coverage.cobertura.xml'
  30. fail_ci_if_error: false
  31. continue-on-error: true
  32. - name: Upload build artifacts
  33. uses: actions/upload-artifact@v4
  34. with:
  35. name: build-output
  36. path: |
  37. src/*/bin/${{ env.CONFIGURATION }}/
  38. !**/*.pdb
  39. publish-windows:
  40. needs: build
  41. runs-on: windows-latest
  42. if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')
  43. steps:
  44. - name: Checkout code
  45. uses: actions/checkout@v4
  46. - name: Setup .NET
  47. uses: actions/setup-dotnet@v4
  48. with:
  49. dotnet-version: ${{ env.DOTNET_VERSION }}
  50. - name: Publish Windows x64
  51. run: |
  52. dotnet publish src/YZWater.Avalonia -c Release -r win-x64 --self-contained true -p:PublishSingleFile=true -o ./publish/win-x64
  53. - name: Upload Windows artifact
  54. uses: actions/upload-artifact@v4
  55. with:
  56. name: YZWater-win-x64
  57. path: ./publish/win-x64/
  58. publish-linux:
  59. needs: build
  60. runs-on: ubuntu-latest
  61. if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')
  62. steps:
  63. - name: Checkout code
  64. uses: actions/checkout@v4
  65. - name: Setup .NET
  66. uses: actions/setup-dotnet@v4
  67. with:
  68. dotnet-version: ${{ env.DOTNET_VERSION }}
  69. - name: Publish Linux x64
  70. run: |
  71. dotnet publish src/YZWater.Avalonia -c Release -r linux-x64 --self-contained true -p:PublishSingleFile=true -o ./publish/linux-x64
  72. - name: Upload Linux artifact
  73. uses: actions/upload-artifact@v4
  74. with:
  75. name: YZWater-linux-x64
  76. path: ./publish/linux-x64/
  77. publish-macos:
  78. needs: build
  79. runs-on: macos-latest
  80. if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')
  81. steps:
  82. - name: Checkout code
  83. uses: actions/checkout@v4
  84. - name: Setup .NET
  85. uses: actions/setup-dotnet@v4
  86. with:
  87. dotnet-version: ${{ env.DOTNET_VERSION }}
  88. - name: Publish macOS x64
  89. run: |
  90. dotnet publish src/YZWater.Avalonia -c Release -r osx-x64 --self-contained true -p:PublishSingleFile=true -o ./publish/osx-x64
  91. - name: Upload macOS artifact
  92. uses: actions/upload-artifact@v4
  93. with:
  94. name: YZWater-osx-x64
  95. path: ./publish/osx-x64/
  96. release:
  97. needs: [publish-windows, publish-linux, publish-macos]
  98. runs-on: ubuntu-latest
  99. if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
  100. steps:
  101. - name: Download all artifacts
  102. uses: actions/download-artifact@v4
  103. with:
  104. path: ./artifacts
  105. - name: Create release archives
  106. run: |
  107. cd artifacts
  108. for dir in */; do
  109. dirname="${dir%/}"
  110. zip -r "../YZWater-${dirname}.zip" "$dirname"
  111. done
  112. - name: Create GitHub Release
  113. uses: softprops/action-gh-release@v2
  114. with:
  115. files: |
  116. YZWater-*.zip
  117. generate_release_notes: true