-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(publish): Add --semantic-version option to sam publish command #1020
Changes from 2 commits
8744703
af424a2
e087eff
0f6a665
ad7fc53
f452d2e
9b05f4a
3c19173
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,12 +7,14 @@ | |
from botocore.exceptions import ClientError | ||
from serverlessrepo import publish_application | ||
from serverlessrepo.publish import CREATE_APPLICATION | ||
from serverlessrepo.parser import METADATA, SERVERLESS_REPO_APPLICATION | ||
from serverlessrepo.exceptions import ServerlessRepoError | ||
|
||
from samcli.cli.main import pass_context, common_options as cli_framework_options, aws_creds_options | ||
from samcli.commands._utils.options import template_common_option | ||
from samcli.commands._utils.template import get_template_data | ||
from samcli.commands.exceptions import UserException | ||
from samcli.yamlhelper import yaml_dump | ||
|
||
HELP_TEXT = """ | ||
Use this command to publish a packaged AWS SAM template to | ||
|
@@ -31,31 +33,40 @@ | |
""" | ||
SHORT_HELP = "Publish a packaged AWS SAM template to the AWS Serverless Application Repository." | ||
SERVERLESSREPO_CONSOLE_URL = "https://console.aws.amazon.com/serverlessrepo/home?region={}#/published-applications/{}" | ||
SEMANTIC_VERSION_HELP = "Optional. The value provided here overwrites SemanticVersion in the template metadata." | ||
SEMANTIC_VERSION = 'SemanticVersion' | ||
|
||
|
||
@click.command("publish", help=HELP_TEXT, short_help=SHORT_HELP) | ||
@template_common_option | ||
@click.option('--semantic-version', help=SEMANTIC_VERSION_HELP) | ||
@aws_creds_options | ||
@cli_framework_options | ||
@pass_context | ||
def cli(ctx, template): | ||
def cli(ctx, template, semantic_version): | ||
# All logic must be implemented in the ``do_cli`` method. This helps with easy unit testing | ||
|
||
do_cli(ctx, template) # pragma: no cover | ||
do_cli(ctx, template, semantic_version) # pragma: no cover | ||
|
||
|
||
def do_cli(ctx, template): | ||
def do_cli(ctx, template, semantic_version): | ||
"""Publish the application based on command line inputs.""" | ||
try: | ||
template_data = get_template_data(template) | ||
except ValueError as ex: | ||
click.secho("Publish Failed", fg='red') | ||
raise UserException(str(ex)) | ||
|
||
# Overwrite SemanticVersion in template metadata when provided in command input | ||
if semantic_version and SERVERLESS_REPO_APPLICATION in template_data.get(METADATA, {}): | ||
template_data.get(METADATA).get(SERVERLESS_REPO_APPLICATION)[SEMANTIC_VERSION] = semantic_version | ||
with open(template, 'w') as fp: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the expectation here? What happens when this is a template that is generated and isn't the exact There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The expectation is that the template used to publish will always be up to date, and the latest semantic version can be tracked in the template. In most cases it's not the source copy since the template needs to be packaged first, but modifying the source copy requires additional inputs (like path to the source template), even with that we can't ensure it's the "source". I think it's better to keep the command simple and just update the published template. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not crazy about writing this back to the template. Till now, none of the commands writes or updates the template that is being handled. Can we pass the semantic version to the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Made the change. |
||
fp.write(yaml_dump(template_data)) | ||
|
||
try: | ||
publish_output = publish_application(template_data) | ||
click.secho("Publish Succeeded", fg="green") | ||
click.secho(_gen_success_message(publish_output), fg="yellow") | ||
click.secho(_gen_success_message(publish_output)) | ||
except ServerlessRepoError as ex: | ||
click.secho("Publish Failed", fg='red') | ||
raise UserException(str(ex)) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are there any restrictions on what the version can be set to? or is it up to the user to setup any version?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's up to the user, but if they pass in invalid version numbers, the API call would fail. I didn't include an explanation of valid version numbers here, because it's already in the metadata doc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we catch the exception correct and provide a useful message to customers within the CLI?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will add code to catch the exception and print user-friendly error message.