Skip to content
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

Merged
merged 8 commits into from
Mar 8, 2019

Conversation

paoptu023
Copy link
Contributor

Description of changes:
Add --semantic-version option to sam publish command. It overwrites the SemanticVersion 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:

  • Write unit tests
  • Write/update integration tests
  • make pr passes
  • Windows testing
  • Write documentation

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@paoptu023
Copy link
Contributor Author

Can we get an ETA for when this PR will get reviewed?

@@ -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."
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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?

Copy link
Contributor Author

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.

# 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:
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made the change.

@jfuss
Copy link
Contributor

jfuss commented Feb 27, 2019

Please update the sam publish design doc on changes.

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':
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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?

# 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:
Copy link
Contributor

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.

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':
Copy link
Contributor

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.

@sriram-mv sriram-mv self-requested a review March 7, 2019 18:29
@jfuss jfuss merged commit 43564aa into aws:develop Mar 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants