skarpdev / dotnet-version-cli

dotnet version cli (similar to npm version cli)
MIT License
38 stars 12 forks source link

Update documentation for use in GitHub actions (or Azure pipelines) #90

Open FrankMuehlschlegel opened 2 years ago

FrankMuehlschlegel commented 2 years ago

Thank you for this awesome tool. It took me quite a little while to figure out the following little details.

1) Escaping $ in yaml files because it is already used by the github actions (or Azure pipelines)

dotnet version patch -m "Auto increment version to v\$newVer by CI/CD pipeline" 

2) Configure git properly before using your tool in a pipeline

git config --local user.email "your@email.com"
git config --local user.name "Your Name" 

Here is my full example script for github pipelines

name: CI/CD
env:
  DOTNET_VERSION_BACKEND: "3.1.x"

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  full:
    name: Build And Publish nuget
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - name: Setup Dotnet ${{ env.DOTNET_VERSION }}
        uses: actions/setup-dotnet@v1
        with:
            dotnet-version: ${{ env.DOTNET_VERSION }}    

      - name: Setup Tool for Version
        run: dotnet tool install -g dotnet-version-cli

      - name: Build
        run: dotnet build --configuration Release

      - name: Git config
        run: |
            git config --local user.email "your@email.com"
            git config --local user.name "Your Name"         

      - name: Increment version
        run: dotnet version -m "Auto increment version to v\$newVer by CI/CD pipeline" patch

      - name: Pack & push nuget
        run: |
            dotnet pack --configuration Release --no-build --no-restore
            dotnet nuget push bin/Release/*.nupkg --skip-duplicate --api-key ${{secrets.NUGET_API_KEY}} --source https://api.nuget.org/v3/index.json

      - name: Git push changes back to repo
        run: |
            git push
            git push --tags
nover commented 2 years ago

@FluentChange thanks for this. I'll make an update, or, feel free to submit a PR with the documentation.