Skip to content

Commit 0e2bcc3

Browse files
authored
Merge pull request #503 from dadhi/copilot/fix-publishing-to-github-feed
Fix publish workflow: use nuget pack for .nuspec files and push to GitHub Packages
2 parents 6c8479a + 5b97d12 commit 0e2bcc3

1 file changed

Lines changed: 45 additions & 12 deletions

File tree

.github/workflows/publish.yml

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,30 @@
11
name: Publish
22

3+
# Triggered automatically when a tag matching "v*.*.*" is pushed, e.g. `git tag v5.4.1 && git push --tags`
4+
35
on:
46
push:
57
tags:
68
- "v*.*.*"
79

10+
# Required secrets / permissions:
11+
#
12+
# 1. secrets.GITHUB_TOKEN — automatically injected by GitHub Actions for every run; no setup required.
13+
# It is used to authenticate pushes to GitHub Packages (https://nuget.pkg.github.com/dadhi/index.json).
14+
# The token only needs `packages: write` permission, which is already granted to GITHUB_TOKEN by default
15+
# for public repos. If you ever restrict default permissions, add:
16+
# permissions:
17+
# packages: write
18+
# at the job level.
19+
#
20+
# 2. secrets.NUGET_API_KEY — a personal API key for https://www.nuget.org.
21+
# How to obtain and store it:
22+
# a. Log in to https://www.nuget.org → account menu → "API Keys" → "Create".
23+
# b. Set the key scope to "Push" and select the relevant package IDs (or use a glob).
24+
# c. Copy the generated key.
25+
# d. In this GitHub repo go to Settings → Secrets and variables → Actions → "New repository secret".
26+
# e. Name it exactly NUGET_API_KEY and paste the key as the value.
27+
828
jobs:
929
build:
1030
runs-on: ubuntu-latest
@@ -19,29 +39,42 @@ jobs:
1939
with:
2040
global-json-file: global.json
2141

42+
# The classic NuGet CLI is required because .nuspec files are not supported by `dotnet pack`.
43+
- name: Install NuGet CLI
44+
run: sudo apt-get install -y nuget
45+
2246
- name: Build
2347
run: dotnet build -c:Release
2448

2549
- name: Make Internal
2650
shell: pwsh
2751
run: ./BuildScripts/MakeInternal.ps1
2852

29-
- name: Pack with dotnet
53+
- name: Pack
3054
run: |
31-
arrTag=(${GITHUB_REF//\// })
32-
VERSION="${arrTag[2]}"
33-
VERSION="${VERSION//v}"
34-
echo "$VERSION"
35-
36-
dotnet pack --no-build --output artifacts -p:Version=$VERSION -p:ContinuousIntegrationBuild=True ./nuspecs/FastExpressionCompiler.src.nuspec
37-
dotnet pack --no-build --output artifacts -p:Version=$VERSION -p:ContinuousIntegrationBuild=True ./nuspecs/FastExpressionCompiler.LightExpression.src.nuspec
38-
dotnet pack --no-build --output artifacts -p:Version=$VERSION -p:ContinuousIntegrationBuild=True ./nuspecs/FastExpressionCompiler.Internal.src.nuspec
39-
dotnet pack --no-build --output artifacts -p:Version=$VERSION -p:ContinuousIntegrationBuild=True ./nuspecs/FastExpressionCompiler.LightExpression.Internal.src.nuspec
55+
# GITHUB_REF_NAME is the tag name, e.g. "v5.4.1"; strip the leading "v" to get the NuGet version.
56+
VERSION="${GITHUB_REF_NAME#v}"
57+
echo "Packing version: $VERSION"
58+
mkdir -p artifacts
59+
nuget pack ./nuspecs/FastExpressionCompiler.src.nuspec -OutputDirectory artifacts -Version $VERSION -NonInteractive
60+
nuget pack ./nuspecs/FastExpressionCompiler.LightExpression.src.nuspec -OutputDirectory artifacts -Version $VERSION -NonInteractive
61+
nuget pack ./nuspecs/FastExpressionCompiler.Internal.src.nuspec -OutputDirectory artifacts -Version $VERSION -NonInteractive
62+
nuget pack ./nuspecs/FastExpressionCompiler.LightExpression.Internal.src.nuspec -OutputDirectory artifacts -Version $VERSION -NonInteractive
4063
4164
- uses: actions/upload-artifact@v4
4265
with:
4366
name: Packages
4467
path: ./artifacts
4568

46-
# - name: Push with dotnet
47-
# run: dotnet nuget push artifacts/*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json
69+
# Pushes to the GitHub Packages NuGet feed for this repository.
70+
# GITHUB_TOKEN is provided automatically — no manual secret setup needed.
71+
# --store-password-in-clear-text is required on Linux because the system credential store is unavailable;
72+
# it is safe here because GitHub Actions runners are ephemeral and credentials are never persisted.
73+
- name: Push to GitHub Packages
74+
run: |
75+
dotnet nuget add source --username dadhi --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/dadhi/index.json"
76+
dotnet nuget push artifacts/*.nupkg --source github --skip-duplicate
77+
78+
# Pushes to nuget.org. Requires the NUGET_API_KEY secret (see setup instructions above).
79+
- name: Push to NuGet.org
80+
run: dotnet nuget push artifacts/*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate

0 commit comments

Comments
 (0)