Serverless plugin to expose git status to serverless services
npm install serverless-plugin-git-variablesExpose git variables (HEAD description, branch name, short commit hash, message, git tags, and if the local repo has changed files) to your serverless services.
Moreover, it adds GIT related environment variables and tags (GIT_COMMIT_SHORT, GIT_COMMIT_LONG, GIT_BRANCH, GIT_IS_DIRTY, GIT_REPOSITORY, GIT_TAGS) for each defined function in the serverless file. You can disable this by adding the following custom variable in your serverless.yml file:
```
custom:
exportGitVariables: false
If you only want to add a specific subset of variables/tags, you can define a whitelist:
``
custom:
gitVariablesEnvWhitelist: ['GIT_COMMIT_SHORT', 'GIT_TAGS']
gitVariablesTagsWhitelist: ['GIT_REPOSITORY', 'GIT_COMMIT_LONG']
If you have multiple git tags, you'll run into issues when adding them as AWS tags, so you'll need to exclude them from the whitelist.
yamlcustom:
gitDescription: ${git:repository} - ${git:branch} - ${git:tags}
functions:
processEventBatch:
name: ${self:provider.stage}-${self:service}-process-event-batch
description: ${self:custom.gitDescription}
processEventBatch2:
name: ${self:provider.stage}-${self:service}-process-event-batch-2
description: ${self:custom.gitDescription}
plugins:
- serverless-plugin-git-variables
resources:
Description: >
${self:service} ${git:branch}:${git:sha1}
https://github.com/jacob-meacham/serverless-plugin-git-variables
${git:message}
`Available variables
* git:repository - name of the git repository
* git:sha1 - hash of the current commit
* git:branch - name of the current branch
* git:isDirty - true if the workspace is currently dirty
* git:describe / git:describeLight - see below
* git:user - The user's name
* git:email - The user's email
* git:tags - The tag pointing to the current commit
* git:message - Full git commit message
* git:messageSubject - Only the suject of the message, as
git log -1 --pretty=%s
* git:messageBody - Only the body of the message, as git log -1 --pretty=%bdescribe and describeLight
The describe (${git:describe}) and the describeLight (${git:describeLight}) variables are both used to return the most recent tag of the repo. However the difference is that whilst describe evaluates to git describe --always, the describeLight variable evaluates to git describe --always --tags.
--always will ensure that if no tags are present, the commit hash is shown as a fallback option. (See git describe documentation for more information).Annotated tags are shown by both
describe and describeLight, only describeLight will show lightweight tags (such as those generated when using GitHub's releases feature).For more information on annotated and lightweight tags go to the git documentation on tagging.
tags
The tags (
${git:tags}) is used to get info about which git tags (separated by ::) are pointing to current commit and if none it will show commit ID as fallback.Version History
* 5.2.0
- Support for Serverless v2/v3. Switch to github actions
* 5.1.0
- Add messageSubject/messageBody (Thanks @vhenzl)
* 5.0.1
- Fix module export (Thanks @nason)
* 5.0.0
- Rely on a more modern version of Node, which allows removal of runtime dependencies
* 4.1.0
- Fix sporadic failure with git write-tree (Thanks to @navrkald and @james-hu)
* 4.0.0
- Change tags` separator from ',' to '::' to conform to the AWS tag regex