Skip to content

fix: resolve NuGet dogfooding issues (0.3.0) #12

fix: resolve NuGet dogfooding issues (0.3.0)

fix: resolve NuGet dogfooding issues (0.3.0) #12

Workflow file for this run

name: Build, Test, and Publish NuGet Package
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
build-and-publish:
runs-on: ubuntu-latest
permissions:
contents: write # 릴리스 태그 push용
id-token: write # Trusted Publishing용 GitHub OIDC 토큰 발급 허용
steps:
- name: Checkout repository
uses: actions/checkout@v7
- name: Setup .NET
uses: actions/setup-dotnet@v5
with:
dotnet-version: '8.0.x'
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --configuration Release --no-restore
- name: Test
run: dotnet test --configuration Release --no-build --verbosity normal
- name: Pack
run: dotnet pack --configuration Release --no-build --output ./nupkg
# Trusted Publishing: OIDC 토큰을 1시간짜리 임시 API 키로 교환
# (nuget.org -> 계정 -> Trusted Publishing 정책 등록 필요)
- name: NuGet login (OIDC -> temp API key)
if: github.ref == 'refs/heads/main'
uses: NuGet/login@v1
id: login
with:
user: JaejoonHan # nuget.org 프로필명
- name: Publish to NuGet
if: github.ref == 'refs/heads/main' # main 브랜치에서만 배포
run: dotnet nuget push ./nupkg/*.nupkg --api-key ${{ steps.login.outputs.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate
# 배포된 버전에 릴리스 태그(v<버전>)를 자동으로 push (이미 있으면 스킵)
- name: Tag release
if: github.ref == 'refs/heads/main'
run: |
VERSION=$(grep -oPm1 '(?<=<Version>)[^<]+' src/OpenGJKSharp/OpenGJKSharp.csproj)
if [ -z "$VERSION" ]; then
echo "Version not found in csproj"; exit 1
fi
if git ls-remote --tags origin "refs/tags/v$VERSION" | grep -q .; then
echo "Tag v$VERSION already exists, skipping"
else
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag -a "v$VERSION" -m "Release v$VERSION"
git push origin "v$VERSION"
fi