ietf-tools / semver-action

GitHub Action to calculate the next release version based on conventional commits
BSD 3-Clause "New" or "Revised" License
56 stars 22 forks source link

action always selects latest tag regardless of branch #29

Closed jeacott1 closed 1 year ago

jeacott1 commented 1 year ago

using the following config

Run ietf-tools/semver-action@v1.[4]
  with:
    token: ***
    branch: main
    patchAll: true
    skipInvalidTags: true
    minorList: feat, feature
    patchList: fix, bugfix, perf, refactor, test, tests
    noVersionBumpBehavior: error

I have 2 branches, main, and a release/xxx branch the latest tag on main is 0.3.0 the latest tag on release/xxx is 0.3.0-testing-p1

I have configured branch: main and expect tags to be found on main only.

the action outputs logs: Comparing against latest tag: 0.3.0-testing-p1

Will bump version 0.3.0-testing-p1 using PATCH Current version is 0.3.0-testing-p1 Next version is v0.3.0

why is ietf-tools/semver-action comparing tags in different branches? this seems wrong and quite dangerous to me. am I missing something?

NGPixel commented 1 year ago

Releases are attached to a tag and tags are not tied to a branch. They are distinct references and the action has no way to know from which branch a tag was created.

The action will query the latest 10 tags and use the first one that is a valid semver. The tag is then compared against the head of the branch you specified to get the list of commits.

jeacott1 commented 1 year ago

yeah - thats a disaster.

NGPixel commented 1 year ago

As a workaround, you could use the prefix option and name your releases/tags with a different prefix for each branch.

jeacott1 commented 1 year ago

As a workaround, you could use the prefix option and name your releases/tags with a different prefix for each branch.

thanks. that wont work for me. whats the point of the branch config if its not used to isolate a branch? an option if you didnt want to add it directly would be to facilitate a fromTag: setting and let users define their own logic to acquire that.

NGPixel commented 1 year ago

The branch option is used to specify the branch to compare against when fetching the list of commits, so that a query like v1.0.0...main can be used.

A fromTag option is a good idea. Keep in mind that you'll still have the problem of somehow finding tags by branch, which is not possible from the API, as mentioned earlier. You'll have to use the git cli to obtain that info.

jeacott1 commented 1 year ago

yeah finding the proper from tag by git in a bash action in github is straightforward.

something like this I think

      - name: Get previous tag
        id: previousTag
        run: |
          name=$(git tag --sort=-creatordate --merged ${{ github.ref_name }} -l "*" | head -n1)
          echo "previousTag: $name"
          echo "previousTag=$name" >> $GITHUB_ENV
NGPixel commented 1 year ago

Added fromTag in v1.5.0

jeacott1 commented 1 year ago

thank you so much!!

jeacott1 commented 1 year ago

@NGPixel hmmm

Run ietf-tools/semver-action@v1.5.0 with: token: *** branch: main patchAll: true skipInvalidTags: true fromTag: 0.3.0 minorList: feat, feature patchList: fix, bugfix, perf, refactor, test, tests noVersionBumpBehavior: error

    /home/runner/work/_actions/ietf-tools/semver-action/v1.5.0/dist/index.js:31142
    latestTag = _.get(tagsRaw, 'repository.ref')
                      ^

 ReferenceError: tagsRaw is not defined
    at main (/home/runner/work/_actions/ietf-tools/semver-action/v1.5.0/dist/index.js:31142:23)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

shall I create this as a new issue?

NGPixel commented 1 year ago

Fixed in v1.5.1

jeacott1 commented 1 year ago

Working beautifully. Thank you so much!!