Skip to content

Workflow file for this run

name: Build and Publish NuGet Package
on:
release:
types: [published]
jobs:
build-and-publish:
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checkout code
uses: actions/[email protected]
with:
fetch-depth: 0
ref: main
- name: Set default branch.
run: |
git fetch origin
git remote set-head origin --auto
- name: Prepare repository
run: git checkout main
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: '8.x'
- 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
sed -i "s/<Version>.*<\/Version>/<Version>${RELEASE_VERSION}<\/Version>/" Source/Silverfly.Generator/Silverfly.Generator.csproj
sed -i "s/<Version>.*<\/Version>/<Version>${RELEASE_VERSION}<\/Version>/" Source/Silverfly.Repl/Silverfly.Repl.csproj
sed -i "s/<Version>.*<\/Version>/<Version>${RELEASE_VERSION}<\/Version>/" Source/Silverfly.TreeVisualizer/Silverfly.TreeVisualizer.csproj
sed -i "s/<Version>.*<\/Version>/<Version>${RELEASE_VERSION}<\/Version>/" Source/Silverfly.Backend/Silverfly.Backend.csproj
- name: GIT commit and push overriding conflicts with local changes (verbose)
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add Source/*.csproj
git commit -m "Update version to ${{ env.RELEASE_VERSION }}"
git fetch origin
git rebase --strategy-option=theirs origin/main
git push
- name: Build and package
run: |
dotnet build -c Release -o ./nuget Source/Silverfly/Silverfly.csproj
dotnet build -c Release -o ./nuget Source/Silverfly.Testing/Silverfly.Testing.csproj
dotnet build -c Release -o ./nuget Source/Silverfly.Repl/Silverfly.Repl.csproj
dotnet build -c Release -o ./nuget Source/Silverfly.TreeVisualizer/Silverfly.TreeVisualizer.csproj
dotnet build -c Release -o ./nuget Source/Silverfly.Backend/Silverfly.Backend.csproj
dotnet build -c Release -o ./nuget Source/Samples/Sample.FuncLanguage/Sample.FuncLanguage.csproj
dotnet build -o ./nuget Source/Silverfly.Generator/Silverfly.Generator.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