Skip to content

Commit f49bfbc

Browse files
committed
CI: migrate to Trusted Publishing Policy
1 parent 6dfdc09 commit f49bfbc

3 files changed

Lines changed: 45 additions & 28 deletions

File tree

‎.github/workflows/release.yml‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,15 @@ jobs:
6565
./TruePath.SystemIo/bin/Release/TruePath.SystemIo.${{ steps.version.outputs.version }}.nupkg
6666
./TruePath.SystemIo/bin/Release/TruePath.SystemIo.${{ steps.version.outputs.version }}.snupkg
6767
name: TruePath v${{ steps.version.outputs.version }}
68+
- if: startsWith(github.ref, 'refs/tags/v')
69+
id: nuget-login
70+
name: Log in to NuGet
71+
uses: NuGet/login@v1
72+
with:
73+
user: ${{ secrets.NUGET_USER }}
6874
- if: startsWith(github.ref, 'refs/tags/v')
6975
name: Push TruePath to NuGet
7076
run: dotnet nuget push ./TruePath/bin/Release/TruePath.${{ steps.version.outputs.version }}.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_TOKEN_TRUE_PATH }}
7177
- if: startsWith(github.ref, 'refs/tags/v')
7278
name: Push TruePath.SystemIo to NuGet
73-
run: dotnet nuget push ./TruePath.SystemIo/bin/Release/TruePath.SystemIo.${{ steps.version.outputs.version }}.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_TOKEN_TRUE_PATH_SYSTEM_IO }}
79+
run: dotnet nuget push ./TruePath.SystemIo/bin/Release/TruePath.SystemIo.${{ steps.version.outputs.version }}.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ steps.nuget-login.outputs.NUGET_API_KEY }}

‎MAINTAINING.md‎

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
SPDX-FileCopyrightText: 2024-2025 Friedrich von Never <friedrich@fornever.me>
2+
SPDX-FileCopyrightText: 2024-2026 Friedrich von Never <friedrich@fornever.me>
33
44
SPDX-License-Identifier: MIT
55
-->
@@ -15,27 +15,28 @@ Publish a New Version
1515
4. Prepare a corresponding entry in the `CHANGELOG.md` file (usually by renaming the "Unreleased" section).
1616
5. Set `<Version>` in the `Directory.Build.props` file.
1717
6. Merge the aforementioned changes via a pull request.
18-
7. Check if the NuGet keys are still valid (see the **Rotate NuGet Publishing Keys** section if they aren't).
18+
7. If you want to publish a new package (not a new version, but a new project/package) change the NuGet Trusted Publishing Policy: switch from **push only new packages versions** to **push new packages and package versions** (see below for more details).
1919
8. Push a tag in form of `v<VERSION>`, e.g. `v0.0.0`. GitHub Actions will do the rest (push a NuGet packages).
20-
21-
Rotate NuGet Publishing Keys
22-
----------------------------
23-
CI relies on NuGet API keys being added to the secrets.
24-
From time to time, these keys require maintenance: they will become obsolete and will have to be updated.
25-
26-
To update the key:
27-
28-
1. Sign in onto nuget.org.
29-
2. Go to the [API keys][nuget.api-keys] section.
30-
3. Update the existing or create a new key named `truepath.github` with a permission to **Push only new package versions** and only allowed to publish the package **TruePath**.
31-
32-
(If this is the first publication of a new package,
33-
upload a temporary short-living key with permission to add new packages and rotate it afterward.)
34-
4. Update the existing or create a new key named `truepath.systemio.github` with a permission to **Push only new package versions** and only allowed to publish the package **TruePath.SystemIo**.
35-
36-
(If this is the first publication of a new package,
37-
upload a temporary short-living key with permission to add new packages and rotate it afterward.)
38-
5. Paste the generated keys, correspondingly, to the `NUGET_TOKEN_TRUE_PATH` and `NUGET_TOKEN_TRUE_PATH_SYSTEM_IO` variables on the [action secrets][github.secrets] section of GitHub settings.
39-
20+
9. If you were publishing a new package, revert back the change you did at step 8.
21+
22+
NuGet Publishing Policy
23+
-----------------------
24+
This repository relies on [NuGet Trusted Publishing][docs.nuget-trusted-publishing] policy. In case you need to create it again, follow these steps:
25+
26+
1. Sign in to nuget.org.
27+
2. Go to the [Trusted Publishing][nuget.trusted-publishing] section.
28+
3. Create a new policy:
29+
- **Policy Name:** `github.truepath`.
30+
- **Repository Owner:** `ForNeVeR`.
31+
- **Repository**: `TruePath`.
32+
- **Workflow File**: `release.yml`.
33+
- **Environment:** _leave empty_.
34+
- **Scope:** **push only new packages versions**.
35+
- **Glob Patterns and Packages**: `TruePath*`.
36+
4. Put your nuget.org username into the `NUGET_USER` variable on the [action secrets][github.secrets] section of GitHub settings.
37+
38+
When introducing a new package, you can adjust the policy temporarily to allow it to **push new packages and package versions**.
39+
40+
[docs.nuget-trusted-publishing]: https://learn.microsoft.com/en-us/nuget/nuget-org/trusted-publishing
4041
[github.secrets]: https://github.com/ForNeVeR/TruePath/settings/secrets/actions
41-
[nuget.api-keys]: https://www.nuget.org/account/apikeys
42+
[nuget.trusted-publishing]: https://www.nuget.org/account/trustedpublishing

‎scripts/github-actions.fsx‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,9 @@ let workflows = [
164164
]
165165
)
166166

167+
let whenPushingTag = "startsWith(github.ref, 'refs/tags/v')"
167168
step(
168-
condition = "startsWith(github.ref, 'refs/tags/v')",
169+
condition = whenPushingTag,
169170
name = "Create a release",
170171
usesSpec = Auto "softprops/action-gh-release",
171172
options = Map.ofList [
@@ -175,14 +176,23 @@ let workflows = [
175176
]
176177
)
177178
step(
178-
condition = "startsWith(github.ref, 'refs/tags/v')",
179+
condition = whenPushingTag,
180+
id = "nuget-login",
181+
name = "Log in to NuGet",
182+
usesSpec = Auto "NuGet/login",
183+
options = Map.ofList [
184+
"user", "${{ secrets.NUGET_USER }}"
185+
]
186+
)
187+
step(
188+
condition = whenPushingTag,
179189
name = "Push TruePath to NuGet",
180190
run = $"dotnet nuget push ./TruePath/bin/Release/TruePath.{versionField}.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{{{ secrets.NUGET_TOKEN_TRUE_PATH }}}}"
181191
)
182192
step(
183-
condition = "startsWith(github.ref, 'refs/tags/v')",
193+
condition = whenPushingTag,
184194
name = "Push TruePath.SystemIo to NuGet",
185-
run = $"dotnet nuget push ./TruePath.SystemIo/bin/Release/TruePath.SystemIo.{versionField}.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{{{ secrets.NUGET_TOKEN_TRUE_PATH_SYSTEM_IO }}}}"
195+
run = $"dotnet nuget push ./TruePath.SystemIo/bin/Release/TruePath.SystemIo.{versionField}.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{{{ steps.nuget-login.outputs.NUGET_API_KEY }}}}"
186196
)
187197
]
188198
]

0 commit comments

Comments
 (0)