cbcrouse / Versioning.NET

A dotnet tool that automatically increments versions in csproj files based on git commit hints.
MIT License
20 stars 3 forks source link

A valid semver tag (e.g. v1.0.0) was not found even though it exists #25

Closed cdavernas closed 2 years ago

cdavernas commented 2 years ago

Describe the bug When using the tool in a Github pipeline, it will systematically return the following message:

Tool 'versioning.net' (version '0.5.0') was successfully installed.
info: Application.GitVersioning.Handlers.GetCommitVersionInfosHandler[0]
      A valid semver tag (e.g. v1.0.0) was not found. Please add a valid semver tag to your repository and try again.
info: Application.GitVersioning.Handlers.IncrementVersionWithGitIntegrationHandler[0]
      Increment 'Unknown' was determined from the commits.

To Reproduce Steps to reproduce the behavior:

  1. Create a Github pipeline such as the following:
name: CI

on:

  push:
    branches: [ main ]

  pull_request:
    branches: [ main ]

  workflow_dispatch:

jobs:
  build:
    runs-on: windows-latest

    steps:
      - uses: actions/checkout@v2

      - name: Configure remote repository
        run: |
          git remote set-url origin "https://[user]:[password]@github.com/[repo]/test.git"
          dotnet tool install --global Versioning.NET
          dotnet-version increment-version-with-git -g "." --branch-name main --author-email pipeline@github.com
  1. Push a commit with a message such as:
fix(Versioning): Fixed issue where git tag could not be found
  1. When running, the pipeline will show the message described above, and the new version is not computed

Expected behavior A new version is successfully computed

Additional context I did tag the repository with a SemVer (v0.1.0) before running the tool, but it did not change a thing 😢 Furthermore, shouldn't semantic versions NOT be prefixed with the 'v' character, as explained in this issue?

cdavernas commented 2 years ago

@cbcrouse Did you have time to check it out? I'm trying to get it to work for CNCF Synapse. If you have time, it would be absolutely amazing if you could contribute with a PR to add a pipeline for your awesome tool.

cbcrouse commented 2 years ago

Hey @cdavernas I apologize, I don't recall seeing a notification of this issue, so thanks for following up on it. I'll have some time tomorrow to review this in more detail.

Furthermore, shouldn't semantic versions NOT be prefixed with the 'v' character, as explained in this issue

The versions in the project files themselves do not contain the 'v' character however, it helps to find the version tag when traversing through potentially many numeric-only tags such as dates. The SemVer C# library supports the 'v' when accepting the string formatted value and works quite well.

cbcrouse commented 2 years ago

Hi @cdavernas - I was able to resolve this issue by setting the fetch-depth value of the checkout task to 0. I've added this as a troubleshooting step to a new section in the wiki.

Example

    steps:
      - name: Checkout
        uses: actions/checkout@v2.4.2
        with:
          fetch-depth: 0

While I was troubleshooting, I also stumbled upon an unhandled exception for missing csproj files so I've published a fix for that. However, this issue did not require any code changes. Can you let me know if following the same steps also resolves your issue?

cbcrouse commented 2 years ago

@cbcrouse Did you have time to check it out? I'm trying to get it to work for CNCF Synapse. If you have time, it would be absolutely amazing if you could contribute with a PR to add a pipeline for your awesome tool.

Let me know if you would still like me to contribute to your workflows. I recommend doing the versioning separately after a pull request is merged into the target branch. If main is the target branch, then create a workflow that triggers on main to version the code, and then create a separate workflow that triggers on completion of the versioning workflow to deploy your code if necessary.

cdavernas commented 2 years ago

Can you let me know if following the same steps also resolves your issue?

I'll check that today!

Let me know if you would still like me to contribute to your workflows

Well, sure! If its not too much hastle for you it would be wonderful! The reason is the more contributors, the better. If you do for that project, Ill make sure to implement your recommendations for another, just to get my hands on it!

Anyways, thank you very much and kudos for your great work!