-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add more workflows support to github-build-matrix and migrate angular…
… workflow (#27624)
- Loading branch information
Showing
12 changed files
with
1,140 additions
and
73 deletions.
There are no files selected for viewing
894 changes: 894 additions & 0 deletions
894
.blueprint/github-build-matrix/__snapshots__/generator.spec.ts.snap
Large diffs are not rendered by default.
Oops, something went wrong.
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,30 @@ | ||
import { basename, dirname, join } from 'path'; | ||
import { fileURLToPath } from 'url'; | ||
import { before, describe, expect, it } from 'esmocha'; | ||
import { defaultHelpers as helpers, runResult } from '../../lib/testing/index.js'; | ||
import { shouldSupportFeatures } from '../../test/support/index.js'; | ||
import Generator from './generator.js'; | ||
|
||
const __filename = fileURLToPath(import.meta.url); | ||
const __dirname = dirname(__filename); | ||
|
||
const generator = basename(__dirname); | ||
|
||
describe(`generator - ${generator}`, () => { | ||
shouldSupportFeatures(Generator); | ||
|
||
for (const workflow of ['angular', 'devserver', 'react', 'docker-compose-integration', 'vue']) { | ||
describe(`with ${workflow}`, () => { | ||
before(async () => { | ||
await helpers.runJHipster(join(__dirname, 'index.ts'), { useEnvironmentBuilder: true }).withArguments(workflow); | ||
}); | ||
|
||
it('should set workflow value', () => { | ||
expect((runResult.generator as any).workflow).toBe(workflow); | ||
}); | ||
it('should match matrix value', () => { | ||
expect((runResult.generator as any).matrix).toMatchSnapshot(); | ||
}); | ||
}); | ||
} | ||
}); |
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
63 changes: 53 additions & 10 deletions
63
.blueprint/github-build-matrix/support/github-ci-matrix.ts
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,40 +1,83 @@ | ||
import { createHash } from 'node:crypto'; | ||
import { readFileSync } from 'node:fs'; | ||
import { join } from 'node:path'; | ||
import { RECOMMENDED_JAVA_VERSION, RECOMMENDED_NODE_VERSION } from '../../../generators/index.js'; | ||
import { getPackageRoot } from '../../../lib/index.js'; | ||
import { JAVA_COMPATIBLE_VERSIONS, JAVA_VERSION, NODE_VERSION } from '../../../generators/generator-constants.js'; | ||
|
||
type GitHubMatrix = { | ||
export type GitHubMatrix = { | ||
os: string; | ||
'node-version': string; | ||
'java-version': string; | ||
'default-environment': string; | ||
'job-name': string; | ||
sample: string; | ||
args: string; | ||
args?: string; | ||
'jwt-secret-key'?: string; | ||
}; | ||
|
||
type GitHubMatrixOutput = { | ||
export type GitHubMatrixRecord = Record<string, Partial<Omit<GitHubMatrix, 'job-name'>> & { disabled?: boolean }>; | ||
|
||
export type GitHubMatrixOutput = { | ||
include: GitHubMatrix[]; | ||
}; | ||
|
||
const NPM_VERSION = JSON.parse(readFileSync(join(getPackageRoot(), 'generators/common/resources/package.json'), 'utf-8')).devDependencies | ||
.npm; | ||
|
||
export const defaultEnvironment = { | ||
os: 'ubuntu-latest', | ||
'node-version': RECOMMENDED_NODE_VERSION, | ||
'java-version': RECOMMENDED_JAVA_VERSION, | ||
'npm-version': NPM_VERSION, | ||
'default-environment': 'prod', | ||
'jwt-secret-key': | ||
'ZjY4MTM4YjI5YzMwZjhjYjI2OTNkNTRjMWQ5Y2Q0Y2YwOWNmZTE2NzRmYzU3NTMwM2NjOTE3MTllOTM3MWRkMzcyYTljMjVmNmQ0Y2MxOTUzODc0MDhhMTlkMDIxMzI2YzQzZDM2ZDE3MmQ3NjVkODk3OTVmYzljYTQyZDNmMTQ=', | ||
}; | ||
|
||
export const defaultEnvironmentMatrix = { | ||
os: ['ubuntu-latest'], | ||
'node-version': [RECOMMENDED_NODE_VERSION], | ||
'java-version': [RECOMMENDED_JAVA_VERSION], | ||
'npm-version': [NPM_VERSION], | ||
'default-environment': ['prod'], | ||
}; | ||
|
||
export const convertToGitHubMatrix = (matrix: Record<string, any>): GitHubMatrixOutput => { | ||
const randomReproducibleValue = <Choice = any>(seed: string, choices: Choice[], options?: { useVersionPlaceholders?: boolean }): Choice => { | ||
const { useVersionPlaceholders } = options ?? {}; | ||
const index = createHash('shake256', { outputLength: 1 }).update(seed, 'utf8').digest('binary').charCodeAt(0) % choices.length; | ||
if (useVersionPlaceholders) { | ||
return `[${index}]` as any; | ||
} | ||
return choices[index]; | ||
}; | ||
|
||
const randomEnvironmentMatrix = (key: string, options: { useVersionPlaceholders?: boolean }) => { | ||
const { useVersionPlaceholders } = options; | ||
const javaVersion = randomReproducibleValue(`java-${key}`, [JAVA_VERSION, ...JAVA_COMPATIBLE_VERSIONS], { useVersionPlaceholders }); | ||
const nodeVersion = randomReproducibleValue(`node-${key}`, [NODE_VERSION, '18', '20'], { useVersionPlaceholders }); | ||
return { | ||
'job-name': `${key} (n${nodeVersion}/j${javaVersion})`, | ||
'java-version': javaVersion, | ||
'node-version': nodeVersion, | ||
}; | ||
}; | ||
|
||
export const convertToGitHubMatrix = ( | ||
matrix: GitHubMatrixRecord, | ||
options?: { randomEnvironment?: boolean; useVersionPlaceholders?: boolean }, | ||
): GitHubMatrixOutput => { | ||
const { randomEnvironment, useVersionPlaceholders } = options ?? {}; | ||
return { | ||
include: Object.entries(matrix).map(([key, value]) => ({ | ||
'job-name': key, | ||
sample: key, | ||
...defaultEnvironment, | ||
...value, | ||
})), | ||
include: Object.entries(matrix) | ||
.filter(([_key, value]) => !value.disabled) | ||
.map(([key, value]) => ({ | ||
'job-name': key, | ||
sample: key, | ||
...defaultEnvironment, | ||
...(useVersionPlaceholders ? { 'java-version': 'JAVA-VERSION', 'node-version': 'NODE-VERSION', 'npm-version': 'NPM-VERSION' } : {}), | ||
...value, | ||
...(randomEnvironment ? randomEnvironmentMatrix(key, { useVersionPlaceholders }) : {}), | ||
})), | ||
}; | ||
}; |
Oops, something went wrong.