Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(repo): enable Nx crystal and nx-cloud agents #318

Merged
merged 2 commits into from
Feb 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
chore(repo): update nx to 18.0.4
  • Loading branch information
FrozenPandaz committed Feb 10, 2024
commit 5f8391a8ebb5a34b3ab40608432b8e5911916c03
178 changes: 22 additions & 156 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,142 +1,33 @@
# Javascript Node CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-javascript/ for more details
#
version: 2
version: 2.1

defaults: &defaults
working_directory: ~/repo
docker:
- image: cimg/node:lts-browsers

set_env: &set_env
name: Setup Environment Variables
command: |
if [[ $CIRCLE_PULL_REQUEST ]]
then
echo 'Fetching Base Commit from GitHub'
echo 'export CIRCLE_PR_NUMBER="${CIRCLE_PR_NUMBER:-${CIRCLE_PULL_REQUEST##*/}}"' >> $BASH_ENV
source $BASH_ENV
echo "export CIRCLE_PR_BASE_SHA=`curl -s https://api.github.com/repos/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}/pulls/${CIRCLE_PR_NUMBER} | jq -r '.base.sha'`" >> $BASH_ENV
echo 'export AFFECTED_ARGS="--base ${CIRCLE_PR_BASE_SHA}"' >> $BASH_ENV
else
echo 'Fetching Base Commit from Deploy Cache'
if [[ ! -f dist/last-deploy.txt ]]
then
mkdir dist && git rev-parse HEAD~1 > dist/last-deploy.txt
fi
echo 'export AFFECTED_ARGS="--base $(cat dist/last-deploy.txt)"' >> $BASH_ENV
fi
source $BASH_ENV
echo $AFFECTED_ARGS
node -v
yarn -v

yarn_cache: &yarn_cache
keys:
- node-deps-node16-{{ checksum "yarn.lock" }}
# fallback to using the latest cache if no exact match is found
- node-deps-node16-
orbs:
nx: nrwl/nx@1.6.2

deploy_cache: &deploy_cache
key: last-deploy-sha

yarn_install: &yarn_install
name: Install Dependencies
command: yarn install --frozen-lockfile --non-interactive

jobs:
install:
<<: *defaults
steps:
- checkout
- restore_cache:
<<: *yarn_cache
- run: rm -rf node_modules
- run:
<<: *yarn_install
- save_cache:
key: node-deps-node16-{{ checksum "yarn.lock" }}
paths:
- ~/.cache
- node_modules
check-formatting:
<<: *defaults
steps:
- checkout
- restore_cache:
<<: *deploy_cache
- run:
<<: *set_env
- restore_cache:
<<: *yarn_cache
- run: yarn format:check ${AFFECTED_ARGS}
lint:
<<: *defaults
steps:
- checkout
- restore_cache:
<<: *deploy_cache
- run:
<<: *set_env
- restore_cache:
<<: *yarn_cache
- run: yarn affected:lint ${AFFECTED_ARGS} --parallel --exclude shared-assets shared-styles
build:
<<: *defaults
steps:
- checkout
- restore_cache:
<<: *deploy_cache
- run:
<<: *set_env
- restore_cache:
<<: *yarn_cache
- run: yarn affected:build -- ${AFFECTED_ARGS} --parallel --configuration production
- save_cache:
key: build-{{ .Environment.CIRCLE_WORKFLOW_ID }}
paths:
- dist
- store_artifacts:
path: dist
test:
<<: *defaults
steps:
- checkout
- restore_cache:
<<: *deploy_cache
- run:
<<: *set_env
- restore_cache:
<<: *yarn_cache
- run: yarn affected -- -t test ${AFFECTED_ARGS} --parallel -- --ci --runInBand
e2e:
<<: *defaults
main:
docker:
- image: cimg/node:lts-browsers
steps:
- checkout
- restore_cache:
<<: *deploy_cache
- run:
<<: *set_env
- restore_cache:
<<: *yarn_cache
- run: yarn affected:e2e -- ${AFFECTED_ARGS} --configuration production --parallel false -- --headless
- store_artifacts:
path: dist/cypress

deploy:
<<: *defaults
steps:
- checkout
# Connect your workspace on nx.app and uncomment this to enable task distribution.
# The "--stop-agents-after" is optional, but allows idle agents to shut down once the "e2e-ci" targets have been requested
- run: npx nx-cloud start-ci-run --distribute-on="5 custom-linux" --stop-agents-after="e2e-ci"

- run: yarn install --frozen-lockfile
- nx/set-shas:
main-branch-name: 'master'
- restore_cache:
<<: *deploy_cache
- run:
<<: *set_env
- restore_cache:
<<: *yarn_cache
- restore_cache:
key: build-{{ .Environment.CIRCLE_WORKFLOW_ID }}
- run: yarn affected -- --target deploy ${AFFECTED_ARGS}

- run: yarn nx-cloud record -- nx format:check --base=$NX_BASE --head=$NX_HEAD
- run: yarn nx affected --base=$NX_BASE --head=$NX_HEAD -t lint --exclude shared-assets shared-styles --parallel 4
- run: yarn nx affected --base=$NX_BASE --head=$NX_HEAD -t test build --parallel 4
- run: yarn nx affected --base=$NX_BASE --head=$NX_HEAD -t e2e-ci --parallel 1
- run: yarn nx affected --base=$NX_BASE --head=$NX_HEAD -t deploy --no-agents
- run: git rev-parse HEAD > dist/last-deploy.txt
- save_cache:
key: last-deploy-sha
Expand All @@ -145,32 +36,7 @@ jobs:

workflows:
version: 2
pr_check:

