Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions .github/workflows/ci-otapi3-nuget.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,40 @@
name: Deploy NuGet(OTAPI3)
name: Publish NuGet

on:
push:
branches: [ nuget-release ]
release:
types: [published]

jobs:
build:

publish:
runs-on: ubuntu-latest
environment: release

steps:
- uses: actions/checkout@v4
with:
submodules: 'recursive'

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 9.0.x

- name: Check csproj version matches release tag
run: |
CSPROJ_VERSION=$(grep -oP '(?<=<Version>)[^<]+' TShockAPI/TShockAPI.csproj)
TAG_VERSION=${GITHUB_REF_NAME#v}
if [ "$CSPROJ_VERSION" != "$TAG_VERSION" ]; then
echo "::warning::<Version> in TShockAPI.csproj is $CSPROJ_VERSION but the release tag is $TAG_VERSION. The NuGet package will use $TAG_VERSION. Consider updating the csproj to match."
fi
- name: Restore dependencies
run: dotnet restore

- name: Build
run: dotnet build TShock.sln --configuration Release --no-restore
run: dotnet build TShock.sln --configuration Release --no-restore -p:PackageVersion=${GITHUB_REF_NAME#v}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unquoted variable expansion in build command

The ${GITHUB_REF_NAME#v} expansion is not quoted. If a release tag ever contains spaces or other special shell characters (e.g., v5.9.9 beta1), the unquoted expansion would result in word splitting — beta1 would be passed as a separate argument to dotnet build, causing the command to fail with an unexpected argument error.

While GitHub release tags with spaces are atypical, quoting the parameter is a defensive best practice:

Suggested change
run: dotnet build TShock.sln --configuration Release --no-restore -p:PackageVersion=${GITHUB_REF_NAME#v}
run: dotnet build TShock.sln --configuration Release --no-restore "-p:PackageVersion=${GITHUB_REF_NAME#v}"


- name: Test
run: dotnet test --no-build --verbosity normal --configuration Release

# Publish to nuget
- name: Push TShockAPI
run: dotnet nuget push TShockAPI/bin/Release/*.nupkg -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json
- name: Push to NuGet
run: dotnet nuget push TShockAPI/bin/Release/*.nupkg -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json --skip-duplicate
4 changes: 3 additions & 1 deletion TShockAPI/TShockAPI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
location, which previously held the date and time.

Also, be sure to release on github with the exact assembly version tag as below
so that the update manager works correctly (via the Github releases api and mimic)
so that the update manager works correctly (via the Github releases api and mimic).
Otherwise the Nuget package will have a version mismatch with the version here.
Prerelease upgrades should not update this version—only do so for the full release.
-->
<Version>5.9.9</Version>
<AssemblyTitle>TShock for Terraria</AssemblyTitle>
Expand Down
Loading