Skip to content

Commit c3d6d64

Browse files
author
LouisDing
committed
Configure GitHub Packages restore in CI
1 parent 17dbf30 commit c3d6d64

4 files changed

Lines changed: 71 additions & 2 deletions

File tree

.github/workflows/cd.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,35 @@ jobs:
5151
exit 1
5252
}
5353
54+
- name: Verify GitHub Packages token
55+
shell: pwsh
56+
env:
57+
GH_PACKAGES_TOKEN: ${{ secrets.GH_PACKAGES_TOKEN }}
58+
run: |
59+
if ([string]::IsNullOrWhiteSpace($env:GH_PACKAGES_TOKEN)) {
60+
Write-Error "Missing repository secret GH_PACKAGES_TOKEN. Create a classic PAT with read:packages permission for GitHub Packages restore."
61+
exit 1
62+
}
63+
5464
# ── 3. 設定 .NET 8 ───────────────────────────────────────────────────────
5565
- name: Setup .NET 8
5666
uses: actions/setup-dotnet@v4
5767
with:
5868
dotnet-version: "8.0.x"
5969

6070
# ── 4. Restore & Publish(self-contained, win-x64)──────────────────────
71+
- name: Configure GitHub Packages NuGet source
72+
shell: pwsh
73+
env:
74+
GH_PACKAGES_TOKEN: ${{ secrets.GH_PACKAGES_TOKEN }}
75+
run: |
76+
dotnet nuget add source `
77+
--username JJDing-Louis `
78+
--password $env:GH_PACKAGES_TOKEN `
79+
--store-password-in-clear-text `
80+
--name JJDing-Louis `
81+
"https://nuget.pkg.github.com/JJDing-Louis/index.json"
82+
6183
- name: Restore NuGet packages
6284
run: dotnet restore YTDownloader.sln
6385

.github/workflows/ci.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,28 @@ jobs:
1919
with:
2020
dotnet-version: "8.0.x"
2121

22+
- name: Verify GitHub Packages token
23+
shell: pwsh
24+
env:
25+
GH_PACKAGES_TOKEN: ${{ secrets.GH_PACKAGES_TOKEN }}
26+
run: |
27+
if ([string]::IsNullOrWhiteSpace($env:GH_PACKAGES_TOKEN)) {
28+
Write-Error "Missing repository secret GH_PACKAGES_TOKEN. Create a classic PAT with read:packages permission for GitHub Packages restore."
29+
exit 1
30+
}
31+
32+
- name: Configure GitHub Packages NuGet source
33+
shell: pwsh
34+
env:
35+
GH_PACKAGES_TOKEN: ${{ secrets.GH_PACKAGES_TOKEN }}
36+
run: |
37+
dotnet nuget add source `
38+
--username JJDing-Louis `
39+
--password $env:GH_PACKAGES_TOKEN `
40+
--store-password-in-clear-text `
41+
--name JJDing-Louis `
42+
"https://nuget.pkg.github.com/JJDing-Louis/index.json"
43+
2244
- name: Restore NuGet packages
2345
run: dotnet restore YTDownloader.sln
2446

docs/PUBLIC_RELEASE_REPO.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ release-repo-template/
3333

3434
## Required Secret
3535

36-
The private source repository needs a GitHub Actions secret:
36+
The private source repository needs a GitHub Actions secret for public release publishing:
3737

3838
```text
3939
RELEASE_REPO_TOKEN
@@ -50,6 +50,28 @@ Use a fine-grained personal access token with access only to the public release
5050
- Contents: Read and write
5151
- Metadata: Read
5252

53+
## Required NuGet Package Secret
54+
55+
The private source repository also needs a GitHub Actions secret for restoring private GitHub Packages:
56+
57+
```text
58+
GH_PACKAGES_TOKEN
59+
```
60+
61+
Use a personal access token classic with:
62+
63+
```text
64+
read:packages
65+
```
66+
67+
The workflow uses this token to add:
68+
69+
```text
70+
https://nuget.pkg.github.com/JJDing-Louis/index.json
71+
```
72+
73+
as a NuGet source before running `dotnet restore`.
74+
5375
## Publish Flow
5476

5577
1. Create or update the private source repository.

docs/RELEASE.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ The CD workflow will:
4747
6. create a GitHub Release in `JJDing-Louis/YTDownloader-Release`;
4848
7. upload the installer and hash file to the public release repository.
4949

50-
The workflow requires the private source repository secret `RELEASE_REPO_TOKEN`.
50+
The workflow requires these private source repository secrets:
51+
52+
- `RELEASE_REPO_TOKEN`: fine-grained PAT that can write releases to `JJDing-Louis/YTDownloader-Release`.
53+
- `GH_PACKAGES_TOKEN`: classic PAT with `read:packages` permission so GitHub Actions can restore `JJNET.DataAccess` and `JJNET.Utility` from GitHub Packages.
5154

5255
## Local Installer Build
5356

0 commit comments

Comments
 (0)