Skip to content

Commit

Permalink
Merge branch 'master' into feat/version-plans
Browse files Browse the repository at this point in the history
  • Loading branch information
fahslaj committed May 15, 2024
2 parents 563c933 + d581cef commit e99ae2d
Show file tree
Hide file tree
Showing 87 changed files with 1,216 additions and 901 deletions.
5 changes: 5 additions & 0 deletions community/approved-plugins.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
"description": "Nx plugin integrations with Vite.",
"url": "https://nx-plugins.netlify.app/"
},
{
"name": "nx-serverless-cdk",
"description": "Create CDK applications and construct libraries. Test and debug infrastructure code and AWS Lambda functions locally.",
"url": "https://github.com/castleadmin/nx-plugins/tree/main/nx-serverless-cdk/plugin"
},
{
"name": "@ago-dev/nx-aws-cdk-v2",
"description": "An nx plugin for the aws-cdk v2.",
Expand Down
10 changes: 8 additions & 2 deletions docs/generated/cli/show.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,18 @@ Show affected projects in the workspace, excluding end-to-end projects:
nx show projects --affected --exclude=*-e2e
```

Show detailed information about "my-app" in a json format.:
If in an interactive terminal, opens the project detail view. If not in an interactive terminal, defaults to JSON.:

```shell
nx show project my-app
```

Show detailed information about "my-app" in a json format.:

```shell
nx show project my-app --json
```

Show information about "my-app" in a human readable format.:

```shell
Expand Down Expand Up @@ -233,4 +239,4 @@ Show version number

Type: `boolean`

Show project details in the browser
Show project details in the browser. (default when interactive)
22 changes: 22 additions & 0 deletions docs/generated/manifests/ci.json
Original file line number Diff line number Diff line change
Expand Up @@ -1799,6 +1799,17 @@
"path": "/ci/reference/launch-templates",
"tags": []
},
{
"id": "custom-steps",
"name": "Custom Steps",
"description": "",
"mediaImage": "",
"file": "nx-cloud/reference/custom-steps",
"itemList": [],
"isExternal": false,
"path": "/ci/reference/custom-steps",
"tags": []
},
{
"id": "env-vars",
"name": "Environment Variables",
Expand Down Expand Up @@ -1859,6 +1870,17 @@
"path": "/ci/reference/launch-templates",
"tags": []
},
"/ci/reference/custom-steps": {
"id": "custom-steps",
"name": "Custom Steps",
"description": "",
"mediaImage": "",
"file": "nx-cloud/reference/custom-steps",
"itemList": [],
"isExternal": false,
"path": "/ci/reference/custom-steps",
"tags": []
},
"/ci/reference/env-vars": {
"id": "env-vars",
"name": "Environment Variables",
Expand Down
16 changes: 16 additions & 0 deletions docs/generated/manifests/menus.json
Original file line number Diff line number Diff line change
Expand Up @@ -6399,6 +6399,14 @@
"children": [],
"disableCollapsible": false
},
{
"name": "Custom Steps",
"path": "/ci/reference/custom-steps",
"id": "custom-steps",
"isExternal": false,
"children": [],
"disableCollapsible": false
},
{
"name": "Environment Variables",
"path": "/ci/reference/env-vars",
Expand Down Expand Up @@ -6442,6 +6450,14 @@
"children": [],
"disableCollapsible": false
},
{
"name": "Custom Steps",
"path": "/ci/reference/custom-steps",
"id": "custom-steps",
"isExternal": false,
"children": [],
"disableCollapsible": false
},
{
"name": "Environment Variables",
"path": "/ci/reference/env-vars",
Expand Down
10 changes: 8 additions & 2 deletions docs/generated/packages/nx/documents/show.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,18 @@ Show affected projects in the workspace, excluding end-to-end projects:
nx show projects --affected --exclude=*-e2e
```

Show detailed information about "my-app" in a json format.:
If in an interactive terminal, opens the project detail view. If not in an interactive terminal, defaults to JSON.:

```shell
nx show project my-app
```

Show detailed information about "my-app" in a json format.:

```shell
nx show project my-app --json
```

Show information about "my-app" in a human readable format.:

```shell
Expand Down Expand Up @@ -233,4 +239,4 @@ Show version number

Type: `boolean`

Show project details in the browser
Show project details in the browser. (default when interactive)
5 changes: 5 additions & 0 deletions docs/map.json
Original file line number Diff line number Diff line change
Expand Up @@ -1877,6 +1877,11 @@
"id": "launch-templates",
"file": "nx-cloud/reference/launch-templates"
},
{
"name": "Custom Steps",
"id": "custom-steps",
"file": "nx-cloud/reference/custom-steps"
},
{
"name": "Environment Variables",
"id": "env-vars",
Expand Down
110 changes: 110 additions & 0 deletions docs/nx-cloud/reference/custom-steps.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# Creating Custom Steps

While Nx Cloud provides several pre-built steps, you can create custom steps to suit your specific needs. Custom steps are defined by creating a new YAML file.

## Defining a Custom Step

To create a custom step, follow these steps:

1\. **Create a New YAML File**: Create a new YAML file in your `.nx/workflows` directory (e.g., `custom-step.yaml`)

{% callout type="note" title="Custom step file location" %}
Custom steps do not need to be in the `.nx/workflows` directory. However, they must be available on a public GitHub repository. You have a few options for organizing your custom steps:

- **Same Repository as your Nx Workspace**: Ideal for open-source projects where the Nx workspace is publicly accessible.
- **Create a Dedicated Repository**: Create a separate repository to store a collection of custom steps. This is useful for sharing steps across multiple projects or teams, or if your main Nx workspace is not on GitHub or is private.

{% /callout %}

2\. **Define the Step Template**: Below is an example of a custom step definition:

```yaml {% fileName=".nx/workflows/custom-step.yaml" %}
name: 'Custom Step'
description: 'This is a custom step that does XYZ.'
definition:
using: 'node'
main: './scripts/custom-script.js'
post: './scripts/post-custom-script.js'
inputs:
- name: 'input1'
description: 'Description for input1'
default: 'default_value'
required: true
- name: 'input2'
description: 'Description for input2'
required: false
```

### Explanation of Fields

- **name**:

- The name of the custom step.

- **description**:

- A description of what the custom step does.

- **definition**:

- **using**: The runtime environment. Supported values are `node` and `aggregate`.
- **node**: If `using` is set to `node`, then only `main` and `post` can be used.
- **aggregate**: If `using` is set to `aggregate`, then only `steps` can be used.
- **main**: Path to the main script to run (only if `using` is `node`).
- **post**: Path to the post script to run (only if `using` is `node`).
- runs before the agent is cleaned up
- **steps**: A list of sub-steps to be executed (only if `using` is `aggregate`). Steps follow the same definition as [launch templates](/ci/reference/launch-templates#launch-template-structure).

- **inputs**:
- **name**: The name of the input.
- **description**: A description of the input.
- **default**: Default value for the input.
- **required**: Whether the input is required.

### Using Inputs in Scripts

If your custom step has inputs, they can be accessed in scripts or JavaScript files using environment variables. Each input is prefixed with `NX_CLOUD_INPUT_`. For example, if you have an input called `input1`, you can access it in a JavaScript file like this:

```javascript
const input1 = process.env.NX_CLOUD_INPUT_input1;
console.log(`The value of input1 is: ${input1}`);
```

### Using Custom Steps in Launch Templates

Once you've defined your custom step, you can use it in your launch templates by referencing the custom step file. Here's an example:

{% callout type="check" title="Custom Step location" %}
When specifying the location for the custom step, you must include a branch or tag (e.g., `main`). Using a direct URL to the repository without a branch or tag will not work.
{% /callout %}

```yaml {% fileName=".nx/workflows/agents.yaml" %}
launch-templates:
custom-template:
resource-class: 'docker_linux_amd64/medium'
image: 'ubuntu22.04-node20.11-v7'
init-steps:
- name: Custom Step
uses: 'your-org/your-repo/main/.nx/workflows/custom-steps.yaml'
env:
CUSTOM_VAR: 'custom_value'
inputs:
input1: 'value1'
input2: 'value2'
```

{% callout type="note" title="Recommendation on Using Inputs vs. Env" %}
While you can use both `env` and `inputs` to pass values to custom steps, it is recommended to use `inputs` as they offer validation support, whereas `env` does not.
{% /callout %}

### Validating Custom Steps

Just like launch templates, you should validate your custom steps to ensure they are defined correctly. In your CI pipeline, use the `nx-cloud validate` command with the `--step-file` flag to ensure nobody merges in invalid changes to your step:

```shell
nx-cloud validate --workflow-file=./.nx/workflows/custom-steps.yaml --step-file
```

Ensure your custom steps are committed to your source control repository before running the validation.

By defining and organizing custom steps in this way, you can create highly tailored workflows that meet the specific needs of your projects and CI/CD pipelines.
2 changes: 1 addition & 1 deletion docs/nx-cloud/reference/launch-templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ launch-templates:

When defined, specifies an existing step file to be used. **Cannot be used when `script` is also defined**

You can find the [list of Nx Cloud reusable steps here](https://github.com/nrwl/nx-cloud-workflows/tree/main/workflow-steps).
You can find the [list of Nx Cloud reusable steps here](https://github.com/nrwl/nx-cloud-workflows/tree/main/workflow-steps). If you cannot find a reusable step that suits your needs, [you can create your own custom steps](/ci/reference/custom-steps).

```yaml {% fileName=".nx/workflows/agents.yaml" %}
launch-templates:
Expand Down
12 changes: 6 additions & 6 deletions docs/shared/guides/define-environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ it will ignore it. It does this for two reasons:

For example:

1. `apps/my-app/.env.local` contains `NX_API_URL=http://localhost:3333`
2. `apps/my-app/.env` contains `NX_API_URL=https://api.example.com`
1. `apps/my-app/.env.local` contains `NX_PUBLIC_API_URL=http://localhost:3333`
2. `apps/my-app/.env` contains `NX_PUBLIC_API_URL=https://api.example.com`
3. Nx will first load the variables from `apps/my-app/.env.local` into the process. When it tries to load the variables
from `apps/my-app/.env`, it will notice that `NX_API_URL` already exists, so it will ignore it.
from `apps/my-app/.env`, it will notice that `NX_PUBLIC_API_URL` already exists, so it will ignore it.

We recommend nesting your **app** specific `env` files in `apps/your-app`, and creating workspace/root level `env` files
for workspace-specific settings (like the [Nx Cloud token](/ci/recipes/security/access-tokens)).
Expand All @@ -68,17 +68,17 @@ In Unix systems, we need to set the environment variables before calling a comma
Let's say that we want to define an API URL for the application to use:

```shell
NX_API_URL=http://localhost:3333 nx build myapp
NX_PUBLIC_API_URL=http://localhost:3333 nx build myapp
```

**Windows (cmd.exe)**

```shell
set "NX_API_URL=http://localhost:3333" && nx build myapp
set "NX_PUBLIC_API_URL=http://localhost:3333" && nx build myapp
```

**Windows (Powershell)**

```shell
($env:NX_API_URL = "http://localhost:3333") -and (nx build myapp)
($env:NX_PUBLIC_API_URL = "http://localhost:3333") -and (nx build myapp)
```
1 change: 1 addition & 0 deletions docs/shared/reference/sitemap.md
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@
- [Configuration Options](/ci/reference/config)
- [nx-cloud CLI](/ci/reference/nx-cloud-cli)
- [Launch Templates](/ci/reference/launch-templates)
- [Custom Steps](/ci/reference/custom-steps)
- [Environment Variables](/ci/reference/env-vars)
- [Release Notes](/ci/reference/release-notes)
- [Troubleshooting](/ci/troubleshooting)
Expand Down
2 changes: 1 addition & 1 deletion e2e/gradle/src/gradle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ function createGradleProject(
projectName: string,
type: 'kotlin' | 'groovy' = 'kotlin'
) {
e2eConsoleLogger(`Using java version: ${execSync('java --version')}`);
e2eConsoleLogger(`Using java version: ${execSync('java -version')}`);
const gradleCommand = isWindows()
? resolve(`${__dirname}/../gradlew.bat`)
: resolve(`${__dirname}/../gradlew`);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@
"unzipper": "^0.10.11",
"url-loader": "^4.1.1",
"use-sync-external-store": "^1.2.0",
"verdaccio": "^5.0.4",
"verdaccio": "^5.30.0",
"vite": "5.0.8",
"vitest": "1.3.1",
"webpack": "5.88.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import 'nx/src/internal-testing-utils/mock-load-nx-plugin';

import { installedCypressVersion } from '@nx/cypress/src/utils/cypress-version';
import type { Tree } from '@nx/devkit';
import * as devkit from '@nx/devkit';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import 'nx/src/internal-testing-utils/mock-load-nx-plugin';

import { installedCypressVersion } from '@nx/cypress/src/utils/cypress-version';
import {
DependencyType,
Expand Down
2 changes: 1 addition & 1 deletion packages/angular/src/generators/host/host.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'nx/src/internal-testing-utils/mock-load-nx-plugin';
import 'nx/src/internal-testing-utils/mock-project-graph';

import { readJson, updateJson } from '@nx/devkit';
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
Expand Down
2 changes: 1 addition & 1 deletion packages/angular/src/generators/library/library.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'nx/src/internal-testing-utils/mock-load-nx-plugin';
import 'nx/src/internal-testing-utils/mock-project-graph';

import {
getProjects,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'nx/src/internal-testing-utils/mock-load-nx-plugin';
import 'nx/src/internal-testing-utils/mock-project-graph';

import type { Tree } from '@nx/devkit';
import { readJson } from '@nx/devkit';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'nx/src/internal-testing-utils/mock-load-nx-plugin';
import 'nx/src/internal-testing-utils/mock-project-graph';

import type { Tree } from '@nx/devkit';
import { readJson } from '@nx/devkit';
Expand Down
2 changes: 1 addition & 1 deletion packages/angular/src/generators/ngrx/ngrx.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'nx/src/internal-testing-utils/mock-load-nx-plugin';
import 'nx/src/internal-testing-utils/mock-project-graph';

import type { Tree } from '@nx/devkit';
import * as devkit from '@nx/devkit';
Expand Down
2 changes: 1 addition & 1 deletion packages/angular/src/generators/remote/remote.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'nx/src/internal-testing-utils/mock-load-nx-plugin';
import 'nx/src/internal-testing-utils/mock-project-graph';

import { E2eTestRunner } from '../../utils/test-runners';
import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'nx/src/internal-testing-utils/mock-load-nx-plugin';
import 'nx/src/internal-testing-utils/mock-project-graph';

import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
import scamGenerator from '../scam/scam';
Expand Down
2 changes: 1 addition & 1 deletion packages/angular/src/generators/setup-mf/setup-mf.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'nx/src/internal-testing-utils/mock-load-nx-plugin';
import 'nx/src/internal-testing-utils/mock-project-graph';

import {
readJson,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'nx/src/internal-testing-utils/mock-load-nx-plugin';
import 'nx/src/internal-testing-utils/mock-project-graph';

import {
NxJsonConfiguration,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'nx/src/internal-testing-utils/mock-load-nx-plugin';
import 'nx/src/internal-testing-utils/mock-project-graph';

import { installedCypressVersion } from '@nx/cypress/src/utils/cypress-version';
import type { Tree } from '@nx/devkit';
Expand Down

0 comments on commit e99ae2d

Please sign in to comment.