Code Monkey home page Code Monkey logo

dotnetcampus.tagtoversion's Introduction

TagToVersion

The dotnetCampus.TagToVersion that can helps us write tag names into version files is a dotnet tool.

This tool can be used in CI to help us push tag and build the special version of nuget file.

Build NuGet

Install

dotnet tool install -g dotnetCampus.TagToVersion

Usage

The tool can automatically find the Version.props file and write the tag name to version file.

dotnet TagToVersion -t 1.0.2

And We can specialize the version file path.

dontet TagToVersion -t 1.0.2 -f build/Version.props

Principle

The tool will read the command line args and get the tag name. The tool then parses the tag name to version and writes it to the Version.props file. If you send a version file path to the tool, the tool will use your path. And if you send nothing, the tool will find the Version.props file. The default version file path is build\Version.props file.

The tool will write this code to the version file.

<Project>
  <PropertyGroup>
    <Version>1.0.3</Version>
  </PropertyGroup>
</Project>

The version in the code will be replaced with the version that parsed in previous step.

GitHub Action

Pushing a tag to GitHub and then publish the nuget package with this tag version.

The first step:

on:
  push:
    tags:
    - '*' 

The second step:

    - name: Install dotnet tool
      run: dotnet tool install -g dotnetCampus.TagToVersion

    - name: Set tag to version  
      run: dotnet TagToVersion -t ${{ github.ref }}

The thrid step:

# Build and publish

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

    - name: Install Nuget
      uses: nuget/setup-nuget@v1
      with:        
        nuget-version: '5.x'

    - name: Add private GitHub registry to NuGet
      run: |
        nuget sources add -name github -Source https://nuget.pkg.github.com/ORGANIZATION_NAME/index.json -Username ORGANIZATION_NAME -Password ${{ secrets.GITHUB_TOKEN }}
    - name: Push generated package to GitHub registry
      run: |
        nuget push .\bin\release\*.nupkg -Source github -SkipDuplicate
        nuget push .\bin\release\*.nupkg -Source https://api.nuget.org/v3/index.json -SkipDuplicate -ApiKey ${{ secrets.NugetKey }} -NoSymbols 

For more detailed code, please find in this repo.

Gitlab

Add the publish stage to .gitlab-ci.yml file

stages:
  - build
  - publish

Add the stage to .gitlab-ci.yml file

publish:
  stage: publish
  script:
    - "chcp 65001"
    - "dotnet new tool-manifest"
    - "dotnet tool install dotnetCampus.TagToVersion"
    - "dotnet tool run dotnet-TagToVersion -t $CI_COMMIT_TAG"

    - "dotnet pack --configuration Release"
    - 'nuget push bin\Release\*.nupkg -Source https://api.nuget.org/v3/index.json -SkipDuplicate -ApiKey $NuGetKey -NoSymbols'

  only:
    - tags

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.