Skip to content

Commit

Permalink
Merge branch 'master' into fix-19990
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesHenry committed Nov 6, 2023
2 parents 7d32357 + 1d62dce commit 746a380
Show file tree
Hide file tree
Showing 95 changed files with 2,012 additions and 934 deletions.
5 changes: 0 additions & 5 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,6 @@ jobs:
command: |
pnpm nx affected -t e2e-macos --parallel=1 --base=$NX_BASE --head=$NX_HEAD
no_output_timeout: 45m
- run:
name: Close CI group
command: |
pnpm nx-cloud stop-all-agents
no_output_timeout: 45m

# -------------------------
# WORKFLOWS(JOBS)
Expand Down
20 changes: 11 additions & 9 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,28 @@
{
"name": "NxDevContainer",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/typescript-node:0-18",
"image": "mcr.microsoft.com/devcontainers/typescript-node:20-bullseye",
"features": {
"ghcr.io/devcontainers/features/rust:1": {}
},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// 4211 = nx graph port
"forwardPorts": [4211],

// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "pnpm install",
"postCreateCommand": "./.devcontainer/postCreateCommand.sh",
// Configure tool-specific properties.
"customizations": {
"vscode": {
"extensions": ["nrwl.angular-console"]
"extensions": [
"nrwl.angular-console",
"firsttris.vscode-jest-runner",
"eamodio.gitlens"
],
"settings": {
"debug.javascript.autoAttachFilter": "onlyWithFlag" // workaround for that issue: https://github.com/microsoft/vscode-js-debug/issues/374#issuecomment-622239998
}
}
}

// Configure tool-specific properties.
// "customizations": {},

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
11 changes: 11 additions & 0 deletions .devcontainer/postCreateCommand.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh

# Update the underlying (Debian) OS, to make sure we have the latest security patches and libraries like 'GLIBC'
sudo apt-get update && sudo apt-get -y upgrade

# Update pnpm
#npm install -g pnpm

# Install dependencies
pnpm install --frozen-lockfile

18 changes: 15 additions & 3 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -155,19 +155,20 @@ jobs:
build-freebsd:
runs-on: macos-12
name: Build FreeBSD
timeout-minutes: 45
steps:
- uses: actions/checkout@v3
- name: Build
id: build
uses: cross-platform-actions/action@v0.15.0
uses: cross-platform-actions/action@v0.21.0
env:
DEBUG: napi:*
RUSTUP_IO_THREADS: 1
with:
operating_system: freebsd
version: '13.2'
architecture: x86-64
environment_variables: DEBUG RUSTUP_IO_THREADS
environment_variables: DEBUG RUSTUP_IO_THREADS CI
shell: bash
run: |
env
Expand All @@ -191,9 +192,13 @@ jobs:
mkdir -p /Users/runner/work/_temp/_github_workflow
echo "{}" > /Users/runner/work/_temp/_github_workflow/event.json
pnpm install --frozen-lockfile --ignore-scripts
pnpm nx run-many --target=build-native -- --target=x86_64-unknown-freebsd
pnpm nx run-many --outputStyle stream --target=build-native -- --target=x86_64-unknown-freebsd
pnpm nx reset
rm -rf node_modules
rm -rf dist
echo "KILL ALL NODE PROCESSES"
killall node
echo "COMPLETE"
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
Expand Down Expand Up @@ -234,6 +239,13 @@ jobs:
git checkout -b publish/$GITHUB_REF_NAME
npm config set //registry.npmjs.org/:_authToken=$NPM_TOKEN
pnpm nx-release --local=false $GITHUB_REF_NAME
- name: Trigger Docs Release
# Publish docs only on a full release and when publishing the latest version
if: ${{ !github.event.release.prerelease && github.event.release.target_commitish == 'master' }}
run: |
# We force recreate the branch in order to always be up to date and avoid merge conflicts within the automated workflow
git branch -f website
git push -f origin website
env:
GH_TOKEN: ${{ github.token }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
4 changes: 3 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@ graph/client/src/assets/generated-task-graphs
/.env
CODEOWNERS

/.nx/cache
/.nx/cache

.pnpm-store
2 changes: 1 addition & 1 deletion docs/generated/packages/vue/generators/application.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
},
"unitTestRunner": {
"type": "string",
"enum": ["jest", "vitest", "none"],
"enum": ["vitest", "none"],
"description": "Test runner to use for unit tests.",
"x-prompt": "Which unit test runner would you like to use?",
"default": "vitest"
Expand Down
6 changes: 0 additions & 6 deletions docs/generated/packages/vue/generators/component.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,6 @@
"type": "boolean",
"default": false,
"x-priority": "internal"
},
"unitTestRunner": {
"type": "string",
"enum": ["vitest", "jest", "none"],
"description": "Test runner to use for unit tests.",
"x-prompt": "What unit test runner should be used?"
}
},
"required": ["name"],
Expand Down
2 changes: 1 addition & 1 deletion docs/generated/packages/vue/generators/library.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
},
"unitTestRunner": {
"type": "string",
"enum": ["vitest", "jest", "none"],
"enum": ["vitest", "none"],
"description": "Test runner to use for unit tests.",
"x-prompt": "What unit test runner should be used?"
},
Expand Down
Binary file modified docs/nx-cloud/reference/swagger-preview.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions docs/shared/guides/using-tailwind-css-in-react.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,15 @@ By specifying the `postcssConfig` option, the PostCSS and Tailwind configuration
{% callout type="note" title="Using library-specific configuration files" %}
If your libraries have their own `postcss.config.js` and `tailwind.config.js` files then you should not use the `postcssConfig` option. Doing so will ignore the library-specific configuration and apply the application's configuration to everything.
{%/ callout %}

