Skip to content

Commit

Permalink
avoid collision of helm release name (#597)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkarlsen authored May 16, 2022
1 parent b66afde commit 4b0110d
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 6 deletions.
3 changes: 2 additions & 1 deletion __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import * as core from '@actions/core'
import * as exec from '@actions/exec'
import * as github from '@actions/github'
import {beforeEach} from 'jest-circus'
import {Context} from '@actions/github/lib/context'

let inputs = {} as any

Expand All @@ -30,5 +29,7 @@ beforeEach(() => {
test('test runs', async () => {
process.env['GITHUB_REPOSITORY'] = 'someOrg/someRepo'
github.context.runNumber = 11
github.context.runId = 12
github.context.job = 'someJob'
await expect(run()).resolves.not.toThrow
})
52 changes: 51 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1073,6 +1073,34 @@ function onceStrict (fn) {
}


/***/ }),

/***/ 53:
/***/ (function(module) {

"use strict";

const OFFSET_BASIS_32 = 2166136261;

const fnv1a = string => {
let hash = OFFSET_BASIS_32;

for (let i = 0; i < string.length; i++) {
hash ^= string.charCodeAt(i);

// 32-bit FNV prime: 2**24 + 2**8 + 0x93 = 16777619
// Using bitshift for accuracy and performance. Numbers in JS suck.
hash += (hash << 1) + (hash << 4) + (hash << 7) + (hash << 8) + (hash << 24);
}

return hash >>> 0;
};

module.exports = fnv1a;
// TODO: remove this in the next major version, refactor the whole definition to:
module.exports.default = fnv1a;


/***/ }),

/***/ 70:
Expand Down Expand Up @@ -1828,11 +1856,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.run = void 0;
const core = __importStar(__webpack_require__(470));
const exec = __importStar(__webpack_require__(986));
const github = __importStar(__webpack_require__(469));
const string_hash_1 = __importDefault(__webpack_require__(720));
const OUTPUT_KEY_RELEASE_NAME = 'releaseName';
const STATE_KEY_RELEASE_NAME = OUTPUT_KEY_RELEASE_NAME;
function run() {
Expand Down Expand Up @@ -1877,7 +1909,9 @@ function cleanup() {
});
}
function getReleaseName(chart) {
return `${chart}-${github.context.repo.repo}-${github.context.runNumber}`;
const prefix = `${chart}-${github.context.repo.repo}`;
const suffix = `${github.context.workflow}-${github.context.job}-${github.context.runId}-${github.context.runNumber}`;
return `${prefix}-${(0, string_hash_1.default)(suffix)}`;
}
run();

Expand Down Expand Up @@ -6800,6 +6834,22 @@ class Deprecation extends Error {
exports.Deprecation = Deprecation;


/***/ }),

/***/ 720:
/***/ (function(module, __unusedexports, __webpack_require__) {

"use strict";

const fnv1a = __webpack_require__(53);

const stringHash = string => fnv1a(string);

module.exports = stringHash;
// TODO: remove this in the next major version
module.exports.default = stringHash;


/***/ }),

/***/ 742:
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

35 changes: 34 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"dependencies": {
"@actions/core": "^1.8.2",
"@actions/exec": "^1.1.1",
"@actions/github": "^5.0.3"
"@actions/github": "^5.0.3",
"@sindresorhus/string-hash": "^1.2.0"
},
"devDependencies": {
"@types/jest": "^27.5.0",
Expand Down
6 changes: 5 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as core from '@actions/core'
import * as exec from '@actions/exec'
import * as github from '@actions/github'
import stringHash from '@sindresorhus/string-hash'
const OUTPUT_KEY_RELEASE_NAME = 'releaseName'
const STATE_KEY_RELEASE_NAME = OUTPUT_KEY_RELEASE_NAME

Expand Down Expand Up @@ -46,7 +47,10 @@ async function cleanup(): Promise<void> {
}

function getReleaseName(chart: string): string {
return `${chart}-${github.context.repo.repo}-${github.context.runNumber}`
const prefix = `${chart}-${github.context.repo.repo}`
const suffix = `${github.context.workflow}-${github.context.job}-${github.context.runId}-${github.context.runNumber}`

return `${prefix}-${stringHash(suffix)}`
}

run()

0 comments on commit 4b0110d

Please sign in to comment.