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'
- 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 }}-${{ github.ref_name }}
- 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
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
- 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 -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
- name: Deploy to image-data branch
uses: peaceiris/actions-gh-pages@v3
with:
publish_dir: ./output
publish_branch: image-data
github_token: ${{ secrets.GITHUB_TOKEN }}
user_name: 'github-actions[bot]'
user_email: 'github-actions[bot]@users.noreply.github.com'
- 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 }}"
push: true
new_branch: update-version
add: '["Source/Silverfly/Silverfly.csproj", "Source/Silverfly.Testing/Silverfly.Testing.csproj", "Source/Silverfly.Generator/Silverfly.Generator.csproj", "Source/Silverfly.Repl/Silverfly.Repl.csproj"]'