{% short-embeds %}
{% short-video
title="The Best Way to Add Tailwind"
embedUrl="https://www.youtube.com/embed/AktHLfCnpqA" /%}
{% short-video
title="Convert CRA to Vite"
embedUrl="https://www.youtube.com/embed/VVj1UdxNp0o" /%}
{% short-video
title="Customize React Webpack Config"
embedUrl="https://www.youtube.com/embed/vgs7LTuuhO8" /%}
{% /short-embeds %}
12 changes: 12 additions & 0 deletions docs/shared/migration/adding-to-existing-project.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,15 @@ Learn more about [Nx Inputs](/recipes/running-tasks/customizing-inputs).
{% card title="Adding Nx to NPM/Yarn/PNPM Workspace" description="Learn more about how to add Nx to an existing monorepo" type="documentation" url="/recipes/adopting-nx/adding-to-monorepo" /%}

{% /cards %}

{% short-embeds %}
{% short-video
title="Nx Tips: Nx Init"
embedUrl="https://www.youtube.com/embed/Wpj3KSpN0Xw" /%}
{% short-video
title="How Long Does It Take To Add Nx?"
embedUrl="https://www.youtube.com/embed/fPt_pFP6hn8" /%}
{% short-video
title="Nx is Complicated?"
embedUrl="https://www.youtube.com/embed/AQbSwPtPBiw" /%}
{% /short-embeds %}
89 changes: 18 additions & 71 deletions docs/shared/monorepo-ci-azure.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,9 @@ Nx needs additional Git history available for `affected` to function correctly.

Unlike `GitHub Actions` and `CircleCI`, you don't have the metadata to help you track the last successful run on `main`. In the example below, the base is set to `HEAD~1` (for push) or branching point (for pull requests), but a more robust solution would be to tag an SHA in the main job once it succeeds and then use this tag as a base. You can also try [using the devops CLI within the pipeline yaml](#get-the-commit-of-the-last-successful-build). See the [nx-tag-successful-ci-run](https://github.com/nrwl/nx-tag-successful-ci-run) and [nx-set-shas](https://github.com/nrwl/nx-set-shas) (version 1 implements tagging mechanism) repositories for more information.

{% callout type="note" title="Tracking the origin branch" %}

If you're using this action in the context of a branch you may need to add `run: "git branch --track main origin/main"` before running the `nx affected` command since `origin/main` won't exist.

{% /callout %}

We also have to set `NX_BRANCH` explicitly. NX_BRANCH does not impact the functionality of your runs, but does provide a human-readable label to easily identify them in the Nx Cloud app.

