wakatime / semver-action

Auto-generate the next semantic version.
MIT License
12 stars 0 forks source link

How to handle new repos? #31

Closed kvernon closed 1 year ago

kvernon commented 1 year ago

Hi again y'all!

So I'm working with this github action, but I can't figure out the right way to go with new repos using this tool.

Basically, I've started coding in a feature branch, and there is no production code (master/main is empty). I'm build up my action using this strategy. I think the issue with this tool is that there are no existing tags, so it doesn't know how to proceed.

How would you all go forward in brand new repos? It seems pre meditative to tag a new repo with v0.0.0. Is there a default I can set up if there are no tags when this action looks?

• debug logs enabled

   • commit sha: "3e5cf...", bump: "auto", base version: "", prefix: "v", prerelease id: "branching", main branch name: "master", develop branch name: "master", repo dir: ".", debug: true

   • running git               args=[-c log.showSignature=false config --global --add safe.directory /github/<repo>]
   • git result                stderr= stdout=
   • running git               args=[-c log.showSignature=false rev-parse --is-inside-work-tree]
   • git result                stderr= stdout=true

   • running git               args=[-c log.showSignature=false -C . rev-parse --abbrev-ref HEAD --quiet]
   • git result                stderr= stdout=HEAD

   • dest branch: "HEAD"

   • running git               args=[-c log.showSignature=false -C . log -1 --pretty=%B 3e...]
   • git result                stderr= stdout=Merge [17](https://github.com/<org>/<repo>/actions/runs/33/jobs/55#step:8:18)05c... into 439...[18](https://github.com/<org>/<repo>/actions/runs/33/jobs/55#step:8:19)[31](https://github.com/<org>/<repo>/actions/runs/33/jobs/55#step:8:32)006

   ⨯ failed to generate semver version: failed to extract source branch from commit: no source branch found
kvernon commented 1 year ago

I figured this out... I'm posting here in case someone else is curious too.

A little background on this. We're assigning some values up front. Also, this job would fail if this step failed, so continue-on-error: true is important here. From there, you can check if steps.semver-tag.outputs.semver_tag has a value

      - id: semver-tag
        uses: wakatime/semver-action@v1.5.1
        continue-on-error: true
        with:
          prefix: "${{ inputs.versionTagPrefix }}"
          prerelease_id: "${{ env.BRANCH_NAME }}"
          main_branch_name: "${{ inputs.mainBranchName }}"
          develop_branch_name: "${{ inputs.developBranchName }}"
          debug: "${{ inputs. Debug }}"

      - name: Default the Version for Feature Branch
        if: ${{ steps.semver-tag.outputs.semver_tag == '' && inputs.isFeatureBranch}}
        run: echo "TAG=0.0.0-${{ env.BRANCH_NAME }}-${{ github.run_number }}" >> $GITHUB_ENV

      - name: Default the Version for Release
        if: ${{ steps.semver-tag.outputs.semver_tag == '' && !inputs.isFeatureBranch }}
        run: echo "TAG=0.0.${{ github.run_number }}" >> $GITHUB_ENV

      - name: "tag found is success"
        if: ${{ steps.semver-tag.outputs.semver_tag != '' }}
        run: echo "TAG=${{ steps.semver-tag.outputs.semver_tag }}" >> $GITHUB_ENV