-
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
Conversation
Can we get an ETA for when this PR will get reviewed? |
samcli/commands/publish/command.py
Outdated
@@ -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." |
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.
samcli/commands/publish/command.py
Outdated
# 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 comment
The 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 source
copy customers edit themselves?
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.
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 comment
The 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 publish_application
instead? Customers using build
will NEED to update the source template anyways, as running build will squash this change to the template. I would prefer a solution that matches the expectation of editing the source rather than possibly editing the generated sources.
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.
Made the change.
Please update the |
samcli/commands/publish/command.py
Outdated
return UserException( | ||
"Your SAM template contains invalid S3 URIs. Please make sure that you have uploaded application " | ||
"artifacts to S3 by packaging the template: 'sam package --template-file <file-path>'.") | ||
if error_code == 'BadRequestException': |
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.
I'm not too fond of looking at the message of the exception to determine the exception we throw, I dont know if there is a better way to do this though.
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.
The only way to tell whether this exception is about S3 or Version is from the message, because we throw general BadRequestException 😞: https://docs.aws.amazon.com/serverlessrepo/latest/devguide/applications-applicationid-versions-semanticversion.html.
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 these the only ones we need to be catching? What is thrown when the semver already exists? Is throttle a concern?
To @thesriram note, can this be handled within the publish_application
call? Instead of consumers of the library having to deal with all these cases, you could expand the library to throw more friendly exceptions. This would result in cleaner code here and for any other consumers.
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.
Makes sense, I'll handle the exceptions inside serverlessrepo, except the S3 URI one. I still want to keep it here since the error message would be specific to sam cli (telling people to run sam package), what do you think?
samcli/commands/publish/command.py
Outdated
# 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 comment
The 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 publish_application
instead? Customers using build
will NEED to update the source template anyways, as running build will squash this change to the template. I would prefer a solution that matches the expectation of editing the source rather than possibly editing the generated sources.
samcli/commands/publish/command.py
Outdated
return UserException( | ||
"Your SAM template contains invalid S3 URIs. Please make sure that you have uploaded application " | ||
"artifacts to S3 by packaging the template: 'sam package --template-file <file-path>'.") | ||
if error_code == 'BadRequestException': |
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 these the only ones we need to be catching? What is thrown when the semver already exists? Is throttle a concern?
To @thesriram note, can this be handled within the publish_application
call? Instead of consumers of the library having to deal with all these cases, you could expand the library to throw more friendly exceptions. This would result in cleaner code here and for any other consumers.
Description of changes:
Add
--semantic-version
option tosam publish
command. It overwrites theSemanticVersion
value in the original template metadata, and publishes application with the provided version number.The use case is that customers can easily use the build number from their continuous deployment pipelines to publish new application versions, without manually updating the template.
Checklist:
make pr
passesBy submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.