Skip to content

Commit 7a2a93e

Browse files
committed
[CI] migrate NuGet push from token auth to trusted publishing
1 parent 19e0330 commit 7a2a93e

6 files changed

Lines changed: 39 additions & 112 deletions

.github/workflows/milky-build.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ on:
1414
- Lagrange.Proto/**
1515
- Lagrange.Proto.Generator/**
1616
pull_request:
17-
branches: [ main ]
17+
branches:
18+
- main
19+
- master
1820
paths:
1921
- .github/workflows/milky-build.yaml
2022
- Lagrange.Codec/**

.github/workflows/milky-docker.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ on:
1414
- Lagrange.Proto/**
1515
- Lagrange.Proto.Generator/**
1616
pull_request:
17-
branches: [ main ]
17+
branches:
18+
- main
19+
- master
1820
paths:
1921
- .github/workflows/milky-docker.yaml
2022
- Lagrange.Codec/**

.github/workflows/native-api-build.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,19 @@
22

33
on:
44
push:
5-
branches: [ main ]
5+
branches:
6+
- main
7+
- master
68
paths:
79
- Lagrange.Codec/**
810
- Lagrange.Core/**
911
- Lagrange.Proto/**
1012
- Lagrange.Proto.Generator/**
1113
- Lagrange.Core.NativeAPI/**
1214
pull_request:
13-
branches: [ main ]
15+
branches:
16+
- main
17+
- master
1418
paths:
1519
- Lagrange.Codec/**
1620
- Lagrange.Core/**

.github/workflows/nuget-push-lagrange-core.yaml

Lines changed: 9 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
push:
55
branches:
66
- main
7+
- master
78
paths:
89
- "Lagrange.Core/Lagrange.Core.csproj"
910
workflow_dispatch:
@@ -13,45 +14,17 @@ jobs:
1314
runs-on: ubuntu-latest
1415

1516
steps:
16-
- uses: actions/checkout@v4
17-
18-
# Check Version
19-
- shell: pwsh
20-
run: |
21-
$lversion = ([xml](Get-Content .\Lagrange.Core\Lagrange.Core.csproj)).Project.PropertyGroup.Version
22-
echo "Local version: $lversion"
23-
24-
try {
25-
$response = Invoke-WebRequest -Uri "https://api.nuget.org/v3-flatcontainer/lagrange.core/index.json"
26-
} catch {
27-
if ($_.Exception.Response.StatusCode.value__ -eq 404) {
28-
echo "No remote version"
29-
echo "continued=true" >> $env:GITHUB_ENV
30-
exit 0
31-
} else {
32-
throw
33-
}
34-
}
35-
36-
$rversions = ($response.Content | ConvertFrom-Json).versions
37-
echo "Remote version: $rversions"
38-
if ($lversion -in $rversions) {
39-
echo "Version($lversion) already exists"
40-
echo "continued=false" >> $env:GITHUB_ENV
41-
exit 0
42-
}
17+
- id: nuget-login
18+
uses: NuGet/login@v1
19+
with:
20+
user: Linwenxuan04
4321

44-
echo "Version($lversion) does not exist"
45-
echo "continued=true" >> $env:GITHUB_ENV
46-
exit 0
22+
- uses: actions/checkout@v4
4723

48-
- if: env.continued == 'true'
49-
uses: actions/setup-dotnet@v4
24+
- uses: actions/setup-dotnet@v4
5025
with:
5126
dotnet-version: '10'
5227

53-
- if: env.continued == 'true'
54-
run: dotnet pack -c Release -p:IncludeSymbols=true -p:SymbolPackageFormat=snupkg Lagrange.Core
28+
- run: dotnet pack -c Release -p:IncludeSymbols=true -p:SymbolPackageFormat=snupkg Lagrange.Core
5529

56-
- if: env.continued == 'true'
57-
run: dotnet nuget push ./Lagrange.Core/bin/Release/*.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_TOKEN }}
30+
- run: dotnet nuget push ./Lagrange.Core/bin/Release/*.nupkg --source https://api.nuget.org/v3/index.json --skip-duplicate --api-key ${{ steps.nuget-login.outputs.NUGET_API_KEY }}

.github/workflows/nuget-push-lagrange-proto-codegen.yaml

Lines changed: 9 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
push:
55
branches:
66
- main
7+
- master
78
paths:
89
- "Lagrange.Proto.Generator/Lagrange.Proto.Generator.csproj"
910
workflow_dispatch:
@@ -13,45 +14,17 @@ jobs:
1314
runs-on: ubuntu-latest
1415

1516
steps:
16-
- uses: actions/checkout@v4
17-
18-
# Check Version
19-
- shell: pwsh
20-
run: |
21-
$lversion = ([xml](Get-Content .\Lagrange.Proto.Generator\Lagrange.Proto.Generator.csproj)).Project.PropertyGroup.Version
22-
echo "Local version: $lversion"
23-
24-
try {
25-
$response = Invoke-WebRequest -Uri "https://api.nuget.org/v3-flatcontainer/lagrange.proto.generator/index.json"
26-
} catch {
27-
if ($_.Exception.Response.StatusCode.value__ -eq 404) {
28-
echo "No remote version"
29-
echo "continued=true" >> $env:GITHUB_ENV
30-
exit 0
31-
} else {
32-
throw
33-
}
34-
}
35-
36-
$rversions = ($response.Content | ConvertFrom-Json).versions
37-
echo "Remote version: $rversions"
38-
if ($lversion -in $rversions) {
39-
echo "Version($lversion) already exists"
40-
echo "continued=false" >> $env:GITHUB_ENV
41-
exit 0
42-
}
17+
- id: nuget-login
18+
uses: NuGet/login@v1
19+
with:
20+
user: Linwenxuan04
4321

44-
echo "Version($lversion) does not exist"
45-
echo "continued=true" >> $env:GITHUB_ENV
46-
exit 0
22+
- uses: actions/checkout@v4
4723

48-
- if: env.continued == 'true'
49-
uses: actions/setup-dotnet@v4
24+
- uses: actions/setup-dotnet@v4
5025
with:
5126
dotnet-version: '10'
5227

53-
- if: env.continued == 'true'
54-
run: dotnet pack -c Release -p:IncludeSymbols=true -p:SymbolPackageFormat=snupkg Lagrange.Proto.Generator
28+
- run: dotnet pack -c Release -p:IncludeSymbols=true -p:SymbolPackageFormat=snupkg Lagrange.Proto.Generator
5529

56-
- if: env.continued == 'true'
57-
run: dotnet nuget push ./Lagrange.Proto.Generator/bin/Release/*.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_TOKEN }}
30+
- run: dotnet nuget push ./Lagrange.Proto.Generator/bin/Release/*.nupkg --source https://api.nuget.org/v3/index.json --skip-duplicate --api-key ${{ steps.nuget-login.outputs.NUGET_API_KEY }}

.github/workflows/nuget-push-lagrange-proto.yaml

Lines changed: 9 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
push:
55
branches:
66
- main
7+
- master
78
paths:
89
- "Lagrange.Proto/Lagrange.Proto.csproj"
910
workflow_dispatch:
@@ -13,45 +14,17 @@ jobs:
1314
runs-on: ubuntu-latest
1415

1516
steps:
16-
- uses: actions/checkout@v4
17-
18-
# Check Version
19-
- shell: pwsh
20-
run: |
21-
$lversion = ([xml](Get-Content .\Lagrange.Proto\Lagrange.Proto.csproj)).Project.PropertyGroup.Version
22-
echo "Local version: $lversion"
23-
24-
try {
25-
$response = Invoke-WebRequest -Uri "https://api.nuget.org/v3-flatcontainer/lagrange.proto/index.json"
26-
} catch {
27-
if ($_.Exception.Response.StatusCode.value__ -eq 404) {
28-
echo "No remote version"
29-
echo "continued=true" >> $env:GITHUB_ENV
30-
exit 0
31-
} else {
32-
throw
33-
}
34-
}
35-
36-
$rversions = ($response.Content | ConvertFrom-Json).versions
37-
echo "Remote version: $rversions"
38-
if ($lversion -in $rversions) {
39-
echo "Version($lversion) already exists"
40-
echo "continued=false" >> $env:GITHUB_ENV
41-
exit 0
42-
}
17+
- id: nuget-login
18+
uses: NuGet/login@v1
19+
with:
20+
user: Linwenxuan04
4321

44-
echo "Version($lversion) does not exist"
45-
echo "continued=true" >> $env:GITHUB_ENV
46-
exit 0
22+
- uses: actions/checkout@v4
4723

48-
- if: env.continued == 'true'
49-
uses: actions/setup-dotnet@v4
24+
- uses: actions/setup-dotnet@v4
5025
with:
5126
dotnet-version: '10'
5227

53-
- if: env.continued == 'true'
54-
run: dotnet pack -c Release -p:IncludeSymbols=true -p:SymbolPackageFormat=snupkg Lagrange.Proto
28+
- run: dotnet pack -c Release -p:IncludeSymbols=true -p:SymbolPackageFormat=snupkg Lagrange.Proto
5529

56-
- if: env.continued == 'true'
57-
run: dotnet nuget push ./Lagrange.Proto/bin/Release/*.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_TOKEN }}
30+
- run: dotnet nuget push ./Lagrange.Proto/bin/Release/*.nupkg --source https://api.nuget.org/v3/index.json --skip-duplicate --api-key ${{ steps.nuget-login.outputs.NUGET_API_KEY }}

0 commit comments

Comments
 (0)