Upload NuGet packages as artifacts #17
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: CI/CD with Auto Versioning | |
on: | |
push: | |
branches: [ master ] | |
pull_request: | |
branches: [ master ] | |
jobs: | |
versioning: | |
runs-on: ubuntu-latest | |
outputs: | |
version: ${{ steps.set_version.outputs.new_version }} | |
steps: | |
- uses: actions/checkout@v4.1.2 | |
with: | |
fetch-depth: 0 # Important for fetching all tags and history | |
- name: Bump version and push tag | |
id: set_version | |
uses: mathieudutour/github-tag-action@v6.2 | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
default_bump: patch # Automatically bump patch version | |
release_branches: master | |
create_annotated_tag: true | |
build: | |
needs: versioning | |
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.versioning.outputs.version }} | |
- name: Upload NuGet packages as artifacts | |
uses: actions/upload-artifact@v3 | |
with: | |
name: nuget-packages | |
path: nupkg/*.nupkg | |
publish: | |
needs: build | |
runs-on: ubuntu-latest | |
steps: | |
- name: Download NuGet packages artifacts | |
uses: actions/download-artifact@v3 | |
with: | |
name: nuget-packages | |
path: nupkg | |
- name: Push to NuGet | |
run: dotnet nuget push "**/*.nupkg" -k ${{secrets.NUGET_API_KEY}} -s https://api.nuget.org/v3/index.json --skip-duplicate |