-
Notifications
You must be signed in to change notification settings - Fork 21
fix(ci): compute the correct hash #438
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
90ccdc2
fix(ci): compute the correct hash
millotp 0412772
use crypto-js
millotp d6bd32e
use node crypto
millotp 036f6b3
toAbsolutePath
millotp e201573
Merge branch 'main' into fix/wrong-hash
millotp 01d3835
the cts needs algoliasarch-lite
millotp 96eab03
Merge branch 'main' into fix/wrong-hash
millotp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
/* eslint-disable no-console */ | ||
import type { HashElementOptions } from 'folder-hash'; | ||
import { hashElement } from 'folder-hash'; | ||
|
||
import { getNbGitDiff } from './utils'; | ||
|
@@ -19,17 +18,10 @@ const JS_CLIENT_FOLDER = 'clients/algoliasearch-client-javascript'; | |
const VARIABLES_TO_CHECK: Array<{ | ||
name: string; | ||
path: string[]; | ||
needHash?: boolean; | ||
hashOptions?: HashElementOptions; | ||
}> = [ | ||
{ | ||
name: 'GITHUB_ACTIONS_CHANGED', | ||
path: ['.github/actions', '.github/workflows', '.github/.cache_version'], | ||
needHash: true, | ||
hashOptions: { | ||
folders: { include: ['.github/actions', '.github/workflows'] }, | ||
files: { include: ['.github/.cache_version'] }, | ||
}, | ||
}, | ||
{ | ||
name: 'SPECS_CHANGED', | ||
|
@@ -46,10 +38,6 @@ const VARIABLES_TO_CHECK: Array<{ | |
{ | ||
name: 'SCRIPTS_CHANGED', | ||
path: ['scripts'], | ||
needHash: true, | ||
hashOptions: { | ||
folders: { include: ['scripts'] }, | ||
}, | ||
}, | ||
{ | ||
name: 'GENERATORS_CHANGED', | ||
|
@@ -106,6 +94,42 @@ const VARIABLES_TO_CHECK: Array<{ | |
}, | ||
]; | ||
|
||
// simple hash to reduce the hash length | ||
// reference: https://code-examples.net/en/q/7437cd | ||
millotp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
function hashCode(str: string): string { | ||
const p1 = 2654435761; | ||
const p2 = 1597334677; | ||
let h1 = 0xdeadbeef | 0; | ||
let h2 = 0x41c6ce57 | 0; | ||
for (let i = 0; i < str.length; i++) { | ||
const ch = str.charCodeAt(i); | ||
h1 = Math.imul(h1 + ch, p1); | ||
h2 = Math.imul(h2 + ch, p2); | ||
} | ||
h1 = Math.imul(h1 ^ (h1 >>> 16), p2); | ||
h2 = Math.imul(h2 ^ (h2 >>> 15), p1); | ||
return ((h2 & 2097151) * 4294967296 + h1).toString(16); | ||
} | ||
millotp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
async function computeCommonHash(): Promise<string> { | ||
const hashGA = await hashElement('../.github', { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok last comment I swear: do we maybe want to use the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if you want ahah, the CI is flaky anyway there will be some merge later |
||
encoding: 'hex', | ||
folders: { exclude: ['ISSUE_TEMPLATE'] }, | ||
files: { include: ['*.yml', '.cache_version'] }, | ||
}); | ||
const hashScripts = await hashElement('../scripts', { | ||
encoding: 'hex', | ||
folders: { exclude: ['docker', '__tests__'] }, | ||
}); | ||
const hashConfig = await hashElement('../', { | ||
encoding: 'hex', | ||
folders: { include: ['config'] }, | ||
files: { include: ['openapitools.json', 'clients.config.json'] }, | ||
}); | ||
|
||
return hashCode(`${hashGA.hash}-${hashScripts.hash}-${hashConfig.hash}`); | ||
} | ||
|
||
/** | ||
* Outputs variables used in the CI to determine if a job should run. | ||
*/ | ||
|
@@ -124,14 +148,10 @@ async function setRunVariables({ | |
|
||
console.log(`Found ${diff} changes for '${check.name}'`); | ||
console.log(`::set-output name=${check.name}::${diff}`); | ||
if (diff && check.needHash) { | ||
const hash = ( | ||
await hashElement('.', { encoding: 'hex', ...check.hashOptions }) | ||
).hash; | ||
console.log(`::set-output name=${check.name}_HASH::${hash}`); | ||
} | ||
} | ||
|
||
console.log(`::set-output name=COMMON_HASH::${await computeCommonHash()}`); | ||
|
||
console.log(`::set-output name=ORIGIN_BRANCH::${originBranch}`); | ||
} | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.