This repository has been archived by the owner on May 31, 2024. It is now read-only.
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Publish NuGet Package on Release | |
on: | |
release: | |
types: [published, prereleased] | |
workflow_dispatch: # Erlaubt manuelles Auslösen des Workflows über die GitHub-Oberfläche | |
permissions: | |
contents: write | |
packages: write | |
pull-requests: read | |
env: | |
CSPROJ_FILE: Templates.csproj | |
DOTNET_VERSION: '8.0.x' | |
jobs: | |
get_release_or_prerelease: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Get latest release or prerelease | |
id: get_release_or_prerelease | |
run: | | |
RELEASES_JSON=$(gh release list --json tagName,name,isPrerelease --exclude-drafts) | |
LATEST_RELEASE_OR_PRERELEASE_JSON=$(echo "$RELEASES_JSON" | jq -r '.[0]') | |
RELEASE_TAG_NAME=$(echo "$LATEST_RELEASE_OR_PRERELEASE_JSON" | jq -r '.tagName') | |
RELEASE_NAME=$(echo "$LATEST_RELEASE_OR_PRERELEASE_JSON" | jq -r '.name') | |
RELEASE_IS_PRERELEASE=$(echo "$LATEST_RELEASE_OR_PRERELEASE_JSON" | jq -r '.isPrerelease') | |
RELEASE_VERSION="${RELEASE_TAG_NAME#"v"}" | |
REPO_URL="https://github.com/${GITHUB_REPOSITORY}" | |
RELEASE_URL="${REPO_URL}/releases/tag/${RELEASE_TAG_NAME}" | |
echo "release_version=$RELEASE_VERSION" >> "$GITHUB_OUTPUT" | |
echo "release_tag_name=$RELEASE_TAG_NAME" >> "$GITHUB_OUTPUT" | |
echo "release_url=$RELEASE_URL" >> "$GITHUB_OUTPUT" | |
echo "release_is_prerelease=$RELEASE_IS_PRERELEASE" >> "$GITHUB_OUTPUT" | |
echo "Found latest $(if [ "$RELEASE_IS_PRERELEASE" = "true" ]; then echo "prerelease"; else echo "release"; fi): $RELEASE_TAG_NAME" | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
outputs: | |
release_version: ${{ steps.get_release_or_prerelease.outputs.release_version }} | |
release_tag_name: ${{ steps.get_release_or_prerelease.outputs.release_tag_name }} | |
release_url: ${{ steps.get_release_or_prerelease.outputs.release_url }} | |
release_is_prerelease: ${{ steps.get_release_or_prerelease.outputs.release_is_prerelease }} | |
build_and_publish: | |
needs: get_release_or_prerelease | |
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_or_prerelease.outputs.release_version }} from setup job." | |
dotnet pack ${{ env.CSPROJ_FILE }} --no-build --configuration Release \ | |
-p:PackageVersion=${{ needs.get_release_or_prerelease.outputs.release_version }} \ | |
-p:PackageReleaseNotes=${{ needs.get_release_or_prerelease.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 |