Skip to content

optimize workflow

optimize workflow #4

Workflow file for this run

name: Build and Deploy
on:
push:
paths:
- 'src/**'
- '.github/workflows/**'
branches: [ main ]
pull_request:
paths:
- 'src/**'
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 9.0.x
- name: Cache NuGet packages
uses: actions/cache@v3
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}
restore-keys: |
${{ runner.os }}-nuget-
- name: Restore dependencies
run: dotnet restore ./src
- name: Build
run: dotnet build ./src --configuration Release --no-restore
pack-and-push:
runs-on: ubuntu-latest
needs: build
if: github.event_name != 'pull_request'
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 9.0.x
- name: Build and pack NuGet package
run: |
dotnet pack ./src/Nager.KeyValueParser/Nager.KeyValueParser.csproj \
--configuration Release \
--output $GITHUB_WORKSPACE/out
- name: Push NuGet package
run: |
dotnet nuget push $GITHUB_WORKSPACE/out/*.nupkg \
--source https://api.nuget.org/v3/index.json \
--api-key ${{ secrets.NUGET_TOKEN }} \
--skip-duplicate