0.1.7 • Published 4 years ago

serverless-version-info v0.1.7

Weekly downloads
2
License
ISC
Repository
github
Last release
4 years ago

Serverless Version Info

This Serverless plugin generates version information from package.json and git commands at the time of deployment. This can be included e.g. in a handler's response headers.

Install

npm install --save-dev serverless-version-info

Usage

Add serverless-version-info to your serverless.yml plugin section:

plugins:
  - serverless-version-info

By default, this adds a LAMBDA_VERSION environment variable. Use this in your code:

  headers['X-Lambda-Version'] = process.env.LAMBDA_VERSION;

Sample output header:

X-Lambda-Version: 1.2.3-15 (master/c9edfbe+2)

Options

Two options are supported:

custom:
  serverless-version-info:
    eval: true        # (Default: true)  Perform eval()'s, see below
    verbose: true     # (Default: false) Print the resulting values during deploy

Template variables

This plugin supports the following template variables:

VariableDescriptionExample
aheadCommits which have not been pushed to branch2
behindCommits in branch which are not in the local codebase0
branchCurrent git branchmaster
deltaNumber of untracked, deleted, modified, or renamed files vs latest commit2
hashShort hash id of latest commitc9edfbe
majorMajor version number1
minorMinor version number2
patchPatch/revision count, i.e. number of commits15
pkgVersionversion in package.json1.2.3
stageprocess.env.STAGE or provider.stage from serverless.ymlprod
timestampUnix/epoch timestamp in milliseconds, also ts1567771125936
versionSemantic version derived from pkgVersion and patch1.2.15

These variables can be used in serverless.yml by prepending a $ to them.

The default template is $pkgVersion-$patch ($branch/$hash+$delta).

Customization

By default, serverless-version-info sets the LAMBDA_VERSION environment variable. You may change this and the template(s) used in serverless.yml:

custom:
  serverless-version-info:
    environment:
      LAMBDA_DEPLOYED_VERSION: true # default template
      X_VERSION_HEADER: "$version-$delta ($branch/$hash)" # 1.2.15-2 (master/c9edfbe)

If you define custom environment variables, LAMBDA_VERSION will not be set unless you also specify it in the configuration.

Expression evaluation

serverless-version-info supports basic eval() support for expressions bounded by $`..` or $|..|.

NOTE: Nesting expressions using the same expression delimiters is currently not supported.

custom:
  serverless-version-info:
    verbose: true
    environment:
      SVI_TEST_1: "$version-$delta ($branch/$hash)"
      SVI_TEST_2: "$version-$delta $major.$minor ($branch/$hash) [$stage]"
      SVI_TEST_3: "$major.$`($minor + $patch/10)`"
      SVI_TEST_4: "$major.$`'${self:provider.stage}' === 'prod' ? '$minor' : '$|$minor+1|'`.$patch"

which results in

Serverless: serverless-version-info set SVI_TEST_1 to "0.1.19-3 (master/c2f466b)"
Serverless: serverless-version-info set SVI_TEST_2 to "0.1.19-3 0.1 (master/c2f466b) [staging]"
Serverless: serverless-version-info set SVI_TEST_3 to "0.2.9"
Serverless: serverless-version-info set SVI_TEST_4 to "0.2.19"

See also

For general expression support in serverless.yml, please check out serverless-eval-plugin.

Contribute

Please see the Github repository.

0.1.7

4 years ago

0.1.6

4 years ago

0.1.5

4 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago