Skip to content

- fix gh actions

- fix gh actions #19

Workflow file for this run

name: Release (Stable)
on:
push:
branches: [ main, master ]
workflow_dispatch:
permissions:
contents: write
packages: write
jobs:
release:
runs-on: ubuntu-latest
env:
working-directory: ${{ github.workspace }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 9.0.x
- name: Install GitVersion
uses: gittools/actions/gitversion/setup@v0.9.15
with:
versionSpec: 5.x
- name: Determine Version
id: gitversion
uses: gittools/actions/gitversion/execute@v0.9.15
with:
useConfigFile: true
- name: Display Version
run: |
echo "FullSemVer: ${{ steps.gitversion.outputs.FullSemVer }}"
echo "NuGetVersionV2: ${{ steps.gitversion.outputs.NuGetVersionV2 }}"
echo "IsPreRelease? ${{ steps.gitversion.outputs.PreReleaseTag != '' }}"
- name: Fail if Pre-release on main
if: ${{ steps.gitversion.outputs.PreReleaseTag != '' }}
run: |
echo "Unexpected pre-release on main. Check GitVersion config."
exit 1
- name: Restore
run: dotnet restore
working-directory: '${{ env.working-directory }}'
- name: Build
run: dotnet build -c Release --no-restore
working-directory: '${{ env.working-directory }}'
- name: Test
run: dotnet test -c Release --no-build
working-directory: '${{ env.working-directory }}'
- name: Pack Stable
run: |
dotnet pack src/MyLibrary/MyLibrary.csproj \
-c Release -o artifacts \
/p:PackageVersion=${{ steps.gitversion.outputs.NuGetVersionV2 }}
- name: Create Tag (if missing)
run: |
TAG="v${{ steps.gitversion.outputs.MajorMinorPatch }}"
if git rev-parse "$TAG" >/dev/null 2>&1; then
echo "Tag $TAG already exists."
else
git tag "$TAG"
git push origin "$TAG"
fi
- name: Add GitHub Packages Source
run: |
dotnet nuget add source \
--username $GITHUB_ACTOR \
--password ${{ secrets.GITHUB_TOKEN }} \
--store-password-in-clear-text \
--name github "https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json"
- name: Publish to GitHub Packages
run: dotnet nuget push "artifacts/*.nupkg" --api-key ${{ secrets.GITHUB_TOKEN }} --source "github" --skip-duplicate
- name: Publish to NuGet
if: ${{ startsWith(github.head_ref, 'release/')}}
env:
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
run: |
dotnet nuget push "artifacts/*.nupkg" \
--api-key "$NUGET_API_KEY" \
--source https://api.nuget.org/v3/index.json \
--skip-duplicate