Add test for package version already exists #92
@ -36,6 +36,7 @@ def command(ctx, include, exclude):
|
||||
verbose = ctx.obj.verbose
|
||||
dry_run = ctx.obj.dry_run
|
||||
local_stack = ctx.obj.local_stack
|
||||
debug = ctx.obj.debug
|
||||
|
||||
if local_stack:
|
||||
dev_root_path = os.getcwd()[0:os.getcwd().rindex("stack-orchestrator")]
|
||||
@ -57,7 +58,7 @@ def command(ctx, include, exclude):
|
||||
|
||||
def build_package(package):
|
||||
if not quiet:
|
||||
print(f"Building: {package}")
|
||||
print(f"Building npm package: {package}")
|
||||
repo_dir = package
|
||||
repo_full_path = os.path.join(dev_root_path, repo_dir)
|
||||
# TODO: make the npm registry url configurable.
|
||||
@ -65,12 +66,13 @@ def command(ctx, include, exclude):
|
||||
if not dry_run:
|
||||
if verbose:
|
||||
print(f"Executing: {build_command}")
|
||||
envs = {"CERC_NPM_AUTH_TOKEN": os.environ["CERC_NPM_AUTH_TOKEN"]} | ({"CERC_SCRIPT_DEBUG": "true"} if debug else {})
|
||||
build_result = docker.run("cerc/builder-js",
|
||||
remove=True,
|
||||
interactive=True,
|
||||
tty=True,
|
||||
user=f"{os.getuid()}:{os.getgid()}",
|
||||
envs={"CERC_NPM_AUTH_TOKEN": os.environ["CERC_NPM_AUTH_TOKEN"]},
|
||||
envs=envs,
|
||||
add_hosts=[("host.docker.internal", "host-gateway")],
|
||||
volumes=[(repo_full_path, "/workspace")],
|
||||
command=build_command
|
||||
|
8
cli.py
8
cli.py
@ -24,11 +24,12 @@ CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help'])
|
||||
|
||||
|
||||
class Options(object):
|
||||
def __init__(self, quiet, verbose, dry_run, local_stack):
|
||||
def __init__(self, quiet, verbose, dry_run, local_stack, debug):
|
||||
self.quiet = quiet
|
||||
self.verbose = verbose
|
||||
self.dry_run = dry_run
|
||||
self.local_stack = local_stack
|
||||
self.debug = debug
|
||||
|
||||
|
||||
@click.group(context_settings=CONTEXT_SETTINGS)
|
||||
@ -36,11 +37,12 @@ class Options(object):
|
||||
@click.option('--verbose', is_flag=True, default=False)
|
||||
@click.option('--dry-run', is_flag=True, default=False)
|
||||
@click.option('--local-stack', is_flag=True, default=False)
|
||||
@click.option('--debug', is_flag=True, default=False)
|
||||
# See: https://click.palletsprojects.com/en/8.1.x/complex/#building-a-git-clone
|
||||
@click.pass_context
|
||||
def cli(ctx, quiet, verbose, dry_run, local_stack):
|
||||
def cli(ctx, quiet, verbose, dry_run, local_stack, debug):
|
||||
"""Laconic Stack Orchestrator"""
|
||||
ctx.obj = Options(quiet, verbose, dry_run, local_stack)
|
||||
ctx.obj = Options(quiet, verbose, dry_run, local_stack, debug)
|
||||
|
||||
|
||||
cli.add_command(setup_repositories.command, "setup-repositories")
|
||||
|
@ -1,7 +1,7 @@
|
||||
#!/bin/bash
|
||||
# Usage: build-npm-package.sh <registry-url> <publish-with-this-version>
|
||||
# Note: supply the registry auth token in CERC_NPM_AUTH_TOKEN
|
||||
if [ -n "$CERC_SCRIPT_DEBUG" ]; then
|
||||
if [[ -n "$CERC_SCRIPT_DEBUG" ]]; then
|
||||
set -x
|
||||
fi
|
||||
if ! [[ $# -eq 1 || $# -eq 2 ]]; then
|
||||
@ -17,11 +17,19 @@ if [[ $# -eq 2 ]]; then
|
||||
else
|
||||
package_publish_version=$( cat package.json | jq -r .version )
|
||||
fi
|
||||
# Get the name of this package from package.json since we weren't passed that
|
||||
package_name=$( cat package.json | jq -r .name )
|
||||
local_npm_registry_url=$1
|
||||
npm config set @lirewine:registry ${local_npm_registry_url}
|
||||
npm config set @cerc-io:registry ${local_npm_registry_url}
|
||||
npm config set -- ${local_npm_registry_url}:_authToken ${CERC_NPM_AUTH_TOKEN}
|
||||
echo "Build and publish version ${package_publish_version}"
|
||||
# First check if the version of this package we're trying to build already exists in the registry
|
||||
package_exists=$( yarn info --json ${package_name}@${package_publish_version} | jq -r .data.dist.tarball )
|
||||
if [[ -n "$package_exists" ]]; then
|
||||
echo "${package_publish_version} of ${package_name} already exists in the registry, skipping build"
|
||||
exit 0
|
||||
fi
|
||||
echo "Build and publish ${package_name} version ${package_publish_version}"
|
||||
yarn install
|
||||
yarn build
|
||||
yarn publish --non-interactive --new-version ${package_publish_version} --no-git-tag-version
|
||||
|
Loading…
Reference in New Issue
Block a user