Skip to content

Commit

Permalink
feat(gradle): add help metadata (#26810)
Browse files Browse the repository at this point in the history
<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #
  • Loading branch information
xiongemi authored Jul 12, 2024
1 parent 638647d commit fc1c049
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ export default function TargetConfigurationDetails({
getDisplayHeaderFromTargetConfiguration(targetConfiguration);
const configurations = targetConfiguration.configurations;

const shouldRenderOptions =
const shouldRenderOptions: boolean =
options &&
(typeof options === 'object' ? Object.keys(options).length : true);
(typeof options === 'object' ? Object.keys(options).length > 0 : true);

const shouldRenderConfigurations =
configurations &&
Expand Down Expand Up @@ -137,7 +137,7 @@ export default function TargetConfigurationDetails({
</div>
)}

{shouldRenderOptions ? (
{shouldRenderOptions || targetConfiguration.metadata?.help ? (
<>
<h4 className="mb-4">
<Tooltip
Expand All @@ -149,32 +149,34 @@ export default function TargetConfigurationDetails({
</span>
</Tooltip>
</h4>
<div className="mb-4">
<FadingCollapsible>
<JsonCodeBlock
data={options}
copyTooltipText="Copy Options"
renderSource={(propertyName: string) => (
<TargetSourceInfo
className="flex min-w-0 pl-4"
propertyKey={`targets.${targetName}.options.${propertyName}`}
sourceMap={sourceMap}
/>
)}
{shouldRenderOptions ? (
<div className="mb-4">
<FadingCollapsible>
<JsonCodeBlock
data={options}
copyTooltipText="Copy Options"
renderSource={(propertyName: string) => (
<TargetSourceInfo
className="flex min-w-0 pl-4"
propertyKey={`targets.${targetName}.options.${propertyName}`}
sourceMap={sourceMap}
/>
)}
/>
</FadingCollapsible>
</div>
) : null}
{targetConfiguration.metadata?.help && (
<div className="mb-4">
<ShowOptionsHelp
targetConfiguration={targetConfiguration}
projectName={projectName}
targetName={targetName}
/>
</FadingCollapsible>
</div>
<div className="mb-4">
<ShowOptionsHelp
targetConfiguration={targetConfiguration}
projectName={projectName}
targetName={targetName}
/>
</div>
</div>
)}
</>
) : (
''
)}
) : null}

{targetConfiguration.inputs && (
<div className="group">
Expand Down
60 changes: 60 additions & 0 deletions packages/gradle/src/plugin/nodes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,16 @@ describe('@nx/gradle/plugin', () => {
"^production",
],
"metadata": {
"help": {
"command": "./gradlew help --task proj:test",
"example": {
"options": {
"args": [
"--rerun",
],
},
},
},
"technologies": [
"gradle",
],
Expand Down Expand Up @@ -168,6 +178,16 @@ describe('@nx/gradle/plugin', () => {
"^production",
],
"metadata": {
"help": {
"command": "./gradlew help --task proj:test",
"example": {
"options": {
"args": [
"--rerun",
],
},
},
},
"technologies": [
"gradle",
],
Expand Down Expand Up @@ -256,6 +276,16 @@ describe('@nx/gradle/plugin', () => {
"^production",
],
"metadata": {
"help": {
"command": "./gradlew help --task proj:test",
"example": {
"options": {
"args": [
"--rerun",
],
},
},
},
"technologies": [
"gradle",
],
Expand All @@ -282,6 +312,16 @@ describe('@nx/gradle/plugin', () => {
],
"metadata": {
"description": "Runs Gradle Tests in CI",
"help": {
"command": "./gradlew help --task proj:test",
"example": {
"options": {
"args": [
"--rerun",
],
},
},
},
"nonAtomizedTarget": "test",
"technologies": [
"gradle",
Expand All @@ -300,6 +340,16 @@ describe('@nx/gradle/plugin', () => {
],
"metadata": {
"description": "Runs Gradle test nested/nested/proj/src/test/java/test/test.java in CI",
"help": {
"command": "./gradlew help --task proj:test",
"example": {
"options": {
"args": [
"--rerun",
],
},
},
},
"technologies": [
"gradle",
],
Expand All @@ -317,6 +367,16 @@ describe('@nx/gradle/plugin', () => {
],
"metadata": {
"description": "Runs Gradle test nested/nested/proj/src/test/java/test/test1.java in CI",
"help": {
"command": "./gradlew help --task proj:test",
"example": {
"options": {
"args": [
"--rerun",
],
},
},
},
"technologies": [
"gradle",
],
Expand Down
24 changes: 24 additions & 0 deletions packages/gradle/src/plugin/nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,14 @@ async function createGradleTargets(
dependsOn: dependsOnMap[task.name],
metadata: {
technologies: ['gradle'],
help: {
command: `${getGradleExecFile()} help --task ${taskCommandToRun}`,
example: {
options: {
args: ['--rerun'],
},
},
},
},
...(outputs && outputs.length ? { outputs } : {}),
};
Expand Down Expand Up @@ -335,6 +343,14 @@ function getTestCiTargets(
metadata: {
technologies: ['gradle'],
description: `Runs Gradle test ${testFile} in CI`,
help: {
command: `${getGradleExecFile()} help --task ${taskCommandToRun}`,
example: {
options: {
args: ['--rerun'],
},
},
},
},
...(outputs && outputs.length > 0 ? { outputs } : {}),
};
Expand All @@ -356,6 +372,14 @@ function getTestCiTargets(
technologies: ['gradle'],
description: 'Runs Gradle Tests in CI',
nonAtomizedTarget: testTargetName,
help: {
command: `${getGradleExecFile()} help --task ${taskCommandToRun}`,
example: {
options: {
args: ['--rerun'],
},
},
},
},
};
targetGroups[targetGroupName].push(ciTargetName);
Expand Down
2 changes: 1 addition & 1 deletion packages/nx/src/command-line/graph/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1220,6 +1220,6 @@ function getHelpTextFromTarget(
throw new Error(`No help command found for ${projectName}:${targetName}`);

return execSync(command, {
cwd: join(workspaceRoot, project.data.root),
cwd: target.options?.cwd ?? workspaceRoot,
}).toString();
}

0 comments on commit fc1c049

Please sign in to comment.