-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
generate a single caching hash (#60)
* generate a single caching hash * add backwards compatibility * print out key info * add cache step test setup * add cache step test setup * add tests for caching step * build source files * improve messaging * commit changed source files * add comment
- Loading branch information
Showing
12 changed files
with
46,144 additions
and
70 deletions.
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { hashKey } from './hashing-utils'; | ||
import * as path from 'path'; | ||
|
||
console.log(hashKey); | ||
describe('hashing-utils', () => { | ||
const testDir = path.join(__dirname, 'test-files'); | ||
it('should hash a single file', () => { | ||
expect(hashKey(`${testDir}/yarn.lock`)).toEqual( | ||
'6ef0d64a2ac614adc8dac86db67244e77cdad3253a65fb8e2b7c11ed4cbb466a', | ||
); | ||
}); | ||
|
||
it('should hash multiple files', () => { | ||
expect(hashKey(`${testDir}/yarn.lock | ${testDir}/main.js`)).toEqual( | ||
'e5c39d066ffa2cd0d38165a018aaac3118b1c81d8f4631335e0f19cda6fa8e65', | ||
); | ||
}); | ||
|
||
it('should hash simple strings', () => { | ||
expect( | ||
hashKey(`${testDir}/yarn.lock | ${testDir}/main.js | "test1"`), | ||
).toEqual( | ||
'16b5f107c209ad4d76dffc803beba37b7e836ca2ca229731c8bc88040874a003', | ||
); | ||
expect( | ||
hashKey(`${testDir}/yarn.lock | ${testDir}/main.js | "test2"`), | ||
).toEqual( | ||
'226f813c92638665c8daa0920cfb83e5f33732f8843042deee348032a1abee40', | ||
); | ||
}); | ||
}); |
This file contains 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/* eslint-disable */ | ||
export default { | ||
displayName: 'cache-step', | ||
preset: 'ts-jest', | ||
}; |
This file contains 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 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 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 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,9 +1,10 @@ | ||
{ | ||
"name": "cache-step", | ||
"version": "0.0.0", | ||
"main": "output/main.js", | ||
"devDependencies": {}, | ||
"scripts": { | ||
"build": "npx esbuild main.ts --bundle --platform=node --target=node20 --outfile=output/main.js && npx esbuild post.ts --bundle --platform=node --target=node20 --outfile=output/post.js" | ||
} | ||
} | ||
"name": "cache-step", | ||
"version": "0.0.0", | ||
"main": "output/main.js", | ||
"devDependencies": {}, | ||
"scripts": { | ||
"build": "npx esbuild main.ts --bundle --platform=node --target=node20 --outfile=output/main.js && npx esbuild post.ts --bundle --platform=node --target=node20 --outfile=output/post.js", | ||
"test": "npx jest --cwd=workflow-steps/cache" | ||
} | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
const { execSync } = require('child_process'); | ||
const { existsSync, readFileSync, writeFileSync } = require('fs'); | ||
|
||
const command = getInstallCommand(); | ||
if (command) { | ||
console.log(`Installing dependencies using ${command.split(' ')[0]}`); | ||
console.log(` Running command: ${command}\n`); | ||
execSync(command, { stdio: 'inherit' }); | ||
patchJest(); | ||
} else { | ||
throw new Error( | ||
'Could not find lock file. Please ensure you have a lock file before running this command.', | ||
); | ||
} | ||
|
||
function getInstallCommand() { | ||
if (existsSync('package-lock.json')) { | ||
return 'npm ci --legacy-peer-deps'; | ||
} else if (existsSync('yarn.lock')) { | ||
const [major] = execSync(`yarn --version`, { | ||
encoding: 'utf-8', | ||
}) | ||
.trim() | ||
.split('.'); | ||
|
||
const useBerry = +major >= 2; | ||
if (useBerry) { | ||
return 'yarn install --immutable'; | ||
} else { | ||
return 'yarn install --frozen-lockfile'; | ||
} | ||
} else if (existsSync('pnpm-lock.yaml') || existsSync('pnpm-lock.yml')) { | ||
return 'pnpm install --frozen-lockfile'; | ||
} | ||
} | ||
|
||
function patchJest() { | ||
try { | ||
const path = | ||
'node_modules/jest-config/build/readConfigFileAndSetRootDir.js'; | ||
const contents = readFileSync(path, 'utf-8'); | ||
writeFileSync( | ||
path, | ||
contents.replace( | ||
"const tsNode = await import('ts-node');", | ||
"require('ts-node'); const tsNode = await import('ts-node');", | ||
), | ||
); | ||
} catch (e) { | ||
if (process.env.NX_VERBOSE_LOGGING == 'true') { | ||
console.log(e); | ||
} | ||
console.log('no need to patch jest'); | ||
} | ||
} |
Oops, something went wrong.