Merge pull request #85 from SuessLabs/feature/PublishSymbols #42
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: Build, Test, Pack, Zip, and Publish | |
| on: | |
| push: | |
| branches: [ master, develop ] | |
| # tags: | |
| # - 'v*' | |
| pull_request: | |
| branches: [ master, develop ] | |
| env: | |
| # Update to desired major.minor. This is the base version family. | |
| BASE_VERSION: "2.1" | |
| PATH_SLNX: "source\\Lite.StateMachine.slnx" | |
| PATH_LIB: "source\\Lite.StateMachine\\Lite.StateMachine.csproj" | |
| PATH_ARTIFACTS: ${{github.workspace}}\artifacts | |
| jobs: | |
| build-test-pack: | |
| runs-on: windows-latest | |
| ## This job runs if the ref is a branch | |
| ##if: startsWith(github.ref, 'refs/heads/') | |
| steps: | |
| # 1. Checkout repository code | |
| - name: 1) Checkout Repository Code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # ensure tags/commits info is available when we expand logic later | |
| # 2. Setup .NET SDK | |
| - name: 2) Setup .NET SDK | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: '10.0.x' # Change to your target version | |
| # 3. Restore dependencies | |
| - name: 3) Restore dependencies | |
| run: dotnet restore ${{env.PATH_SLNX}} | |
| # 4. Build solution | |
| - name: 4) Build Solution | |
| run: dotnet build ${{env.PATH_SLNX}} --configuration Release --no-restore | |
| # 5. Run tests | |
| - name: 5) Run Tests | |
| run: dotnet test ${{env.PATH_SLNX}} --configuration Release --no-build --verbosity normal | |
| # 6. Determin SemVersion package version | |
| # "$run" is based on GitHub Action's Workflow "Runs" counter. | |
| - name: 6) Determine Version for Package | |
| shell: pwsh | |
| run: | | |
| $branch = "${{ github.ref_name }}" | |
| $shortSha = (git rev-parse --short HEAD) | |
| $base = "${{ env.BASE_VERSION }}" | |
| $run = "${{ github.run_number }}" | |
| if ($branch -eq "master") { | |
| # Stable versions on master | |
| $version = "$base.$run" | |
| $prerelease = "" | |
| } | |
| elseif ($branch -eq "develop") { | |
| # Pre-release versions on develop | |
| $version = "$base.$run-beta.$shortSha" | |
| $prerelease = "beta.$shortSha" | |
| } | |
| else { | |
| # Optional default for other branches | |
| $version = "$base.$run-alpha.$shortSha" | |
| $prerelease = "alpha.$shortSha" | |
| } | |
| "PACKAGE_VERSION=$version" | Out-File -FilePath $env:GITHUB_ENV -Append | |
| "VERSION_SUFFIX=$prerelease" | Out-File -FilePath $env:GITHUB_ENV -Append | |
| Write-Host "Calculated PACKAGE_VERSION=$version" | |
| if ($prerelease) { Write-Host "Version suffix=$prerelease" } | |
| # 7. Pack NuGet | |
| - name: 7) Pack NuGet | |
| # Optionally, "--include-symbols" | |
| run: dotnet pack ${{env.PATH_LIB}} --configuration Release --no-build --output ${{env.PATH_ARTIFACTS}} | |
| # dotnet pack source/Lite.StateMachine/Lite.StateMachine.csproj --configuration Release --no-build --output ./artifacts | |
| #- name: Pack NuGet | |
| # shell: pwsh | |
| # run: | | |
| # $version = "${{ env.PACKAGE_VERSION }}" | |
| # dotnet pack ` | |
| # --configuration Release ` | |
| # --no-build ` | |
| # /p:PackageVersion=$version ` | |
| # /p:Version=$version ` | |
| # /p:IncludeSymbols=true /p:SymbolPackageFormat=snupkg ` | |
| # --output ${{env.PATH_ARTIFACTS}} | |
| ## 8. Create ZIP of artifacts | |
| ##- name: 8) Create ZIP archive | |
| ## run: | | |
| ## mkdir ./zip | |
| ## powershell Compress-Archive -Path ${{env.PATH_ARTIFACTS}}\* -DestinationPath ./zip/artifacts.zip | |
| ## #shell: pwsh | |
| ## #run: | | |
| ## # New-Item -ItemType Directory -Force -Path ./zip | Out-Null | |
| ## # Compress-Archive -Path ./artifacts/* -DestinationPath ./zip/artifacts.zip | |
| ## 9. Upload ZIP as workflow artifact | |
| ##- name: 9) Upload ZIP | |
| ## uses: actions/upload-artifact@v4 | |
| ## with: | |
| ## name: nuget-package-zip | |
| ## path: ./zip/artifacts.zip | |
| ## publish-nuget: | |
| ## runs-on: windows-latest | |
| ## | |
| ## # This job runs only if the ref is a tag | |
| ## if: startsWith(github.ref, 'refs/tags/') | |
| ## steps: | |
| ## 10) Publish to NuGet.org (master branch, push events only) | |
| - name: 8) NuGet Push Package | |
| env: | |
| NUGET_API_URL: "https://api.nuget.org/v3/index.json" | |
| ## Optionally pass, `--skip-duplicate` if a pkg version already exists on NuGet.org | |
| if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/') | |
| run: dotnet nuget push ${{env.PATH_ARTIFACTS}}\*.nupkg -k ${{secrets.NUGET_AUTH_TOKEN}} -s ${{env.NUGET_API_URL}} | |
| #- name: Publish to NuGet.org | |
| # if: github.ref_name == 'master' && github.event_name == 'push' | |
| # env: | |
| # NUGET_API_KEY: ${{ secrets.NUGET_AUTH_TOKEN }} | |
| # shell: pwsh | |
| # run: | | |
| # # Push .nupkg first | |
| # dotnet nuget push "./artifacts/*.nupkg" ` | |
| # --source "https://api.nuget.org/v3/index.json" ` | |
| # --api-key "$env:NUGET_API_KEY" ` | |
| # --skip-duplicate ` | |
| # --no-symbols # push symbols separately | |
| # | |
| # # Push symbols (.snupkg) | |
| # dotnet nuget push "./artifacts/*.snupkg" ` | |
| # --source "https://api.nuget.org/v3/index.json" ` | |
| # --api-key "$env:NUGET_API_KEY" ` | |
| # --skip-duplicate |