|
| 1 | +name: Publish Packages |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + version: |
| 7 | + description: Release version without the leading "v" |
| 8 | + required: false |
| 9 | + type: string |
| 10 | + publish_nuget: |
| 11 | + description: Publish to NuGet.org |
| 12 | + required: false |
| 13 | + default: true |
| 14 | + type: boolean |
| 15 | + publish_github_packages: |
| 16 | + description: Publish to GitHub Packages |
| 17 | + required: false |
| 18 | + default: true |
| 19 | + type: boolean |
| 20 | + workflow_call: |
| 21 | + inputs: |
| 22 | + version: |
| 23 | + description: Release version without the leading "v" |
| 24 | + required: false |
| 25 | + type: string |
| 26 | + publish_nuget: |
| 27 | + description: Publish to NuGet.org |
| 28 | + required: false |
| 29 | + type: boolean |
| 30 | + publish_github_packages: |
| 31 | + description: Publish to GitHub Packages |
| 32 | + required: false |
| 33 | + type: boolean |
| 34 | + |
| 35 | +permissions: |
| 36 | + contents: read |
| 37 | + packages: write |
| 38 | + |
| 39 | +jobs: |
| 40 | + package: |
| 41 | + uses: ./.github/workflows/publish-artifacts.yml |
| 42 | + with: |
| 43 | + package_version: ${{ inputs.version }} |
| 44 | + |
| 45 | + publish-nuget: |
| 46 | + name: Publish to NuGet.org |
| 47 | + runs-on: ubuntu-latest |
| 48 | + needs: package |
| 49 | + if: ${{ inputs.publish_nuget != false }} |
| 50 | + permissions: |
| 51 | + contents: read |
| 52 | + id-token: write |
| 53 | + |
| 54 | + steps: |
| 55 | + - name: Setup .NET |
| 56 | + uses: actions/setup-dotnet@v5 |
| 57 | + with: |
| 58 | + dotnet-version: 10.0.x |
| 59 | + |
| 60 | + - name: Download packages |
| 61 | + uses: actions/download-artifact@v6 |
| 62 | + with: |
| 63 | + pattern: ModularityKit-packages |
| 64 | + path: dist |
| 65 | + merge-multiple: true |
| 66 | + |
| 67 | + - name: NuGet login |
| 68 | + id: login |
| 69 | + uses: NuGet/login@v1 |
| 70 | + with: |
| 71 | + user: ${{ secrets.NUGET_USERNAME }} |
| 72 | + |
| 73 | + - name: Push packages to NuGet.org |
| 74 | + run: | |
| 75 | + if [ -z "${{ secrets.NUGET_USERNAME }}" ]; then |
| 76 | + echo "NUGET_USERNAME secret is required to publish to NuGet.org with Trusted Publishing." >&2 |
| 77 | + exit 1 |
| 78 | + fi |
| 79 | +
|
| 80 | + for package in dist/*.nupkg; do |
| 81 | + dotnet nuget push "$package" \ |
| 82 | + --api-key "${{ steps.login.outputs.NUGET_API_KEY }}" \ |
| 83 | + --source https://api.nuget.org/v3/index.json \ |
| 84 | + --skip-duplicate |
| 85 | + done |
| 86 | +
|
| 87 | + publish-github-packages: |
| 88 | + name: Publish to GitHub Packages |
| 89 | + runs-on: ubuntu-latest |
| 90 | + needs: package |
| 91 | + if: ${{ inputs.publish_github_packages != false }} |
| 92 | + |
| 93 | + steps: |
| 94 | + - name: Setup .NET |
| 95 | + uses: actions/setup-dotnet@v5 |
| 96 | + with: |
| 97 | + dotnet-version: 10.0.x |
| 98 | + |
| 99 | + - name: Download packages |
| 100 | + uses: actions/download-artifact@v6 |
| 101 | + with: |
| 102 | + pattern: ModularityKit-packages |
| 103 | + path: dist |
| 104 | + merge-multiple: true |
| 105 | + |
| 106 | + - name: Push packages to GitHub Packages |
| 107 | + env: |
| 108 | + GITHUB_TOKEN: ${{ github.token }} |
| 109 | + GITHUB_OWNER: ${{ github.repository_owner }} |
| 110 | + run: | |
| 111 | + for package in dist/*.nupkg; do |
| 112 | + dotnet nuget push "$package" \ |
| 113 | + --api-key "$GITHUB_TOKEN" \ |
| 114 | + --source "https://nuget.pkg.github.com/${GITHUB_OWNER}/index.json" \ |
| 115 | + --skip-duplicate |
| 116 | + done |
0 commit comments