|
| 1 | +name: NuGet Publish |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main, master ] |
| 6 | + paths: |
| 7 | + - '**/*.fs' |
| 8 | + - '**/*.fsproj' |
| 9 | + - '**/*.sln' |
| 10 | + - '.github/workflows/nuget-publish.yml' |
| 11 | + release: |
| 12 | + types: [ published ] |
| 13 | + workflow_dispatch: |
| 14 | + inputs: |
| 15 | + version: |
| 16 | + description: 'Version to publish (e.g., 0.2.0). If empty on dispatch, publish is skipped.' |
| 17 | + required: false |
| 18 | + |
| 19 | +jobs: |
| 20 | + publish: |
| 21 | + runs-on: ubuntu-latest |
| 22 | + |
| 23 | + steps: |
| 24 | + - name: Checkout code |
| 25 | + uses: actions/checkout@v4 |
| 26 | + |
| 27 | + - name: Setup .NET SDKs |
| 28 | + uses: actions/setup-dotnet@v4 |
| 29 | + with: |
| 30 | + dotnet-version: | |
| 31 | + 8.0.x |
| 32 | + 9.0.x |
| 33 | + cache: true |
| 34 | + |
| 35 | + - name: Restore dependencies |
| 36 | + run: dotnet restore ancpdevkit.sln |
| 37 | + |
| 38 | + - name: Build solution |
| 39 | + run: dotnet build ancpdevkit.sln --configuration Release --no-restore |
| 40 | + |
| 41 | + - name: Run tests |
| 42 | + run: dotnet test ancpdevkit.sln --configuration Release --no-build --verbosity normal |
| 43 | + |
| 44 | + - name: Determine package version |
| 45 | + id: version |
| 46 | + run: | |
| 47 | + set -euo pipefail |
| 48 | + event='${{ github.event_name }}' |
| 49 | + ver='' |
| 50 | + if [ "$event" = 'release' ]; then |
| 51 | + ver='${{ github.event.release.tag_name }}' |
| 52 | + elif [ "$event" = 'workflow_dispatch' ]; then |
| 53 | + ver='${{ github.event.inputs.version }}' |
| 54 | + fi |
| 55 | + ver="${ver#v}" |
| 56 | + if [ -n "$ver" ]; then |
| 57 | + echo "Using package version: $ver" |
| 58 | + echo "pkg_version=$ver" >> "$GITHUB_OUTPUT" |
| 59 | + else |
| 60 | + echo "No version provided; skipping pack/publish." |
| 61 | + echo "pkg_version=" >> "$GITHUB_OUTPUT" |
| 62 | + fi |
| 63 | +
|
| 64 | + - name: Pack NuGet packages |
| 65 | + if: (github.event_name == 'release' || github.event_name == 'workflow_dispatch') && steps.version.outputs.pkg_version != '' |
| 66 | + run: | |
| 67 | + dotnet pack tools/ancp/f/f.fsproj --configuration Release --no-build --output ./nupkg \ |
| 68 | + -p:GeneratePackageOnBuild=false -p:PackageVersion=${{ steps.version.outputs.pkg_version }} -p:ContinuousIntegrationBuild=true |
| 69 | + dotnet pack tools/ancp/fc/fc.fsproj --configuration Release --no-build --output ./nupkg \ |
| 70 | + -p:GeneratePackageOnBuild=false -p:PackageVersion=${{ steps.version.outputs.pkg_version }} -p:ContinuousIntegrationBuild=true |
| 71 | +
|
| 72 | + - name: Publish packages to NuGet.org |
| 73 | + if: (github.event_name == 'release' || github.event_name == 'workflow_dispatch') && steps.version.outputs.pkg_version != '' |
| 74 | + env: |
| 75 | + NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }} |
| 76 | + run: | |
| 77 | + if [ -z "+${NUGET_API_KEY}+" ]; then echo "NUGET_API_KEY is not set" && exit 1; fi |
| 78 | + dotnet nuget push ./nupkg/*.nupkg \ |
| 79 | + --api-key $NUGET_API_KEY \ |
| 80 | + --source https://api.nuget.org/v3/index.json \ |
| 81 | + --skip-duplicate |
0 commit comments