Build and Publish NuGet Package #35
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 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
steps: | |
- name: Checkout code | |
run: | | |
git checkout -b main --track origin/main | |
- 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 changes | |
uses: EndBug/add-and-commit@v9 | |
with: | |
author_name: github-actions[bot] | |
author_email: github-actions[bot]@users.noreply.github.com | |
message: "Update version to ${{ env.RELEASE_VERSION }}" | |
add: '["Source/Silverfly/Silverfly.csproj", "Source/Silverfly.Testing/Silverfly.Testing.csproj"]' | |
- name: Create Pull Request | |
uses: peter-evans/create-pull-request@v5 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
branch: update-version | |
base: main | |
title: "Update version to ${{ env.RELEASE_VERSION }}" | |
body: "This PR updates the .csproj files to version ${{ env.RELEASE_VERSION }}." | |
- 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 |