Skip to content

Commit

Permalink
(hotfix) 0.35.1 (#147)
Browse files Browse the repository at this point in the history
* fix npm tag failures with floating tags

* add option to npm add_tags command

* add missing tag when creating images on releases

* (hotfix) 0.35.1
  • Loading branch information
jmlopez-rod authored Jun 18, 2024
1 parent 86277ef commit d654f90
Show file tree
Hide file tree
Showing 14 changed files with 79 additions and 21 deletions.
19 changes: 18 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,22 @@ The format of this changelog is based on
## [Unreleased]

## [0.35.1] <a name="0.35.1" href="#0.35.1">-</a> June 17, 2024

- `m npm add_tags` no longer attempts to tag `v#.#` since these are npm sem
versions.

> Tags that can be interpreted as valid semver ranges will be rejected. For
> example, v1.4 cannot be used as a tag, because it is interpreted by semver
> as >=1.4.0 <1.5.0. See https://github.com/npm/npm/issues/6082.
- `m npm add_tags` requires the `--branch` option. When we tag as `latest` we
also need to provide the name of the branch in which we are building the
package. The env var `$M_BRANCH` should be passed to the option.

- Fix missing docker tag creation. When creating the `latest` tag we were also
missing the default branch tag.

## [0.35.0] <a name="0.35.0" href="#0.35.0">-</a> June 13, 2024

- Update `npm_tags` to semi-match output with `docker_tags`.
Expand Down Expand Up @@ -578,7 +594,8 @@ latest on the `master` branch.
- Provides basic utilities to create a CI/CD flow via the m cli.
- As a library, it facilities the creation of clis similar to m.

[unreleased]: https://github.com/jmlopez-rod/m/compare/0.35.0...HEAD
[unreleased]: https://github.com/jmlopez-rod/m/compare/0.35.1...HEAD
[0.35.1]: https://github.com/jmlopez-rod/m/compare/0.35.0...0.35.1
[0.35.0]: https://github.com/jmlopez-rod/m/compare/0.34.3...0.35.0
[0.34.3]: https://github.com/jmlopez-rod/m/compare/0.34.2...0.34.3
[0.34.2]: https://github.com/jmlopez-rod/m/compare/0.34.1...0.34.2
Expand Down
2 changes: 1 addition & 1 deletion m/m.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
owner: jmlopez-rod
repo: m
version: 0.35.0
version: 0.35.1
workflow: m_flow
build_tag_with_version: true
2 changes: 2 additions & 0 deletions packages/python/m/ci/docker/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ def write_ci_manifest_info(
m_tag = '1.1.1'
names = [img.image_name for img in self.images]
tags = [m_tag, *docker_tags(m_tag)]
if 'latest' in tags:
tags.append(m_env.default_branch)
names_json = json.dumps(names, separators=(',', ':'))
tags_json = json.dumps(tags, separators=(',', ':'))
files_res = [
Expand Down
3 changes: 3 additions & 0 deletions packages/python/m/ci/docker/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
class MEnvDocker(BaseModel):
"""Values from `MEnv` needed by docker."""

# The name of the default branch based on the workflow.
default_branch: str

# The m tag to build the images.
m_tag: str

Expand Down
13 changes: 13 additions & 0 deletions packages/python/m/ci/docker/tags.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
import re


def is_semver(m_tag: str) -> bool:
"""Determine if a tag is a semver.
Args:
m_tag: A tag/version provided by m.
Returns:
True if the tag is a semver.
"""
regex = r'\d+.\d+.\d+-(.*)\.(.*)'
return not bool(re.match(regex, m_tag))


def docker_tags(m_tag: str, *, skip_floating: bool = False) -> list[str]:
"""Convert an m_tag to docker tags.
Expand Down
1 change: 1 addition & 0 deletions packages/python/m/ci/m_blueprints.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def _write_blueprints(
multi_arch=bool(docker_config.architectures),
architectures=list((docker_config.architectures or {}).keys()),
use_buildx=docker_config.platforms is not None,
default_branch=config.get_default_branch(),
)
files = FileNames.create_instance(m_dir)
if update_makefile:
Expand Down
9 changes: 7 additions & 2 deletions packages/python/m/cli/commands/npm/add_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
class Arguments(BaseModel):
"""Add tags to a package version.
$ m npm add_tags <package-name> <m_tag>
$ m npm add_tags --branch "$M_BRANCH" <package-name> <m_tag>
These tags are the same tags generated from docker.
"""
Expand All @@ -21,11 +21,16 @@ class Arguments(BaseModel):
required=True,
)

branch: str = Arg(
help='the branch where the build is taking place',
required=True,
)


@command(
help='add tags to an npm package version',
model=Arguments,
)
def run(arg: Arguments):
from m.npm.add_tags import add_tags
return run_main(lambda: add_tags(arg.package_name, arg.m_tag))
return run_main(lambda: add_tags(arg.package_name, arg.m_tag, arg.branch))
15 changes: 11 additions & 4 deletions packages/python/m/npm/add_tags.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
from m.ci.docker.tags import docker_tags
from m.ci.docker.tags import docker_tags, is_semver

from ..core import Issue, issue
from ..core.fp import Bad, Good, OneOf
from .cli import add_dist_tag


def add_tags(pkg: str, version: str) -> OneOf[Issue, list[str]]:
def add_tags(pkg: str, version: str, branch: str) -> OneOf[Issue, list[str]]:
"""Add tags to a package.
The branch name will be added to the tags in the event that we have a
valid sem-version.
Args:
pkg: The name of the npm package.
version: The package version to tag.
branch: The current branch where the build is taking place.
Returns:
A `OneOf` containing a summary of added tags or an Issue.
"""
tags = docker_tags(version)
tags = docker_tags(version, skip_floating=True)
if is_semver(version):
tags.append('latest')
tags.append(branch)
issues: list[Issue] = []
added: list[str] = []
for tag in tags:
Expand All @@ -26,7 +33,7 @@ def add_tags(pkg: str, version: str) -> OneOf[Issue, list[str]]:
added.append(cmd_result.value)
if issues:
return issue('dist-tag add issues', context={
'issues': issues,
'issues': [iss.to_dict() for iss in issues],
'added': added,
})
return Good(added)
2 changes: 1 addition & 1 deletion packages/python/m/npm/clean_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def remove_tags(pkg: str, tags: Set[str]) -> OneOf[Issue, List[str]]:
removed.append(cast(str, cmd_result.value))
if issues:
return issue('dist-tag rm issues', context={
'issues': issues,
'issues': [iss.to_dict() for iss in issues],
'removed': removed,
})
return Good(removed)
Original file line number Diff line number Diff line change
@@ -1 +1 @@
["1.1.1","latest","v1","v1.1"]
["1.1.1","latest","v1","v1.1","master"]
Original file line number Diff line number Diff line change
@@ -1 +1 @@
["1.1.1","latest","v1","v1.1"]
["1.1.1","latest","v1","v1.1","master"]
Original file line number Diff line number Diff line change
@@ -1 +1 @@
["1.1.1","latest","v1","v1.1"]
["1.1.1","latest","v1","v1.1","master"]
26 changes: 18 additions & 8 deletions packages/python/tests/cli/commands/test_npm.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Any

import pytest
from m.core import Bad, Good
from m.core import Bad, Good, Issue
from pytest_mock import MockerFixture
from tests.cli.conftest import TCase as CliTestCase
from tests.cli.conftest import assert_streams, run_cli
Expand All @@ -24,35 +24,45 @@ class TCase(CliTestCase):
expected='["- tag1","- tag2"]',
),
TCase(
cmd='m npm add_tags scope/pkg 0.0.0-rc123.b123',
cmd='m npm add_tags --branch default_branch scope/pkg 0.0.0-rc123.b123',
eval_cmd_side_effects=[
Good('+ next'),
Good('+ pr123'),
],
expected='["+ next","+ pr123"]',
),
TCase(
cmd='m npm add_tags scope/pkg 1.1.1',
cmd='m npm add_tags --branch default_branch scope/pkg 1.1.1',
eval_cmd_side_effects=[
Good('+ latest'),
Good('+ v1'),
Good('+ v1.1'),
Good('+ default_branch'),
],
expected='["+ latest","+ v1","+ v1.1"]',
expected='["+ latest","+ default_branch"]',
),
TCase(
cmd='m npm add_tags scope/pkg 0.0.0-pr12.b123',
cmd='m npm add_tags --branch default_branch scope/pkg 0.0.0-pr12.b123',
eval_cmd_side_effects=[
Good('+ pr12'),
],
expected='["+ pr12"]',
),
TCase(
cmd='m npm add_tags --branch default_branch scope/pkg 0.0.0-pr12.b123',
eval_cmd_side_effects=[
Bad(Issue('SOME ERROR')),
],
errors=[
'dist-tag add issues',
'SOME ERROR',
],
exit_code=1,
),
TCase(
cmd='m npm clean_tags scope/pkg',
eval_cmd_side_effects=[
Good('{"tag1":"","tag2":"","tag3":"v3"}'),
Good('- tag1'),
Bad('some_error_tag2'),
Bad(Issue('some_error_tag2')),
],
errors=[
'dist-tag rm issues',
Expand Down
2 changes: 1 addition & 1 deletion packages/python/tests/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ if [ "$SINGLE" = 'false' ]; then
else
# To run specific tests:
source="packages/python/m/ci/docker"
filter="test_m_start_release"
filter="test_m_npm_dist_tags"
coverage run --source "$source" -m pytest -p no:logging packages/python -vv -k "$filter"
coverage report -m
fi
Expand Down

0 comments on commit d654f90

Please sign in to comment.