Initial commit #2
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: Continuous Integration | |
| on: | |
| push: | |
| branches: | |
| - main | |
| pull_request: | |
| branches: | |
| - main | |
| env: | |
| DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true | |
| DOTNET_NOLOGO: true | |
| DOTNET_CLI_TELEMETRY_OPTOUT: true | |
| jobs: | |
| build-and-test: | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| configuration: [Debug, Release] | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| global-json-file: global.json | |
| - name: Restore dependencies | |
| run: dotnet restore --verbosity minimal | |
| - name: Build solution | |
| run: dotnet build --configuration ${{ matrix.configuration }} --no-restore --verbosity minimal | |
| - name: Run tests | |
| run: dotnet test --configuration ${{ matrix.configuration }} --no-build --verbosity minimal --logger trx --results-directory ./artifacts/test-results | |
| - name: Upload test results | |
| uses: actions/upload-artifact@v4 | |
| if: always() | |
| with: | |
| name: test-results-${{ matrix.configuration }} | |
| path: ./artifacts/test-results/*.trx | |
| - name: Upload build artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: build-artifacts-${{ matrix.configuration }} | |
| path: | | |
| ./artifacts/bin/**/* | |
| !./artifacts/bin/**/ref/** | |
| !./artifacts/bin/**/*.pdb | |
| - name: Generate preview version | |
| if: matrix.configuration == 'Release' && github.event_name == 'push' && github.ref == 'refs/heads/main' | |
| id: version | |
| run: | | |
| # Get base version from project file (Linux compatible) | |
| BASE_VERSION=$(awk -F'[<>]' '/<PackageVersion>/{print $3}' src/Nuggy.Cli.csproj) | |
| # Generate timestamp in format YYYYMMDDHHMMSS | |
| TIMESTAMP=$(date -u +%Y%m%d%H%M%S) | |
| # Create preview version: base-preview.timestamp | |
| PREVIEW_VERSION="${BASE_VERSION}-preview.${TIMESTAMP}" | |
| echo "preview_version=${PREVIEW_VERSION}" >> $GITHUB_OUTPUT | |
| echo "Generated preview version: ${PREVIEW_VERSION}" | |
| - name: Pack NuGet package | |
| if: matrix.configuration == 'Release' && github.event_name == 'push' && github.ref == 'refs/heads/main' | |
| run: | | |
| dotnet pack src/Nuggy.Cli.csproj \ | |
| --configuration Release \ | |
| --no-build \ | |
| --output ./artifacts/packages \ | |
| -p:PackageVersion=${{ steps.version.outputs.preview_version }} | |
| - name: Publish to NuGet.org | |
| if: matrix.configuration == 'Release' && github.event_name == 'push' && github.ref == 'refs/heads/main' | |
| run: | | |
| dotnet nuget push ./artifacts/packages/*.nupkg \ | |
| --source https://api.nuget.org/v3/index.json \ | |
| --api-key ${{ secrets.NUGET_API_KEY }} \ | |
| --skip-duplicate | |
| - name: Upload NuGet package | |
| if: matrix.configuration == 'Release' && github.event_name == 'push' && github.ref == 'refs/heads/main' | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: nuget-package | |
| path: ./artifacts/packages/*.nupkg |