Skip to content

feat: add github workflow #1

feat: add github workflow

feat: add github workflow #1

Workflow file for this run

name: Build and Publish to NuGet
on:
push:
branches: [ master, main ]
paths:
- 'src/Base58Encoding/**'
- '!src/Base58Encoding.Tests/**'
- '!src/Base58Encoding.Benchmarks/**'
tags:
- 'v*.*.*'
pull_request:
branches: [ master, main ]
paths:
- 'src/Base58Encoding/**'
- '!src/Base58Encoding.Tests/**'
- '!src/Base58Encoding.Benchmarks/**'
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Get version from tag
if: startsWith(github.ref, 'refs/tags/v')
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 9.0.x
- name: Restore dependencies
run: dotnet restore src/Base58Encoding/Base58Encoding.csproj
- name: Build
run: dotnet build src/Base58Encoding/Base58Encoding.csproj --configuration Release --no-restore
- name: Test
run: dotnet test src/Base58Encoding.Tests/Base58Encoding.Tests.csproj --configuration Release --no-build --verbosity normal
- name: Pack (with version from tag)
if: startsWith(github.ref, 'refs/tags/v')
run: dotnet pack src/Base58Encoding/Base58Encoding.csproj --configuration Release --no-build --output ./artifacts -p:PackageVersion=${{ env.VERSION }}
- name: Pack (without version)
if: "!startsWith(github.ref, 'refs/tags/v')"
run: dotnet pack src/Base58Encoding/Base58Encoding.csproj --configuration Release --no-build --output ./artifacts
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: nupkg
path: ./artifacts/*.nupkg
publish:
needs: build
runs-on: ubuntu-latest
# Only publish on version tags
if: startsWith(github.ref, 'refs/tags/v')
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: nupkg
path: ./artifacts
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 9.0.x
- name: Publish to NuGet
run: dotnet nuget push ./artifacts/*.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_API_KEY }} --skip-duplicate
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
files: ./artifacts/*.nupkg
generate_release_notes: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}