Skip to content

CI/CD with Auto Versioning #54

CI/CD with Auto Versioning

CI/CD with Auto Versioning #54

Workflow file for this run

name: CI/CD with Auto Versioning
on:
workflow_dispatch: # Manual trigger
release:
types: [published] # Trigger on published releases
jobs:
get_version:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.get_version.outputs.version }}
steps:
- uses: actions/checkout@v4.1.2
with:
fetch-depth: 0 # Fetch all history and tags
- name: Debug - List tags
run: git tag -l
- name: Debug - Show commits
run: git log --oneline
- name: Get latest tag
id: get_version
run: |
tag=$(git describe --tags $(git rev-list --tags --max-count=1) 2>/dev/null || echo "v0.0.1")
version=${tag#v} # Remove leading 'v' if present
echo "version=$version" >> $GITHUB_ENV
echo "::set-output name=version::$version"
echo "Resolved version: $version"
build:
needs: get_version
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4.1.2
- name: Setup .NET
uses: actions/setup-dotnet@v4.0.0
with:
dotnet-version: '8.0'
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore -c Release
- name: Test
run: dotnet test --no-build -c Release --verbosity normal
- name: Pack
run: dotnet pack --no-build -c Release -o nupkg /p:PackageVersion=${{ needs.get_version.outputs.version }}
- name: Upload NuGet packages as artifacts
uses: actions/upload-artifact@v4.3.1
with:
name: nuget-packages
path: nupkg/*.nupkg
publish:
needs: build
runs-on: ubuntu-latest
steps:
- name: Download NuGet packages artifacts
uses: actions/download-artifact@v4.1.4
with:
name: nuget-packages
path: nupkg
- name: Push to NuGet.org
run: dotnet nuget push "**/*.nupkg" -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json --skip-duplicate
- name: Push to GitHub Packages
run: dotnet nuget push "**/*.nupkg" -k ${{ secrets.GITHUB_TOKEN }} -s https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json --skip-duplicate