Skip to content

Feature/added example to readme.md; option to suppress update message… #58

Feature/added example to readme.md; option to suppress update message…

Feature/added example to readme.md; option to suppress update message… #58

name: Build, Test, and Publish NuGet Package
on:
push:
branches:
- main
tags:
- 'v*.*.*' # Ensure that NuGet publishing is triggered on version tags like v1.0.0
permissions:
contents: write
packages: write
jobs:
build_and_test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup .NET Core
uses: actions/setup-dotnet@v3
with:
dotnet-version: '8.x'
- name: Set API Key Environment Variable
run: echo "SOLCAST_API_KEY=${{ secrets.SOLCAST_API_KEY }}" >> $GITHUB_ENV
- name: Restore dependencies
run: dotnet restore
- name: Run tests
run: dotnet test
package_and_publish:
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
needs: build_and_test
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup .NET Core
uses: actions/setup-dotnet@v3
with:
dotnet-version: '8.x'
- name: Copy README.md to the project folder
run: cp README.md src/Solcast/README.md
- name: Restore dependencies
run: dotnet restore src/Solcast/Solcast.csproj
- name: Extract version from Git tag
run: |
CLEAN_VERSION="${GITHUB_REF##*/}" # Remove 'refs/tags/'
CLEAN_VERSION="${CLEAN_VERSION#v}" # Remove leading 'v'
NUMERIC_VERSION=$(echo "$CLEAN_VERSION" | sed 's/[^0-9.].*//') # Strip any suffix for AssemblyVersion
echo "CLEAN_VERSION=$CLEAN_VERSION" >> $GITHUB_ENV
echo "NUMERIC_VERSION=$NUMERIC_VERSION" >> $GITHUB_ENV
- name: Pack NuGet Package with version from tag
run: |
dotnet pack src/Solcast/Solcast.csproj --configuration Release --output ./nupkg \
/p:Version=${{ env.CLEAN_VERSION }} \
/p:AssemblyVersion=${{ env.NUMERIC_VERSION }} \
/p:FileVersion=${{ env.NUMERIC_VERSION }} \
/p:InformationalVersion=${{ env.CLEAN_VERSION }}
- name: Publish NuGet Package to GitHub Packages
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: dotnet nuget push ./nupkg/*.nupkg --source "https://nuget.pkg.github.com/solcast/index.json" --api-key ${{ secrets.GITHUB_TOKEN }}
- name: Publish NuGet Package to NuGet.org
env:
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
run: dotnet nuget push ./nupkg/*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json