Skip to content

permissions

permissions #14

Workflow file for this run

# This workflow will build a .NET project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net
name: .NET
on:
push:
branches:
- main
pull_request:
branches:
- main
release:
types:
- published
jobs:
build:
name: .NET
runs-on: ubuntu-latest
env:
NUGET_PACKAGES: ${{ github.workspace }}/.nuget/packages
OUTPUT_PATH: output
NUGETPROJ: Directory.Build.props
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup .NET
uses: actions/setup-dotnet@v4
- name: Cache NuGet
uses: actions/cache@v4
with:
path: ${{ github.workspace }}/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('Directory.Packages.props') }} #hash of project files
restore-keys: ${{ runner.os }}-nuget-
- name: Bump revision
id: bump
if: github.event_name == 'push'
uses: vers-one/[email protected]
with:
file: ${{ env.NUGETPROJ }}
version: bump-revision
tags: props.Version, props.FileVersion
- name: Describe
id: describe
if: github.event_name == 'push'
shell: pwsh
run: echo "InfoVersion=$($(git describe --tags --long) -replace $(git describe --tags --abbrev=0),'${{ steps.bump.outputs.newVersion }}')" >> $env:GITHUB_OUTPUT
- name: Set Version
if: github.event_name == 'push'
uses: vers-one/[email protected]
with:
file: ${{ env.NUGETPROJ }}
version: ${{ steps.describe.outputs.InfoVersion }}
tags: props.Version
- name: Restore dependencies
run: dotnet restore
- name: Build (Debug)
run: dotnet build --no-restore
- name: Test (Debug)
run: dotnet test --no-build --verbosity normal
- name: Build (Release)
run: dotnet build --configuration Release --no-restore
- name: Pack (Release)
run: dotnet pack --configuration Release --no-build --output ${{ env.OUTPUT_PATH }}
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ github.event.repository.name }}.nupkg
path: ${{ env.OUTPUT_PATH }}/*.*nupkg
publish-gpr:
name: Publish to GitHub Packages Registry
if: github.event_name == 'push'
needs: build
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
source-url: https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json
env:
NUGET_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Download Package artifact
uses: actions/download-artifact@v4
with:
name: ${{ github.event.repository.name }}.nupkg
- name: Publish to GitHub Package Registry
run: 'dotnet nuget push "*.nupkg" --skip-duplicate'
publish-nuget:
name: Publish to NuGet
if: github.event_name == 'release'
needs: build
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
- name: Download Package artifact
uses: actions/download-artifact@v4
with:
name: ${{ github.event.repository.name }}.nupkg
- name: Upload Release Assets
uses: softprops/action-gh-release@v2
with:
files: "*.nupkg"
- name: Publish to Nuget
run: 'dotnet nuget push "*.nupkg" -s https://api.nuget.org/v3/index.json -k ${{ secrets.NUGET_KEY }} --skip-duplicate'