mathieudutour / github-tag-action

A Github Action to automatically bump and tag master, on merge, with the latest SemVer formatted version. Works on any platform.
https://github.com/marketplace/actions/github-tag
MIT License
641 stars 201 forks source link

Tag prefixes don't work if the repository contains non prefixed tags #143

Closed mattwcole closed 1 year ago

mattwcole commented 2 years ago

The tag_prefix breaks if non prefixed tags are present in the repository. Consider the following history:

Commit 3 | tag app2/5.0.0
Commit 2 | tag 7.0.0
Commit 1 | tag app1/3.0.0

With a tag_prefix: app1/, the new tag should be app1/3.0.1, but it is instead 7.0.1.

This appears to be a bug in getValidTags. I have written a failing test to demonstrate.

it('returns only prefixed tags', async () => {
  /*
   * Given
   */
  const testTags = [
    {
      name: 'app2/5.0.0',
      commit: { sha: 'string', url: 'string' },
      zipball_url: 'string',
      tarball_url: 'string',
      node_id: 'string',
    },
    {
      name: '7.0.0',
      commit: { sha: 'string', url: 'string' },
      zipball_url: 'string',
      tarball_url: 'string',
      node_id: 'string',
    },
    {
      name: 'app1/3.0.0',
      commit: { sha: 'string', url: 'string' },
      zipball_url: 'string',
      tarball_url: 'string',
      node_id: 'string',
    },
  ];
  const mockListTags = jest
    .spyOn(github, 'listTags')
    .mockImplementation(async () => testTags);
  /*
   * When
   */
  const validTags = await getValidTags(/^app1\//, false);
  /*
   * Then
   */
  expect(mockListTags).toHaveBeenCalled();
  expect(validTags).toHaveLength(1);
  expect(validTags[0]).toEqual({
    name: 'app1/3.0.0',
    commit: { sha: 'string', url: 'string' },
    zipball_url: 'string',
    tarball_url: 'string',
    node_id: 'string',
  });
});
duality72 commented 1 year ago

The pull request above attempts to correct the behavior of getValidTags() so that tags that don't match the requested tag prefix are not considered valid. I wouldn't think anyone was relying on the previous behavior where getValidTags() would return tags that didn't match the submitted prefix, but it is a slight behavior change.