Skip to content
This repository has been archived by the owner on May 31, 2024. It is now read-only.

Workflow file for this run

name: Publish NuGet Package on Release
on:
release:
types: [published]
workflow_dispatch: # Erlaubt manuelles Auslösen des Workflows über die GitHub-Oberfläche
env:
CSPROJ_FILE: Templates.csproj
DOTNET_VERSION: '8.0.x'
jobs:
get_release:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Get latest release
id: get_release
run: |
RELEASE_JSON=$(gh release view --json tagName,name,url)
RELEASE_TAG_NAME=$(echo "$RELEASE_JSON" | jq -r '.tagName')
RELEASE_NAME=$(echo "$RELEASE_JSON" | jq -r '.name')
RELEASE_URL=$(echo "$RELEASE_JSON" | jq -r '.url')
RELEASE_VERSION="${RELEASE_TAG_NAME#"v"}"
echo "release_version=$RELEASE_VERSION" >> "$GITHUB_OUTPUT"
echo "release_tag_name=$RELEASE_TAG_NAME" >> "$GITHUB_OUTPUT"
echo "release_url=$RELEASE_URL" >> "$GITHUB_OUTPUT"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
outputs:
release_version: ${{ steps.get_release.outputs.release_version }}
release_tag_name: ${{ steps.get_release.outputs.release_tag_name }}
release_url: ${{ steps.get_release.outputs.release_url }}
build_and_publish:
needs: get_release
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Restore dependencies
run: dotnet restore ${{ env.CSPROJ_FILE }}
- name: Build
run: dotnet build ${{ env.CSPROJ_FILE }} --no-restore --configuration Release
# Packen des Projekts in ein NuGet-Paket
# Hinweis: Kein Symbolpaket da es sich um ein Template-Projekt handelt.
- name: Pack
run: |
echo "Using version ${{ needs.get_release.outputs.release_version }} from setup job."
dotnet pack ${{ env.CSPROJ_FILE }} --no-build --configuration Release \
-p:PackageVersion=${{ needs.get_release.outputs.release_version }} \
-p:PackageReleaseNotes=${{ needs.get_release.outputs.release_url }} \
-p:PackageProjectUrl="https://github.com/${{ github.repository }}" \
-p:RepositoryUrl="https://github.com/${{ github.repository }}.git" \
-p:RepositoryType="git" \
-o nupkg
shell: bash
- name: List output files
run: |
echo "Listing built packages in nupkg directory:"
ls nupkg/
shell: bash
- name: Push NuGet Package
run: |
cd nupkg
dotnet nuget push "*.nupkg" --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate
shell: pwsh
- name: Push to GitHub Packages
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
cd nupkg
dotnet nuget push "*.nupkg" --api-key $env:GITHUB_TOKEN --source "https://nuget.pkg.github.com/${{ github.repository_owner }}" --skip-duplicate
shell: pwsh