Skip to content

Commit

Permalink
reimplement devserver workflow (#27612)
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima authored Oct 18, 2024
1 parent a4765c7 commit dee8a44
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 43 deletions.
11 changes: 2 additions & 9 deletions .blueprint/generate-sample/generator.mts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export default class extends BaseGenerator {
const sample = await generateSample(this.sampleName, {
destProjectFolder: this.projectFolder,
fork: false,
entity: this.entitiesSample,
});
assert.ok(sample, `Sample ${this.sampleName} not found`);

Expand Down Expand Up @@ -103,20 +104,12 @@ export default class extends BaseGenerator {
const entitiesFiles = entitiesByType[this.entitiesSample];
if (entitiesFiles) {
this.jhipsterConfig.entities = entitiesFiles;
/*
this.log.info(`Copying entities ${this.entitiesSample} (${entitiesFiles})`);
this.copyTemplate(
entitiesFiles.map(entity => `.jhipster/${entity}.json`),
this.projectFolder,
{ noGlob: true, fromBasePath: this.templatePath('../../../test-integration/samples/') },
);
*/
entitiesFiles.forEach(entity =>
this.copyTemplate(
`../../../test-integration/samples/.jhipster/${entity}.json`,
`${this.projectFolder}/.jhipster/${entity}.json`,
{ noGlob: true },
),
);
}
await this.composeWithJHipster(GENERATOR_APP, { generatorOptions: { destinationRoot: this.projectFolder } });
},
Expand Down
2 changes: 1 addition & 1 deletion .blueprint/github-build-matrix/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default {
type: String,
},
scope: 'generator',
choices: ['testcontainers'],
choices: ['testcontainers', 'dev-server'],
},
},
} as const satisfies JHipsterCommandDefinition;
17 changes: 17 additions & 0 deletions .blueprint/github-build-matrix/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import BaseGenerator from '../../generators/base/index.js';
import { setGithubTaskOutput } from '../../lib/testing/index.js';
import { convertToGitHubMatrix } from './support/github-ci-matrix.js';
import { dockerComposeMatrix } from './samples/docker-compose-integration.js';
import { getGitChanges } from './support/git-changes.js';
import { devServerMatrix } from './samples/dev-server.js';

export default class extends BaseGenerator {
workflow;
Expand All @@ -15,6 +17,21 @@ export default class extends BaseGenerator {
async buildMatrix() {
if (this.workflow === 'docker-compose-integration') {
setGithubTaskOutput('matrix', JSON.stringify(convertToGitHubMatrix(dockerComposeMatrix), null, 2));
} else if (this.workflow === 'dev-server') {
const { devserverCi, client, angular, react, vue } = await getGitChanges();
const matrix = {};
if (devserverCi || client || angular) {
// Object.assign(matrix, devServerMatrix.angular);
}
if (devserverCi || client || react) {
Object.assign(matrix, devServerMatrix.react);
}
if (devserverCi || client || vue) {
// Object.assign(matrix, devServerMatrix.vue);
}
const githubMatrix = convertToGitHubMatrix(matrix);
setGithubTaskOutput('matrix', JSON.stringify(githubMatrix, null, 2));
setGithubTaskOutput('empty-matrix', githubMatrix.include.length === 0);
}
},
});
Expand Down
20 changes: 20 additions & 0 deletions .blueprint/github-build-matrix/samples/dev-server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export const devServerMatrix = {
angular: {
'ng-default': {
sample: 'samples/ng-default',
args: '--sample-yorc-folder --entities-sample sqllight',
},
},
react: {
'react-default': {
sample: 'samples/react-default',
args: '--sample-yorc-folder --entities-sample sqllight',
},
},
vue: {
'vue-default': {
sample: 'samples/vue-default',
args: '--sample-yorc-folder --entities-sample sqllight',
},
},
};
28 changes: 28 additions & 0 deletions .blueprint/github-build-matrix/support/git-changes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { fileURLToPath } from 'url';
import { minimatch } from 'minimatch';
import { simpleGit } from 'simple-git';

export const getGitChanges = async () => {
const git = simpleGit({ baseDir: fileURLToPath(new URL('../../', import.meta.url).href) });
const summary = await git.diffSummary({ '@~1': null });
const files = summary.files.map(({ file }) => file);
const hasPatternChanges = (pattern: string) => files.some(file => minimatch(file, pattern, { dot: true }));
return {
files,
base:
hasPatternChanges('lib/**') ||
hasPatternChanges('generators/*') ||
hasPatternChanges('generators/{base*,bootstrap*,git,jdl,project-name}/**'),
ci:
hasPatternChanges('.blueprint/**') ||
hasPatternChanges('.github/{actions,workflows}/**') ||
hasPatternChanges('generators/{docker-compose,kubernetes*,workspaces}/**'),
devserverCi: hasPatternChanges('.github/workflows/devserver.yml'),
common: hasPatternChanges('generators/{app,common,cypress,docker,languages}/**'),
client: hasPatternChanges('generators/{client,init,javascript}/**'),
angular: hasPatternChanges('generators/angular/**'),
react: hasPatternChanges('generators/react/**'),
vue: hasPatternChanges('generators/vue/**'),
java: hasPatternChanges('generators/{cucumber,feign-client,gatling,gradle,java,liquibase,maven,server,spring*}/**'),
};
};
2 changes: 2 additions & 0 deletions .blueprint/github-build-matrix/support/github-ci-matrix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ type GitHubMatrix = {
'java-version': string;
'default-environment': string;
'job-name': string;
sample: string;
args: string;
};

