chore: fix ci build for tests #11
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 | |
| tags: | |
| - 'v*' | |
| 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: | |
| - 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 | |
| build-cross-platform: | |
| needs: build-and-test | |
| if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')) | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| runtime: | |
| - linux-x64 | |
| - linux-arm64 | |
| - win-x64 | |
| - win-arm64 | |
| - osx-x64 | |
| - osx-arm64 | |
| 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: Generate version | |
| id: version | |
| run: | | |
| if [[ $GITHUB_REF == refs/tags/* ]]; then | |
| # For tags, use the tag name as version | |
| VERSION=${GITHUB_REF#refs/tags/v} | |
| ASSEMBLY_VERSION="${VERSION}.0" | |
| FILE_VERSION="${VERSION}.0" | |
| echo "version=${VERSION}" >> $GITHUB_OUTPUT | |
| echo "assembly_version=${ASSEMBLY_VERSION}" >> $GITHUB_OUTPUT | |
| echo "file_version=${FILE_VERSION}" >> $GITHUB_OUTPUT | |
| echo "is_release=true" >> $GITHUB_OUTPUT | |
| else | |
| # For main branch, generate preview version | |
| BASE_VERSION=$(awk -F'[<>]' '/<PackageVersion>/{print $3}' src/Nuggy.Cli.csproj) | |
| TIMESTAMP=$(date -u +%Y%m%d%H%M%S) | |
| VERSION="${BASE_VERSION}-preview.${TIMESTAMP}" | |
| ASSEMBLY_VERSION="${BASE_VERSION}.0" | |
| FILE_VERSION="${BASE_VERSION}.0" | |
| echo "version=${VERSION}" >> $GITHUB_OUTPUT | |
| echo "assembly_version=${ASSEMBLY_VERSION}" >> $GITHUB_OUTPUT | |
| echo "file_version=${FILE_VERSION}" >> $GITHUB_OUTPUT | |
| echo "is_release=false" >> $GITHUB_OUTPUT | |
| fi | |
| echo "Generated version: ${VERSION}" | |
| - name: Publish single-file executable | |
| run: | | |
| dotnet publish src/Nuggy.Cli.csproj \ | |
| --configuration Release \ | |
| --runtime ${{ matrix.runtime }} \ | |
| --self-contained true \ | |
| --output ./artifacts/publish/${{ matrix.runtime }} \ | |
| -p:PublishSingleFile=true \ | |
| -p:PublishTrimmed=true \ | |
| -p:TrimMode=link \ | |
| -p:EnableCompressionInSingleFile=true \ | |
| -p:IncludeNativeLibrariesForSelfExtract=true \ | |
| -p:AssemblyVersion=${{ steps.version.outputs.assembly_version }} \ | |
| -p:FileVersion=${{ steps.version.outputs.file_version }} \ | |
| -p:Version=${{ steps.version.outputs.version }} | |
| - name: Create archive | |
| run: | | |
| cd ./artifacts/publish/${{ matrix.runtime }} | |
| if [[ "${{ matrix.runtime }}" == win-* ]]; then | |
| # Windows - create zip | |
| zip -r "../../../nuggy-${{ steps.version.outputs.version }}-${{ matrix.runtime }}.zip" . | |
| else | |
| # Linux/macOS - create tar.gz | |
| tar -czf "../../../nuggy-${{ steps.version.outputs.version }}-${{ matrix.runtime }}.tar.gz" . | |
| fi | |
| - name: Upload artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: nuggy-${{ matrix.runtime }} | |
| path: ./artifacts/nuggy-${{ steps.version.outputs.version }}-${{ matrix.runtime }}.* | |
| create-release: | |
| # Create GitHub releases for both tagged releases and preview releases from main | |
| # Tagged releases (v1.0.0) -> stable releases | |
| # Main branch pushes -> preview releases with timestamp versions | |
| needs: build-cross-platform | |
| if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')) | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Get version | |
| id: version | |
| run: | | |
| if [[ $GITHUB_REF == refs/tags/* ]]; then | |
| # For tags, use the tag name as version | |
| VERSION=${GITHUB_REF#refs/tags/v} | |
| IS_PRERELEASE=false | |
| RELEASE_NAME="Release $VERSION" | |
| else | |
| # For main branch, generate preview version | |
| BASE_VERSION=$(awk -F'[<>]' '/<PackageVersion>/{print $3}' src/Nuggy.Cli.csproj) | |
| TIMESTAMP=$(date -u +%Y%m%d%H%M%S) | |
| VERSION="${BASE_VERSION}-preview.${TIMESTAMP}" | |
| IS_PRERELEASE=true | |
| RELEASE_NAME="Preview Release $VERSION" | |
| fi | |
| echo "version=${VERSION}" >> $GITHUB_OUTPUT | |
| echo "is_prerelease=${IS_PRERELEASE}" >> $GITHUB_OUTPUT | |
| echo "release_name=${RELEASE_NAME}" >> $GITHUB_OUTPUT | |
| echo "Generated version: ${VERSION}" | |
| - name: Download all artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: ./artifacts | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: v${{ steps.version.outputs.version }} | |
| name: ${{ steps.version.outputs.release_name }} | |
| body: | | |
| ## ${{ steps.version.outputs.release_name }} | |
| ### Downloads | |
| Choose the appropriate binary for your platform: | |
| - **Linux x64**: `nuggy-${{ steps.version.outputs.version }}-linux-x64.tar.gz` | |
| - **Linux ARM64**: `nuggy-${{ steps.version.outputs.version }}-linux-arm64.tar.gz` | |
| - **Windows x64**: `nuggy-${{ steps.version.outputs.version }}-win-x64.zip` | |
| - **Windows ARM64**: `nuggy-${{ steps.version.outputs.version }}-win-arm64.zip` | |
| - **macOS x64**: `nuggy-${{ steps.version.outputs.version }}-osx-x64.tar.gz` | |
| - **macOS ARM64**: `nuggy-${{ steps.version.outputs.version }}-osx-arm64.tar.gz` | |
| ### Installation | |
| 1. Download the appropriate archive for your platform | |
| 2. Extract the archive | |
| 3. Run the `nuggy` executable (or `Nuggy.Cli.exe` on Windows) | |
| ### Alternatively, install as a .NET tool | |
| ```bash | |
| dotnet tool install -g Nuggy.Cli | |
| ``` | |
| ${{ steps.version.outputs.is_prerelease == 'true' && '> **Note**: This is a preview release built from the latest main branch. Use at your own risk.' || '' }} | |
| files: "./artifacts/nuggy-*/nuggy-*" | |
| draft: false | |
| prerelease: ${{ steps.version.outputs.is_prerelease }} | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| publish-nuget: | |
| needs: build-and-test | |
| if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')) | |
| runs-on: ubuntu-latest | |
| 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: Generate version | |
| id: version | |
| run: | | |
| if [[ $GITHUB_REF == refs/tags/* ]]; then | |
| # For tags, use the tag name as version | |
| VERSION=${GITHUB_REF#refs/tags/v} | |
| echo "version=${VERSION}" >> $GITHUB_OUTPUT | |
| echo "is_release=true" >> $GITHUB_OUTPUT | |
| else | |
| # For main branch, generate preview version | |
| BASE_VERSION=$(awk -F'[<>]' '/<PackageVersion>/{print $3}' src/Nuggy.Cli.csproj) | |
| TIMESTAMP=$(date -u +%Y%m%d%H%M%S) | |
| VERSION="${BASE_VERSION}-preview.${TIMESTAMP}" | |
| echo "version=${VERSION}" >> $GITHUB_OUTPUT | |
| echo "is_release=false" >> $GITHUB_OUTPUT | |
| fi | |
| echo "Generated version: ${VERSION}" | |
| - name: Pack NuGet package | |
| run: | | |
| dotnet pack src/Nuggy.Cli.csproj \ | |
| --configuration Release \ | |
| --output ./artifacts/packages \ | |
| -p:PackageVersion=${{ steps.version.outputs.version }} | |
| - name: Publish to NuGet.org | |
| 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 | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: nuget-package | |
| path: ./artifacts/packages/*.nupkg |