Migrate to GitHub Actions and use SLNX (#182) #4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: publish | |
| on: | |
| workflow_dispatch: | |
| push: | |
| branches: | |
| - 'master' | |
| pull_request: | |
| branches: | |
| - '*' | |
| release: | |
| types: | |
| - published | |
| env: | |
| DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1 | |
| DOTNET_NOLOGO: true | |
| DOTNET_VERSION: 10.0.x | |
| NUGET_DIRECTORY: ${{ github.workspace }}/nuget | |
| defaults: | |
| run: | |
| shell: pwsh | |
| jobs: | |
| build: | |
| runs-on: ${{ matrix.os }} | |
| timeout-minutes: 15 | |
| strategy: | |
| matrix: | |
| os: [ubuntu-latest, windows-latest] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: ${{ env.DOTNET_VERSION }} | |
| - name: Build | |
| run: dotnet build src/Namotion.Reflection.slnx --configuration Release | |
| - name: Run tests | |
| run: dotnet test src/Namotion.Reflection.slnx --configuration Release --no-build --logger GitHubActions -- RunConfiguration.TargetPlatform=x64 | |
| if: matrix.os == 'windows-latest' | |
| - name: Run tests (.NET only) | |
| run: dotnet test src/Namotion.Reflection.slnx --configuration Release --no-build --logger GitHubActions --framework net8.0 | |
| if: matrix.os == 'ubuntu-latest' | |
| pack: | |
| if: github.event_name == 'release' | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 15 | |
| needs: [ build ] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: ${{ env.DOTNET_VERSION }} | |
| - name: Extract version from tag | |
| id: version | |
| run: | | |
| $version = "${{ github.event.release.tag_name }}" -replace '^v', '' | |
| echo "VERSION=$version" >> $env:GITHUB_OUTPUT | |
| - name: Pack | |
| run: dotnet pack src/Namotion.Reflection.slnx --configuration Release --output ${{ env.NUGET_DIRECTORY }} -p:PackageVersion=${{ steps.version.outputs.VERSION }} | |
| - name: Upload NuGet packages | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: nuget | |
| if-no-files-found: error | |
| retention-days: 7 | |
| path: ${{ env.NUGET_DIRECTORY }}/*.nupkg | |
| validate: | |
| if: github.event_name == 'release' | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 15 | |
| needs: [ pack ] | |
| steps: | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: ${{ env.DOTNET_VERSION }} | |
| - uses: actions/download-artifact@v4 | |
| with: | |
| name: nuget | |
| path: ${{ env.NUGET_DIRECTORY }} | |
| - name: Install nuget validator | |
| run: dotnet tool update Meziantou.Framework.NuGetPackageValidation.Tool --global | |
| - name: Validate package | |
| run: meziantou.validate-nuget-package (Get-ChildItem "${{ env.NUGET_DIRECTORY }}/*.nupkg") | |
| deploy-nuget: | |
| if: github.event_name == 'release' | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 15 | |
| needs: [ validate, build ] | |
| steps: | |
| - uses: actions/download-artifact@v4 | |
| with: | |
| name: nuget | |
| path: ${{ env.NUGET_DIRECTORY }} | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: ${{ env.DOTNET_VERSION }} | |
| - name: Publish NuGet package | |
| run: | | |
| foreach($file in (Get-ChildItem "${{ env.NUGET_DIRECTORY }}" -Recurse -Include *.nupkg)) { | |
| dotnet nuget push $file --api-key "${{ secrets.NUGET_APIKEY }}" --source https://api.nuget.org/v3/index.json --skip-duplicate | |
| } |