├── .github
└── workflows
│ └── publish.yml
├── .gitignore
├── .npmignore
├── LICENSE
├── README.md
├── fixture
├── .npmrc
├── chart
│ └── Chart.yaml
├── package-lock.json
└── package.json
├── index.js
├── package-lock.json
└── package.json
/.github/workflows/publish.yml:
--------------------------------------------------------------------------------
1 | name: Node.js Package
2 | on:
3 | push:
4 | tags:
5 | - '*'
6 | jobs:
7 | build:
8 | runs-on: ubuntu-latest
9 | steps:
10 | - uses: actions/checkout@v2
11 | - uses: actions/setup-node@v2
12 | with:
13 | node-version: '18'
14 | registry-url: 'https://registry.npmjs.org'
15 | - run: npm install
16 | - run: npm publish
17 | env:
18 | NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | .github
2 | fixture
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) Intility AS
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | 
3 | @intility/helm-version
4 |
5 |
6 |
7 | A tool for setting a Helm charts appVersion
based on the package.json
version
field.
8 |
9 | To be used with npm version
.
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 | ## Usage
22 |
23 | Install with
24 |
25 | ```shell
26 | npm install @intility/helm-version
27 | ```
28 |
29 | Add a `version` script to your `package.json`
30 |
31 | ```json
32 | {
33 | "scripts": {
34 | "version": "helm-version path/to/chart && git add path/to/chart/Chart.yaml"
35 | }
36 | }
37 | ```
38 |
39 | You can now call `npm version` as usual to version your app,
40 | and the `appVersion` field will be automatically updated and added to the git commit and tag!
41 |
42 | Alternatively, you can run it manually
43 |
44 | ```shell
45 | helm-version
46 | ```
47 |
48 | Prefix is optional, and defaults to `v`.
49 | This is because `npm version` prefixes the git tag with `v`.
50 |
--------------------------------------------------------------------------------
/fixture/.npmrc:
--------------------------------------------------------------------------------
1 | git-tag-version=false
2 |
--------------------------------------------------------------------------------
/fixture/chart/Chart.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: v2
2 | name: fixture
3 | description: A Helm chart for Kubernetes
4 |
5 | # A chart can be either an 'application' or a 'library' chart.
6 | #
7 | # Application charts are a collection of templates that can be packaged into versioned archives
8 | # to be deployed.
9 | #
10 | # Library charts provide useful utilities or functions for the chart developer. They're included as
11 | # a dependency of application charts to inject those utilities and functions into the rendering
12 | # pipeline. Library charts do not define any templates and therefore cannot be deployed.
13 | type: application
14 |
15 | # This is the chart version. This version number should be incremented each time you make changes
16 | # to the chart and its templates, including the app version.
17 | # Versions are expected to follow Semantic Versioning (https://semver.org/)
18 | version: 0.1.0
19 |
20 | # This is the version number of the application being deployed. This version number should be
21 | # incremented each time you make changes to the application. Versions are not expected to
22 | # follow Semantic Versioning. They should reflect the version the application is using.
23 | # It is recommended to use it with quotes.
24 | appVersion: "v0.5.0"
25 |
--------------------------------------------------------------------------------
/fixture/package-lock.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "fixture",
3 | "version": "0.6.0",
4 | "lockfileVersion": 2,
5 | "requires": true,
6 | "packages": {
7 | "": {
8 | "name": "fixture",
9 | "version": "0.6.0",
10 | "dependencies": {
11 | "helm-version": "file:../"
12 | }
13 | },
14 | "..": {
15 | "name": "@intility/helm-version",
16 | "version": "1.2.1",
17 | "license": "MIT",
18 | "dependencies": {
19 | "read-pkg-up": "^8.0.0",
20 | "semver": "^7.3.8",
21 | "yaml": "^2.0.0-6"
22 | },
23 | "bin": {
24 | "helm-version": "index.js"
25 | }
26 | },
27 | "node_modules/helm-version": {
28 | "resolved": "..",
29 | "link": true
30 | }
31 | },
32 | "dependencies": {
33 | "helm-version": {
34 | "version": "file:..",
35 | "requires": {
36 | "read-pkg-up": "^8.0.0",
37 | "semver": "^7.3.8",
38 | "yaml": "^2.0.0-6"
39 | }
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/fixture/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "fixture",
3 | "private": true,
4 | "version": "0.5.0",
5 | "scripts": {
6 | "version": "helm-version chart"
7 | },
8 | "dependencies": {
9 | "helm-version": "file:../"
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 |
3 | import YAML from "yaml";
4 | import fs from "fs";
5 | import semver from "semver";
6 |
7 | if (process.argv.length > 2) {
8 | const [, , chartPath, prefix = "v"] = process.argv;
9 |
10 | const helmChart = YAML.parseDocument(
11 | fs.readFileSync(`${chartPath}/Chart.yaml`, "utf8")
12 | );
13 |
14 | // get app versions and calculate diff
15 | const prevAppVersion = helmChart.get("appVersion");
16 |
17 | // https://docs.npmjs.com/cli/v9/using-npm/scripts?v=true#packagejson-vars
18 | const newAppVersion = process.env.npm_package_version;
19 |
20 | // apply new appVersion
21 | helmChart.set("appVersion", prefix + newAppVersion);
22 |
23 | // detect diff in appVersion
24 | const appVersionDiff = semver.diff(prevAppVersion, newAppVersion);
25 |
26 | if (appVersionDiff !== null) {
27 | // get helm version and apply the app version diff
28 | const prevHelmVersion = helmChart.get("version");
29 | const newHelmVersion = semver.inc(prevHelmVersion, appVersionDiff);
30 |
31 | // apply the new versions
32 | helmChart.set("version", newHelmVersion);
33 | } else {
34 | console.log(
35 | "No difference in appVersion detected, not updating version field."
36 | );
37 | }
38 |
39 | fs.writeFileSync(`${chartPath}/Chart.yaml`, helmChart.toString());
40 | } else {
41 | console.log("Usage:");
42 | console.log('helm-version \n');
43 | process.exit(0);
44 | }
45 |
--------------------------------------------------------------------------------
/package-lock.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@intility/helm-version",
3 | "version": "1.3.1",
4 | "lockfileVersion": 2,
5 | "requires": true,
6 | "packages": {
7 | "": {
8 | "name": "@intility/helm-version",
9 | "version": "1.3.1",
10 | "license": "MIT",
11 | "dependencies": {
12 | "semver": "^7.5.2",
13 | "yaml": "^2.2.2"
14 | },
15 | "bin": {
16 | "helm-version": "index.js"
17 | }
18 | },
19 | "node_modules/lru-cache": {
20 | "version": "6.0.0",
21 | "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz",
22 | "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==",
23 | "dependencies": {
24 | "yallist": "^4.0.0"
25 | },
26 | "engines": {
27 | "node": ">=10"
28 | }
29 | },
30 | "node_modules/semver": {
31 | "version": "7.5.2",
32 | "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.2.tgz",
33 | "integrity": "sha512-SoftuTROv/cRjCze/scjGyiDtcUyxw1rgYQSZY7XTmtR5hX+dm76iDbTH8TkLPHCQmlbQVSSbNZCPM2hb0knnQ==",
34 | "dependencies": {
35 | "lru-cache": "^6.0.0"
36 | },
37 | "bin": {
38 | "semver": "bin/semver.js"
39 | },
40 | "engines": {
41 | "node": ">=10"
42 | }
43 | },
44 | "node_modules/yallist": {
45 | "version": "4.0.0",
46 | "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz",
47 | "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A=="
48 | },
49 | "node_modules/yaml": {
50 | "version": "2.2.2",
51 | "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.2.2.tgz",
52 | "integrity": "sha512-CBKFWExMn46Foo4cldiChEzn7S7SRV+wqiluAb6xmueD/fGyRHIhX8m14vVGgeFWjN540nKCNVj6P21eQjgTuA==",
53 | "engines": {
54 | "node": ">= 14"
55 | }
56 | }
57 | },
58 | "dependencies": {
59 | "lru-cache": {
60 | "version": "6.0.0",
61 | "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz",
62 | "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==",
63 | "requires": {
64 | "yallist": "^4.0.0"
65 | }
66 | },
67 | "semver": {
68 | "version": "7.5.2",
69 | "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.2.tgz",
70 | "integrity": "sha512-SoftuTROv/cRjCze/scjGyiDtcUyxw1rgYQSZY7XTmtR5hX+dm76iDbTH8TkLPHCQmlbQVSSbNZCPM2hb0knnQ==",
71 | "requires": {
72 | "lru-cache": "^6.0.0"
73 | }
74 | },
75 | "yallist": {
76 | "version": "4.0.0",
77 | "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz",
78 | "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A=="
79 | },
80 | "yaml": {
81 | "version": "2.2.2",
82 | "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.2.2.tgz",
83 | "integrity": "sha512-CBKFWExMn46Foo4cldiChEzn7S7SRV+wqiluAb6xmueD/fGyRHIhX8m14vVGgeFWjN540nKCNVj6P21eQjgTuA=="
84 | }
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@intility/helm-version",
3 | "version": "1.3.1",
4 | "description": "Automatically version helm charts with npm version.",
5 | "bin": {
6 | "helm-version": "index.js"
7 | },
8 | "type": "module",
9 | "scripts": {
10 | "test": "echo \"Error: no test specified\" && exit 1"
11 | },
12 | "homepage": "https://github.com/Intility/helm-version",
13 | "repository": {
14 | "type": "git",
15 | "url": "https://github.com/Intility/helm-version.git"
16 | },
17 | "publishConfig": {
18 | "registry": "https://registry.npmjs.org/",
19 | "access": "public"
20 | },
21 | "keywords": [
22 | "helm",
23 | "npm",
24 | "version"
25 | ],
26 | "author": "Intility",
27 | "license": "MIT",
28 | "dependencies": {
29 | "semver": "^7.5.2",
30 | "yaml": "^2.2.2"
31 | }
32 | }
33 |
--------------------------------------------------------------------------------