# serverless-git-version-plugin

> Save latest git commit hash into version.txt file and environment variable

Latest version **1.0.6** (published 2018-02-06) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install serverless-git-version-plugin
pnpm add serverless-git-version-plugin
yarn add serverless-git-version-plugin
bun add serverless-git-version-plugin
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.0.6 |
| Published | 2018-02-06 |
| First published | 2018-01-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Author | VB |
| Maintainers | mspclaims |

## Links

- npm: https://www.npmjs.com/package/serverless-git-version-plugin
- npm.io page: https://npm.io/package/serverless-git-version-plugin

## Dependencies (4)

- [fs](https://npm.io/package/fs.md) 0.0.1-security
- [path](https://npm.io/package/path.md) ^0.12.7
- [app-root-path](https://npm.io/package/app-root-path.md) ^2.0.1
- [child_process](https://npm.io/package/child_process.md) ^1.0.2

## Recent versions

- 1.0.6 (latest) — 2018-02-06
- 1.0.5 — 2018-01-30
- 1.0.4 — 2018-01-30
- 1.0.3 — 2018-01-30
- 1.0.2 — 2018-01-30
- 1.0.0 — 2018-01-25

## README

# serverless-git-version-plugin
[![serverless](http://public.serverless.com/badges/v3.svg)](http://www.serverless.com)

This plugin works with [serverless](https://serverless.com/) and [serverless-offline](https://github.com/dherault/serverless-offline). 
It generates files version.txt and branch.txt in the root folder of your project
by parsing the output of
* git rev-parse HEAD
* git branch --list


## Quickstart
* run **npm install serverless-git-version-plugin**
* update your serverless.yml to include reference to plugin
> `plugins:`
>`  	- serverless-git-version-plugin`
* update your serverless.yml to read version into evironment variable
>`environment:`
>`	version: ${file(./version.txt)}`
>`	branch: ${file(./branch.txt)}`
* start your service **sls offline** or deploy it **sls deploy**
* now version your lambdas can read version from `process.env.version`

## Usage in the real world
See the example below:
	
    module.exports.version = function(event, context, callback) {
    	let results={"code_version":"","git_branch":""};   
    	if (process.env.version) {
    		results.code_version = process.env.version;
    	}
		if (process.env.branch) {
    		results.git_branch = process.env.branch;
    	}
        callback(null, {body: JSON.stringify(results)});
    }

---
_Source: https://npm.io/package/serverless-git-version-plugin · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
