Build and Publish NuGet Package #28
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Publish NuGet Package | |
on: | |
release: | |
types: [published] | |
jobs: | |
build-and-publish: | |
runs-on: ubuntu-latest | |
permissions: | |
packages: write | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- uses: actions/cache@v4 | |
name: Setup Cache | |
id: cache-setup | |
with: | |
path: | | |
~/.nuget/packages | |
~/.dotnet | |
key: ${{ runner.os }}-${{ github.ref_name }} | |
restore-keys: | | |
${{ runner.os }}- | |
- name: Setup .NET | |
uses: actions/setup-dotnet@v3 | |
with: | |
dotnet-version: '8.x' | |
- name: Install dependencies | |
run: dotnet restore Source/Silverfly/Silverfly.csproj | |
- name: Get release version | |
id: get_release | |
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV | |
- name: Update .csproj file | |
run: | | |
RELEASE_VERSION=$(echo ${{ env.RELEASE_VERSION }}) | |
sed -i "s/<Version>.*<\/Version>/<Version>${RELEASE_VERSION}<\/Version>/" Source/Silverfly/Silverfly.csproj | |
sed -i "s/<Version>.*<\/Version>/<Version>${RELEASE_VERSION}<\/Version>/" Source/Silverfly.Testing/Silverfly.Testing.csproj | |
- name: Commit and push changes | |
run: | | |
git config --global user.name "github-actions[bot]" | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
git add Source/Silverfly/Silverfly.csproj | |
git add Source/Silverfly.Testing/Silverfly.Testing.csproj | |
git commit -m "Update version to ${{ env.RELEASE_VERSION }}" | |
git push HEAD:main | |
- name: Build and package | |
run: | | |
dotnet build -c Release Source/Silverfly/Silverfly.csproj | |
dotnet pack -c Release -o ./nuget Source/Silverfly/Silverfly.csproj | |
dotnet build -c Release Source/Silverfly.Testing/Silverfly.Testing.csproj | |
dotnet pack -c Release -o ./nuget Source/Silverfly.Testing/Silverfly.Testing.csproj | |
- name: Publish to NuGet | |
uses: actions/upload-artifact@v4 | |
with: | |
name: nuget-package | |
path: ./nuget/*.nupkg | |
- name: Publish package To Nuget | |
run: | | |
dotnet nuget push ./nuget/*.nupkg --api-key "${{ secrets.NUGET_APIKEY }}" --source https://api.nuget.org/v3/index.json --skip-duplicate |