update CI/CD to dotnet 9 correctly #18
Workflow file for this run
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: Release | |
| on: | |
| push: | |
| tags: | |
| - '[0-9]+.[0-9]+.[0-9]+*' # Matches version tags like 1.0.0, 1.0.0-20250330, 1.0.0-alpha-20250330.1 | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: 'Version number (e.g. 1.0.0, 1.0.0-20250330, 1.0.0-alpha-20250330.1)' | |
| required: true | |
| type: string | |
| jobs: | |
| build-and-publish: | |
| runs-on: ubuntu-latest | |
| environment: production # Adds protection and approval requirements | |
| env: | |
| AZURE_OPENAI_ENDPOINT: ${{ secrets.AZURE_OPENAI_ENDPOINT }} | |
| AZURE_OPENAI_API_KEY: ${{ secrets.AZURE_OPENAI_API_KEY }} | |
| AZURE_OPENAI_CHAT_DEPLOYMENT: ${{ secrets.AZURE_OPENAI_CHAT_DEPLOYMENT }} | |
| AZURE_OPENAI_SYSTEM_PROMPT: ${{ secrets.AZURE_OPENAI_SYSTEM_PROMPT }} | |
| BING_SEARCH_V7_ENDPOINT: ${{ secrets.BING_SEARCH_V7_ENDPOINT }} | |
| BING_SEARCH_V7_KEY: ${{ secrets.BING_SEARCH_V7_KEY }} | |
| GOOGLE_SEARCH_ENDPOINT: ${{ secrets.GOOGLE_SEARCH_ENDPOINT }} | |
| GOOGLE_SEARCH_KEY: ${{ secrets.GOOGLE_SEARCH_KEY }} | |
| GOOGLE_SEARCH_ENGINE_ID: ${{ secrets.GOOGLE_SEARCH_ENGINE_ID }} | |
| steps: | |
| - uses: actions/checkout@v3 | |
| with: | |
| fetch-depth: 0 # Fetch all history for proper version determination | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v3 | |
| with: | |
| dotnet-version: 9.0.x | |
| - name: Determine version | |
| id: get-version | |
| run: | | |
| if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then | |
| VERSION="${{ github.event.inputs.version }}" | |
| else | |
| # Extract version from tag (remove leading 'v' if present) | |
| VERSION=$(echo ${{ github.ref_name }} | sed 's/^v//') | |
| fi | |
| echo "VERSION=$VERSION" >> $GITHUB_ENV | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| # Calculate numeric version components for both projects | |
| # Extract the major.minor.build parts from the version | |
| MAJOR=$(echo $VERSION | sed -E 's/^([0-9]+).*/\1/') | |
| MINOR=$(echo $VERSION | sed -E 's/^[0-9]+\.([0-9]+).*/\1/') | |
| BUILD=$(echo $VERSION | sed -E 's/^[0-9]+\.[0-9]+\.([0-9]+).*/\1/') | |
| # Try to extract a YYYYMMDD date pattern from the version | |
| DATE_PART=$(echo $VERSION | grep -oE '20[0-9]{2}(0[1-9]|1[0-2])(0[1-9]|[12][0-9]|3[01])') | |
| if [ -n "$DATE_PART" ]; then | |
| echo "Found date in version: $DATE_PART" | |
| # Convert YYYYMMDD to day of year | |
| # Extract year, month, day | |
| YEAR=${DATE_PART:0:4} | |
| MONTH=${DATE_PART:4:2} | |
| DAY=${DATE_PART:6:2} | |
| # Use date command to convert to day of year | |
| DAY_OF_YEAR=$(date -d "$YEAR-$MONTH-$DAY" +%j | sed 's/^0*//') | |
| echo "Using date from version: $YEAR-$MONTH-$DAY (day of year: $DAY_OF_YEAR)" | |
| else | |
| echo "No date found in version, using today's date as fallback" | |
| DAY_OF_YEAR=$(date '+%j' | sed 's/^0*//') | |
| fi | |
| # Extract final decimal part if it exists (match the last .digit sequence) | |
| FINAL_PART=$(echo $VERSION | grep -oE '\.[0-9]+$' | grep -oE '[0-9]+') | |
| if [ -z "$FINAL_PART" ]; then | |
| FINAL_PART=0 | |
| fi | |
| # Calculate revision: day_of_year * 100 + final_part | |
| REVISION=$((DAY_OF_YEAR * 100 + FINAL_PART)) | |
| # Safety check: ensure revision doesn't exceed maximum allowed value | |
| if [ $REVISION -gt 65535 ]; then | |
| echo "WARNING: Revision exceeds maximum allowed value (65535). Capping at 65535." | |
| REVISION=65535 | |
| fi | |
| # Combine for a valid .NET version with 4 parts | |
| NUMERIC_VERSION="$MAJOR.$MINOR.$BUILD.$REVISION" | |
| echo "Using numeric version: $NUMERIC_VERSION for AssemblyVersion and FileVersion" | |
| echo "NUMERIC_VERSION=$NUMERIC_VERSION" >> $GITHUB_ENV | |
| - name: Update project versions | |
| run: | | |
| # Update all projects with the same version information | |
| # Apply semantic version (can include pre-release tags) | |
| sed -i "s/<Version>.*<\/Version>/<Version>${{ env.VERSION }}<\/Version>/" src/cycod/cycod.csproj | |
| sed -i "s/<Version>.*<\/Version>/<Version>${{ env.VERSION }}<\/Version>/" src/cycodt/cycodt.csproj | |
| sed -i "s/<Version>.*<\/Version>/<Version>${{ env.VERSION }}<\/Version>/" src/cycodmd/cycodmd.csproj | |
| # Apply informational version (can include pre-release tags) | |
| sed -i "s/<InformationalVersion>.*<\/InformationalVersion>/<InformationalVersion>${{ env.VERSION }}<\/InformationalVersion>/" src/cycod/cycod.csproj | |
| sed -i "s/<InformationalVersion>.*<\/InformationalVersion>/<InformationalVersion>${{ env.VERSION }}<\/InformationalVersion>/" src/cycodt/cycodt.csproj | |
| sed -i "s/<InformationalVersion>.*<\/InformationalVersion>/<InformationalVersion>${{ env.VERSION }}<\/InformationalVersion>/" src/cycodmd/cycodmd.csproj | |
| # Apply numeric versions for assembly and file versions (must be numeric only) | |
| sed -i "s/<AssemblyVersion>.*<\/AssemblyVersion>/<AssemblyVersion>${{ env.NUMERIC_VERSION }}<\/AssemblyVersion>/" src/cycod/cycod.csproj | |
| sed -i "s/<AssemblyVersion>.*<\/AssemblyVersion>/<AssemblyVersion>${{ env.NUMERIC_VERSION }}<\/AssemblyVersion>/" src/cycodt/cycodt.csproj | |
| sed -i "s/<AssemblyVersion>.*<\/AssemblyVersion>/<AssemblyVersion>${{ env.NUMERIC_VERSION }}<\/AssemblyVersion>/" src/cycodmd/cycodmd.csproj | |
| sed -i "s/<FileVersion>.*<\/FileVersion>/<FileVersion>${{ env.NUMERIC_VERSION }}<\/FileVersion>/" src/cycod/cycod.csproj | |
| sed -i "s/<FileVersion>.*<\/FileVersion>/<FileVersion>${{ env.NUMERIC_VERSION }}<\/FileVersion>/" src/cycodt/cycodt.csproj | |
| sed -i "s/<FileVersion>.*<\/FileVersion>/<FileVersion>${{ env.NUMERIC_VERSION }}<\/FileVersion>/" src/cycodmd/cycodmd.csproj | |
| - name: Restore dependencies | |
| run: dotnet restore | |
| - name: Build | |
| run: dotnet build --configuration Release --no-restore | |
| - name: Test | |
| run: dotnet test --configuration Release --verbosity normal --logger "trx;LogFileName=test-results.trx" --results-directory ./TestResults | |
| - name: Run cycodt tests | |
| run: | | |
| export PATH=$PATH:$(pwd)/src/cycod/bin/Release/net9.0:$(pwd)/src/cycodt/bin/Release/net9.0:$(pwd)/src/cycodmd/bin/Release/net9.0 | |
| which cycod | |
| which cycodmd | |
| which cycodt | |
| cycodt run --output-file ./TestResults/test-results-cycodt.trx | |
| - name: Upload test results | |
| uses: actions/upload-artifact@v4 | |
| if: always() # Upload test results even if tests fail | |
| with: | |
| name: test-results | |
| path: ./TestResults/*.trx | |
| - name: Publish test results | |
| uses: dorny/test-reporter@v1 | |
| if: always() # Run this step even if previous steps failed | |
| with: | |
| name: .NET Tests | |
| path: ./TestResults/*.trx | |
| reporter: dotnet-trx | |
| fail-on-error: false | |
| - name: Pack cycod | |
| run: | | |
| # Publish for multiple platforms first | |
| dotnet publish src/cycod/cycod.csproj -c Release -r win-x64 | |
| dotnet publish src/cycod/cycod.csproj -c Release -r linux-x64 | |
| dotnet publish src/cycod/cycod.csproj -c Release -r osx-x64 | |
| # Then pack the NuGet package (will include all published runtimes) | |
| dotnet pack src/cycod/cycod.csproj --configuration Release --no-build -o nuget-packages | |
| - name: Pack cycodt | |
| run: | | |
| # Publish for multiple platforms first | |
| dotnet publish src/cycodt/cycodt.csproj -c Release -r win-x64 | |
| dotnet publish src/cycodt/cycodt.csproj -c Release -r linux-x64 | |
| dotnet publish src/cycodt/cycodt.csproj -c Release -r osx-x64 | |
| # Then pack the NuGet package (will include all published runtimes) | |
| dotnet pack src/cycodt/cycodt.csproj --configuration Release --no-build -o nuget-packages | |
| - name: Pack cycodmd | |
| run: | | |
| # Publish for multiple platforms first | |
| dotnet publish src/cycodmd/cycodmd.csproj -c Release -r win-x64 | |
| dotnet publish src/cycodmd/cycodmd.csproj -c Release -r linux-x64 | |
| dotnet publish src/cycodmd/cycodmd.csproj -c Release -r osx-x64 | |
| # Then pack the NuGet package (will include all published runtimes) | |
| dotnet pack src/cycodmd/cycodmd.csproj --configuration Release --no-build -o nuget-packages | |
| - name: Generate package checksums | |
| run: | | |
| cd nuget-packages | |
| for f in *.nupkg; do | |
| sha256sum "$f" > "${f}.sha256" | |
| done | |
| cd .. | |
| - name: Upload NuGet packages and checksums | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: cycod-cycodt-cycodmd-nuget-packages | |
| path: nuget-packages/* | |
| - name: Publish to NuGet | |
| if: ${{ env.NUGET_API_KEY != '' }} | |
| run: dotnet nuget push "nuget-packages/*.nupkg" --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json | |
| env: | |
| NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }} |