```yaml
```yaml {% fileName="azure-pipelines.yml" %}
trigger:
- main
pr:
Expand All @@ -40,35 +34,33 @@ jobs:
steps:
# Set Azure Devops CLI default settings
- bash: az devops configure --defaults organization=$(System.TeamFoundationCollectionUri) project=$(System.TeamProject)
displayName: 'Set default Azure DevOps organization and project'
displayName: 'Set default Azure DevOps organization and project'

# Get last successfull commit from Azure Devops CLI
- bash: |
LAST_SHA=$(az pipelines build list --branch $(Build.SourceBranchName) --definition-ids $(System.DefinitionId) --result succeeded --top 1 --query "[0].triggerInfo.\"ci.sourceSha\"")
if [ -z "$LAST_SHA" ]
then
LAST_SHA=$DEFAULT_BASE_SHA
fi
echo "Last successful commit SHA: $LAST_SHA"
echo "##vso[task.setvariable variable=BASE_SHA]$LAST_SHA"
displayName: 'Get last successful commit SHA'
env:
AZURE_DEVOPS_EXT_PAT: $(System.AccessToken)
LAST_SHA=$(az pipelines build list --branch $(Build.SourceBranchName) --definition-ids $(System.DefinitionId) --result succeeded --top 1 --query "[0].triggerInfo.\"ci.sourceSha\"")
if [ -z "$LAST_SHA" ]
then
LAST_SHA=$DEFAULT_BASE_SHA
fi
echo "Last successful commit SHA: $LAST_SHA"
echo "##vso[task.setvariable variable=BASE_SHA]$LAST_SHA"
displayName: 'Get last successful commit SHA'
env:
AZURE_DEVOPS_EXT_PAT: $(System.AccessToken)
# Required for nx affected if we're on a branch
- script: git branch --track main origin/main
- script: npm ci

- script: npx nx format:check --base=$(BASE_SHA)

- script: npx nx affected --base=$(BASE_SHA) -t lint --parallel=3
- script: npx nx affected --base=$(BASE_SHA) -t test --parallel=3 --configuration=ci
- script: npx nx affected --base=$(BASE_SHA) -t build --parallel=3
- script: npx nx affected --base=$(BASE_SHA) -t lint,test,build --parallel=3 --configuration=ci
```

The `main` job implements the CI workflow.

## Get the Commit of the Last Successful Build

The idea is to use [Azure Devops CLI](https://learn.microsoft.com/en-us/cli/azure/pipelines?view=azure-cli-latest)
In the example above we ran a script to retrieve the commit of the last successful build. The idea is to use [Azure Devops CLI](https://learn.microsoft.com/en-us/cli/azure/pipelines?view=azure-cli-latest)
directly in the [Pipeline Yaml](https://learn.microsoft.com/en-us/azure/devops/cli/azure-devops-cli-in-yaml?view=azure-devops)

First, we configure Devops CLI
Expand Down Expand Up @@ -103,51 +95,6 @@ By default the command returns an entire JSON object with all the information. B

Finally we extract the result in a common [custom variable](https://learn.microsoft.com/en-us/azure/devops/pipelines/process/set-variables-scripts?view=azure-devops&tabs=bash) named `BASE_SHA` used later by `nx affected` commands

An example with a default SHA in case no commit is found:

```yaml {% fileName="azure-pipelines.yml" %}
trigger:
- main
pr:
- main

variables:
CI: 'true'
NX_BRANCH: $(Build.SourceBranchName)
DEFAULT_BASE_SHA: $(git rev-parse HEAD~1)
HEAD_SHA: $(git rev-parse HEAD)

jobs:
- job: main
pool:
vmImage: 'ubuntu-latest'
steps:
# Set Azure Devops CLI default settings
- bash: az devops configure --defaults organization=$(System.TeamFoundationCollectionUri) project=$(System.TeamProject)
displayName: 'Set default Azure DevOps organization and project'

