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
#6031 Add the sls:stage
variable
#9296
Conversation
Codecov Report
@@ Coverage Diff @@
## master #9296 +/- ##
==========================================
+ Coverage 86.86% 86.93% +0.06%
==========================================
Files 316 316
Lines 11765 11827 +62
==========================================
+ Hits 10220 10282 +62
Misses 1545 1545
Continue to review full report at Codecov.
|
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.
@mnapoli great thanks for working on that!
What's exactly the status of it? Why exactly it's submitted as draft PR ?
Just wanted to make sure this is what you expected ^^ Since you seem to be good with this I'll add the region. |
Oh 😄 This is why it was in draft. I'll remove the commit I just pushed then. |
OK all good, ready for review, there's just |
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.
Thank you @mnapoli looks very good! I've just suggested few improvements to tests.
@@ -134,6 +134,10 @@ functions: | |||
APIG_DEPLOYMENT_ID: ApiGatewayDeployment${sls:instanceId} | |||
``` | |||
|
|||
**stage** | |||
|
|||
The stage used by the Serverless CLI. The `${sls:stage}` variable is a shortcut for `${opt:stage, self:provider.stage}`. |
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 technically a shortcut for ${opt:stage, self:provider.stage, "dev"}
@@ -13,18 +13,24 @@ describe('test/unit/lib/configuration/variables/sources/instance-dependent/get-s | |||
let variablesMeta; | |||
let serverlessInstance; | |||
|
|||
before(async () => { | |||
const initializeServerless = async (providerStage, cliOptionStage) => { |
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.
Let's update the signature to (configExt, options)
. It'll be more up to convention in other test files, and more portable for eventual future addition.
configExt
should be a simply configuration extension to be applied via _.merge(config, configExt)
, and options
, should be CLI options.
}); | ||
}; | ||
|
||
beforeEach(async () => await initializeServerless()); |
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.
This is invoked prior every test, even one which invokes initializeServerless()
on it's own. So that's not clean.
Let's remove this, and simply invoke initializeServerless
in context of it
's
}); | ||
}; | ||
|
||
beforeEach(async () => await initializeServerless()); | ||
|
||
it('should resolve instanceId', () => { |
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.
We can reword to should resolve ${sls.instanceId}
|
||
it('should resolve instanceId', () => { | ||
if (variablesMeta.get('custom\0sls')) throw variablesMeta.get('custom\0sls').error; | ||
expect(typeof serverlessInstance.instanceId).to.equal('string'); | ||
expect(configuration.custom.sls).to.equal(serverlessInstance.instanceId); | ||
}); | ||
|
||
it('should resolve ${sls:stage} to "dev" by default', () => { |
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 would do one it("should resolve ${sls:stage}")
and in it's context simply test one by one, all three variants
@medikoo I have pushed changes that should address all your comments. |
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.
Thank @mnapoli ! That looks great. I've just proposed few style simplifications, so code is simpler
missingAddress: '${sls:}', | ||
unsupportedAddress: '${sls:foo}', | ||
nonStringAddress: '${sls:${self:custom.someObject}}', | ||
someObject: {}, | ||
}, | ||
}; | ||
if (configExt !== undefined) { |
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.
Let's simplify this to if (configExt) {
@@ -40,29 +47,61 @@ describe('test/unit/lib/configuration/variables/sources/instance-dependent/get-s | |||
configuration, | |||
variablesMeta, | |||
sources: { self: selfSource, sls: getSlsSource(serverlessInstance) }, | |||
options: {}, | |||
options: options !== undefined ? options : {}, |
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.
Let's simplify to options || {}
@mnapoli one more thing. I think it'll be nice to also update examples in our documentation, which use stage resolution (as e.g. I think those can easily be found by searching for |
This variable is a shortcut to: ``` ${opt:stage, self:provider.stage, "dev"} ```
@medikoo good idea! I just pushed again. |
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.
Thank you @mnapoli that's great!
Does |
@razor-x a quick search in the codebase shows no result for I also read here https://forum.serverless.com/t/process-env-serverless-stage-in-1-0/144:
It seems like it's no longer a feature indeed. I would say that no, this variable is not taken into account. I might be wrong though. |
A shortcut to ``` ${opt:stage, self:provider.stage, "dev"} ```
I understand that |
@nikhilpr23 please open a different discussion. FYI you can set the default stage via |
${sls:stage}
is a shortcut to:This is a new attempt at solving #6031, replacing older PR #6049.
As a start, I'm only introducing
${sls:stage}
for now, and opening this PR as WIP. Once we're happy with the implementation, I'll addregion
in this PR.Closes: #6031
Note:
npm run lint
shows errors all over the codebase, so I'm ignoring it for now.