Expand All @@ -31,6 +32,7 @@ export const convertToGitHubMatrix = (matrix: Record<string, any>): GitHubMatrix
return {
include: Object.entries(matrix).map(([key, value]) => ({
'job-name': key,
sample: key,
...defaultEnvironment,
...value,
})),
Expand Down
48 changes: 19 additions & 29 deletions .github/workflows/devserver.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ on:
- '.github/workflows/devserver.yml'
- 'generators/angular/**'
- 'generators/client/**'
- 'generators/javascript/**'
- 'generators/react/**'
- 'generators/vue/**'
- 'generators/*'
Expand All @@ -49,15 +50,13 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: 2
- name: 'Build matrix'
id: build
uses: ./.github/actions/build-matrix
with:
workflow-file-prefix: devserver
- run: npm ci --ignore-scripts
- id: build
run: bin/jhipster.cjs github-build-matrix dev-server
applications:
name: ${{ matrix.app-sample }}
name: ${{ matrix.job-name }}
needs: build-matrix
runs-on: ubuntu-20.04
runs-on: ${{ matrix.os }}
defaults:
run:
working-directory: ${{ github.workspace }}/app
Expand All @@ -75,44 +74,35 @@ jobs:
with:
path: generator-jhipster
fetch-depth: 2
- name: 'SETUP: environment'
id: setup
uses: ./generator-jhipster/.github/actions/setup
with:
application-sample: ${{ matrix.setup-application-sample }}
entities-sample: ${{ matrix.setup-entities-sample }}
jdl-entities-sample: ${{ matrix.setup-jdl-entities-sample }}
jdl-sample: ${{ matrix.setup-jdl-sample }}
application-environment: ${{ matrix.setup-application-environment }}
application-packaging: ${{ matrix.setup-application-packaging }}
- uses: jhipster/actions/setup-runner@v0
with:
node-version: ${{ steps.setup.outputs.node-version }}
java-version: ${{ steps.setup.outputs.java-version }}
node-version: ${{ matrix.node-version }}
java-version: ${{ matrix.java-version }}
npm-version: ${{ matrix.npm-version }}
maven-cache: true
binary-dir: ${{ github.workspace }}/generator-jhipster/bin
#----------------------------------------------------------------------
# Install JHipster and generate project+entities
#----------------------------------------------------------------------
- name: 'GENERATION: install JHipster'
run: $JHI_SCRIPTS/10-install-jhipster.sh
- name: 'GENERATION: config'
run: $JHI_SCRIPTS/11-generate-config.sh
- run: npm ci --ignore-scripts
working-directory: ${{ github.workspace }}/generator-jhipster
- name: 'GENERATION: project'
run: $JHI_SCRIPTS/12-generate-project.sh ${{ matrix.extra-args }} ${{ matrix.new-extra-args }}
- name: 'GENERATION: jhipster info'
run: $JHI_SCRIPTS/14-jhipster-info.sh
run: jhipster.cjs generate-sample ${{ matrix.sample }} --skip-jhipster-dependencies --skip-install ${{ matrix.args }}
- run: jhipster.cjs info
#----------------------------------------------------------------------
# Launch tests
#----------------------------------------------------------------------
- name: 'E2E: Run'
id: e2e
run: ./npmw run e2e:devserver --if-present
run: |
./npmw install
./npmw run e2e:devserver --if-present
- name: 'E2E: Store failure screenshots'
uses: actions/upload-artifact@v4
if: always() && steps.e2e.outcome == 'failure'
with:
name: screenshots-${{ matrix.app-sample }}
path: ${{ steps.setup.outputs.application-path }}/*/cypress/screenshots
name: screenshots-${{ matrix.job-name }}
path: ${{ github.workspace }}/app/*/cypress/screenshots
check-dev-server:
permissions:
contents: none
Expand Down
4 changes: 2 additions & 2 deletions generators/base-core/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1372,8 +1372,8 @@ templates: ${JSON.stringify(existingTemplates, null, 2)}`;
/**
* Create a simple-git instance using current destinationPath as baseDir.
*/
createGit() {
return simpleGit({ baseDir: this.destinationPath() }).env({
createGit(options?: Parameters<typeof simpleGit>[0]) {
return simpleGit({ baseDir: this.destinationPath(), ...options }).env({
...process.env,
LANG: 'en',
});
Expand Down
3 changes: 1 addition & 2 deletions generators/vue/templates/package.json.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@
"vitest-sonar-reporter": "<%= nodeDependencies['vitest-sonar-reporter'] %>"
},
"engines": {
"node": ">=<%= nodeVersion %>",
"npm": ">= 6.14.4"
"node": ">=<%= nodeVersion %>"
},
"config": {
"default_environment": "prod"
Expand Down

0 comments on commit dee8a44

Please sign in to comment.