# Get last successfull commit from Azure Devops CLI
- bash: |
LAST_SHA=$(az pipelines build list --branch $(Build.SourceBranchName) --definition-ids $(System.DefinitionId) --result succeeded --top 1 --query "[0].triggerInfo.\"ci.sourceSha\"")
if [ -z "$LAST_SHA" ]
then
LAST_SHA=$DEFAULT_BASE_SHA
fi
echo "Last successful commit SHA: $LAST_SHA"
echo "##vso[task.setvariable variable=BASE_SHA]$LAST_SHA"
displayName: 'Get last successful commit SHA'
env:
AZURE_DEVOPS_EXT_PAT: $(System.AccessToken)
- script: npm ci

- script: npx nx format:check

- script: npx nx affected --base=$(BASE_SHA) -t lint --parallel=3
- script: npx nx affected --base=$(BASE_SHA) -t test --parallel=3 --ci --code-coverage
- script: npx nx affected --base=$(BASE_SHA) -t build --parallel=3
```

## Distributed Task Execution with Nx Cloud

Read more about [Distributed Task Execution (DTE)](/core-features/distribute-task-execution).
Expand Down Expand Up @@ -185,11 +132,11 @@ jobs:
pool:
vmImage: 'ubuntu-latest'
steps:
- script: git branch --track main origin/main
- script: npm ci
- script: npx nx-cloud start-ci-run --stop-agents-after="build"

- script: npx nx-cloud record -- npx nx format:check --base=$(BASE_SHA) --head=$(HEAD_SHA)
- script: npx nx affected --base=$(BASE_SHA) --head=$(HEAD_SHA) -t lint --parallel=3 & npx nx affected --base=$(BASE_SHA) --head=$(HEAD_SHA) -t test --parallel=3 --configuration=ci & npx nx affected --base=$(BASE_SHA) --head=$(HEAD_SHA) -t build --parallel=3
- script: npx nx affected --base=$(BASE_SHA) --head=$(HEAD_SHA) -t lint,test,build --parallel=3 --configuration=ci
```

You can also use our [ci-workflow generator](/nx-api/workspace/generators/ci-workflow) to generate the pipeline file.
47 changes: 42 additions & 5 deletions docs/shared/monorepo-ci-bitbucket-pipelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Below is an example of a Bitbucket Pipeline setup for an Nx workspace - building and testing only what is affected.

```yaml
image: node:16
image: node:20
pipelines:
pull-requests:
'**':
Expand All @@ -14,9 +14,7 @@ pipelines:
script:
- npm ci
- npx nx format:check
- npx nx affected -t lint --base=origin/master --parallel --max-parallel=3
- npx nx affected -t test --base=origin/master --parallel --max-parallel=3 --configuration=ci
- npx nx affected -t build --base=origin/master --head=HEAD --parallel --max-parallel=3
- npx nx affected -t lint,test,build --base=origin/master --head=HEAD --configuration=ci

branches:
main:
Expand All @@ -27,7 +25,46 @@ pipelines:
script:
- npm ci
- npx nx format:check
- npx nx affected -t lint --base=origin/master --parallel --max-parallel=3 & npx nx affected -t test --base=HEAD~1 --parallel --max-parallel=3 --configuration=ci & npx nx affected -t build --base=HEAD~1 --parallel --max-parallel=3
- npx nx affected -t lint,test,build --base=HEAD~1 --configuration=ci
```

The `pull-requests` and `main` jobs implement the CI workflow.

## Distributed Task Execution

This pipeline uses [Distributed Task Execution (DTE)](/core-features/distribute-task-execution) to automatically distribute work across multiple agent processes.

```yaml
image: node:20

clone:
depth: full

definitions:
steps:
- step: &agent
name: Agent
script:
- export NX_BRANCH=$BITBUCKET_PR_ID

- npm ci
- npx nx-cloud start-agent

pipelines:
pull-requests:
'**':
- parallel:
- step:
name: CI
script:
- export NX_BRANCH=$BITBUCKET_PR_ID

- npm ci
- npx nx-cloud start-ci-run --stop-agents-after="build" --agent-count=3
- npx nx-cloud record -- npx nx format:check
- npx nx affected --target=lint,test,build
- npx nx-cloud stop-all-agents
- step: *agent
- step: *agent
- step: *agent
```

0 comments on commit 746a380

Please sign in to comment.