ci:
jobs:
- install
- check-formatting:
requires:
- install
- lint:
requires:
- install
- test:
requires:
- install
- build:
requires:
- install
- e2e:
requires:
- install
- deploy:
filters:
branches:
only:
- master
requires:
- check-formatting
- lint
- test
- build
- e2e
- main
176 changes: 176 additions & 0 deletions .circleci/someconfig.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
# Javascript Node CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-javascript/ for more details
#
version: 2

defaults: &defaults
working_directory: ~/repo
docker:
- image: cimg/node:lts-browsers

set_env: &set_env
name: Setup Environment Variables
command: |
if [[ $CIRCLE_PULL_REQUEST ]]
then
echo 'Fetching Base Commit from GitHub'
echo 'export CIRCLE_PR_NUMBER="${CIRCLE_PR_NUMBER:-${CIRCLE_PULL_REQUEST##*/}}"' >> $BASH_ENV
source $BASH_ENV
echo "export CIRCLE_PR_BASE_SHA=`curl -s https://api.github.com/repos/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}/pulls/${CIRCLE_PR_NUMBER} | jq -r '.base.sha'`" >> $BASH_ENV
echo 'export AFFECTED_ARGS="--base ${CIRCLE_PR_BASE_SHA}"' >> $BASH_ENV
else
echo 'Fetching Base Commit from Deploy Cache'
if [[ ! -f dist/last-deploy.txt ]]
then
mkdir dist && git rev-parse HEAD~1 > dist/last-deploy.txt
fi
echo 'export AFFECTED_ARGS="--base $(cat dist/last-deploy.txt)"' >> $BASH_ENV
fi
source $BASH_ENV
echo $AFFECTED_ARGS
node -v
yarn -v

yarn_cache: &yarn_cache
keys:
- node-deps-node16-{{ checksum "yarn.lock" }}
# fallback to using the latest cache if no exact match is found
- node-deps-node16-

deploy_cache: &deploy_cache
key: last-deploy-sha

yarn_install: &yarn_install
name: Install Dependencies
command: yarn install --frozen-lockfile --non-interactive

jobs:
install:
<<: *defaults
steps:
- checkout
- restore_cache:
<<: *yarn_cache
- run: rm -rf node_modules
- run:
<<: *yarn_install
- save_cache:
key: node-deps-node16-{{ checksum "yarn.lock" }}
paths:
- ~/.cache
- node_modules
check-formatting:
<<: *defaults
steps:
- checkout
- restore_cache:
<<: *deploy_cache
- run:
<<: *set_env
- restore_cache:
<<: *yarn_cache
- run: yarn format:check ${AFFECTED_ARGS}
lint:
<<: *defaults
steps:
- checkout
- restore_cache:
<<: *deploy_cache
- run:
<<: *set_env
- restore_cache:
<<: *yarn_cache
- run: yarn affected:lint ${AFFECTED_ARGS} --parallel --exclude shared-assets shared-styles
build:
<<: *defaults
steps:
- checkout
- restore_cache:
<<: *deploy_cache
- run:
<<: *set_env
- restore_cache:
<<: *yarn_cache
- run: yarn affected:build -- ${AFFECTED_ARGS} --parallel --configuration production
- save_cache:
key: build-{{ .Environment.CIRCLE_WORKFLOW_ID }}
paths:
- dist
- store_artifacts:
path: dist
test:
<<: *defaults
steps:
- checkout
- restore_cache:
<<: *deploy_cache
- run:
<<: *set_env
- restore_cache:
<<: *yarn_cache
- run: yarn affected -- -t test ${AFFECTED_ARGS} --parallel -- --ci --runInBand
e2e:
<<: *defaults
steps:
- checkout
- restore_cache:
<<: *deploy_cache
- run:
<<: *set_env
- restore_cache:
<<: *yarn_cache
- run: yarn affected:e2e -- ${AFFECTED_ARGS} --configuration production --parallel false -- --headless
- store_artifacts:
path: dist/cypress

deploy:
<<: *defaults
steps:
- checkout
- restore_cache:
<<: *deploy_cache
- run:
<<: *set_env
- restore_cache:
<<: *yarn_cache
- restore_cache:
key: build-{{ .Environment.CIRCLE_WORKFLOW_ID }}
- run: yarn affected -- --target deploy ${AFFECTED_ARGS}
- run: git rev-parse HEAD > dist/last-deploy.txt
- save_cache:
key: last-deploy-sha
paths:
- dist/last-deploy.txt

workflows:
version: 2
pr_check:
jobs:
- install
- check-formatting:
requires:
- install
- lint:
requires:
- install
- test:
requires:
- install
- build:
requires:
- install
- e2e:
requires:
- install
- deploy:
filters:
branches:
only:
- master
requires:
- check-formatting
- lint
- test
- build
- e2e
19 changes: 19 additions & 0 deletions .nx/workflows/agents.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
launch-templates:
custom-linux:
resource-class: 'docker_linux_amd64/medium'
image: 'ubuntu22.04-node20.9-v2'
init-steps:
- name: Checkout
uses: 'nrwl/nx-cloud-workflows/v3.1/workflow-steps/checkout/main.yaml'
- name: Restore Node Modules Cache
uses: 'nrwl/nx-cloud-workflows/v3.1/workflow-steps/cache/main.yaml'
env:
KEY: 'package-lock.json|yarn.lock|pnpm-lock.yaml'
PATHS: 'node_modules'
BASE_BRANCH: 'main'
- name: Install Node Modules
uses: 'nrwl/nx-cloud-workflows/v3.1/workflow-steps/install-node-modules/main.yaml'
- name: Install Browsers (if needed)
uses: 'nrwl/nx-cloud-workflows/v3.1/workflow-steps/install-browsers/main.yaml'
- name: Setup Cypress
script: 'yarn cypress install'
Loading