Skip to content

Commit d244839

Browse files
authored
Merge pull request #25 from Cysharp/ci/nuget
ci: use OIDC for NuGet package push authentication
2 parents e7d5af4 + 1cff934 commit d244839

1 file changed

Lines changed: 31 additions & 4 deletions

File tree

.github/workflows/build-release.yaml

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
# pack nuget
3939
- run: dotnet build -c Release -p:Version=${{ inputs.tag }}
4040
- run: dotnet test -c Release --no-build -p:Version=${{ inputs.tag }}
41-
- run: dotnet pack -c Release --no-build -p:Version=${{ inputs.tag }} -o ./publish
41+
- run: dotnet pack -c Release --no-build -p:Version=${{ inputs.tag }} -p:IncludeSymbols=true -p:SymbolPackageFormat=snupkg -o ./publish
4242
- uses: Cysharp/Actions/.github/actions/upload-artifact@main
4343
with:
4444
name: nuget
@@ -96,9 +96,36 @@ jobs:
9696
path: ./src/RandomFixtureKit.Unity/RandomFixtureKit.${{ inputs.tag }}.unitypackage
9797
retention-days: 1
9898

99+
# publish
100+
publish:
101+
name: "Publish NuGet packages"
102+
needs: [build-dotnet, build-unity]
103+
permissions:
104+
contents: read
105+
id-token: write # required for NuGet Trusted Publish
106+
runs-on: ubuntu-24.04
107+
timeout-minutes: 10
108+
steps:
109+
- uses: Cysharp/Actions/.github/actions/setup-dotnet@main
110+
- uses: Cysharp/Actions/.github/actions/download-artifact@main
111+
# push nuget
112+
- name: NuGet login (OIDC)
113+
uses: NuGet/login@8d196754b4036150537f80ac539e15c2f1028841 # v1.2.0
114+
id: login
115+
with:
116+
user: ${{ secrets.NUGET_USER }}
117+
- run: dotnet nuget push "./nuget/*.nupkg" --skip-duplicate -s https://api.nuget.org/v3/index.json -k "${NUGET_KEY}"
118+
if: ${{ !inputs.dry-run }}
119+
env:
120+
NUGET_KEY: ${{ steps.login.outputs.NUGET_API_KEY }}
121+
- run: dotnet nuget push "./nuget/*.snupkg" --skip-duplicate -s https://api.nuget.org/v3/index.json -k "${NUGET_KEY}"
122+
if: ${{ !inputs.dry-run }}
123+
env:
124+
NUGET_KEY: ${{ steps.login.outputs.NUGET_API_KEY }}
125+
99126
# release
100127
create-release:
101-
needs: [update-packagejson, build-dotnet, build-unity]
128+
needs: [update-packagejson, publish]
102129
permissions:
103130
contents: write
104131
id-token: write # required for NuGet Trusted Publish
@@ -107,14 +134,14 @@ jobs:
107134
commit-id: ${{ needs.update-packagejson.outputs.sha }}
108135
dry-run: ${{ inputs.dry-run }}
109136
tag: ${{ inputs.tag }}
110-
nuget-push: true
137+
nuget-push: false
111138
release-upload: true
112139
release-asset-path: ./RandomFixtureKit.${{ inputs.tag }}.unitypackage/RandomFixtureKit.${{ inputs.tag }}.unitypackage
113140
secrets: inherit
114141

115142
cleanup:
116143
if: ${{ needs.update-packagejson.outputs.is-branch-created == 'true' }}
117-
needs: [update-packagejson, build-unity]
144+
needs: [update-packagejson, create-release]
118145
permissions:
119146
contents: write
120147
uses: Cysharp/Actions/.github/workflows/clean-packagejson-branch.yaml@main

0 commit comments

Comments
 (0)