github-tag-action icon indicating copy to clipboard operation
github-tag-action copied to clipboard

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

Open mattwcole opened this issue 2 years ago • 0 comments

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',
  });
});

mattwcole avatar Sep 07 '22 17:09 mattwcole