diff --git a/.github/workflows/build-and-publish.yml b/.github/workflows/build-and-publish.yml new file mode 100644 index 0000000..41a57bc --- /dev/null +++ b/.github/workflows/build-and-publish.yml @@ -0,0 +1,48 @@ +name: Build and Publish + +on: + push: + branches: [master] + tags: ['v*'] + pull_request: + branches: [master] + +jobs: + build: + runs-on: windows-latest + + steps: + - uses: actions/checkout@v4 + + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: '10.x' + + - name: Determine version + id: version + shell: pwsh + run: | + if ($env:GITHUB_REF -like 'refs/tags/v*') { + $version = $env:GITHUB_REF -replace 'refs/tags/v', '' + } else { + $version = "0.0.0-ci.${{ github.run_number }}" + } + echo "PackageVersion=$version" >> $env:GITHUB_ENV + Write-Host "Version: $version" + + - name: Restore + run: dotnet restore + + - name: Build + run: dotnet build --configuration Release --no-restore -p:PackageVersion=${{ env.PackageVersion }} + + - name: Test + run: dotnet test tests/CodeStructure.Analyzers.Tests/CodeStructure.Analyzers.Tests.csproj --configuration Release --no-build + + - name: Pack + run: dotnet pack CodeStructure.Analyzers/CodeStructure.Analyzers.csproj --configuration Release --no-build --output ./nupkg -p:PackageVersion=${{ env.PackageVersion }} + + - name: Push to NuGet + if: startsWith(github.ref, 'refs/tags/v') + run: dotnet nuget push ./nupkg/*.nupkg --api-key ${{ secrets.CodeStructureNuGetKey }} --source https://api.nuget.org/v3/index.json --skip-duplicate