diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index 8edfa9e..0000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,35 +0,0 @@ -name: Build and Publish NuGet Packages - -on: - workflow_dispatch: - -env: - SOLUTION_PATH: ./SerializationGenerator.sln - BUILD_CONFIG: Release - NUGET_SOURCE: https://api.nuget.org/v3/index.json - -jobs: - build-and-publish: - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Setup .NET SDK - uses: actions/setup-dotnet@v4 - with: - dotnet-version: '10.0.x' - - - name: Restore dependencies - run: | - dotnet clean - dotnet restore - - - name: Build and Pack - run: | - dotnet build -c Release - - - name: Publish to NuGet.org - run: | - dotnet nuget push "**/*.nupkg" --source "https://api.nuget.org/v3/index.json" --api-key "${{ secrets.NUGET_API_KEY }}" --skip-duplicate diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..f5e543b --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,51 @@ +name: Publish to NuGet + +# Trusted publishing: nuget.org trusts this repo + this workflow file (+ the "nuget" environment) +# and exchanges the job's GitHub OIDC token for a short-lived API key. No long-lived key is stored. +# Renaming this file or the environment breaks the nuget.org policy until it is updated to match. + +on: + workflow_dispatch: + +permissions: + contents: read + +jobs: + publish: + if: github.ref == 'refs/heads/main' + runs-on: ubuntu-latest + environment: nuget + permissions: + contents: read + id-token: write + + env: + PACKAGE_DIR: ${{ github.workspace }}/packages + + steps: + - uses: actions/checkout@v7 + + - uses: actions/setup-dotnet@v6 + with: + dotnet-version: '10.0.x' + + # Pack before logging in: the temporary key expires after an hour. + - name: Pack + run: | + dotnet pack ModernUO.Serialization.Annotations/ModernUO.Serialization.Annotations.csproj -c Release -o "$PACKAGE_DIR" + dotnet pack ModernUO.Serialization.Generator/ModernUO.Serialization.Generator.csproj -c Release -o "$PACKAGE_DIR" + dotnet pack ModernUO.Serialization.SchemaGenerator/ModernUO.Serialization.SchemaGenerator.csproj -c Release -o "$PACKAGE_DIR" + + - name: NuGet login (OIDC) + id: login + uses: NuGet/login@v1 + with: + user: ${{ secrets.NUGET_USER }} + + # Symbol packages (.snupkg) next to a .nupkg are pushed along with it. + - name: Push + run: > + dotnet nuget push "$PACKAGE_DIR/*.nupkg" + --api-key "${{ steps.login.outputs.NUGET_API_KEY }}" + --source https://api.nuget.org/v3/index.json + --skip-duplicate