Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 10 additions & 0 deletions src/commands/std/std_authenticate_yarn.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
steps:
- run:
name: Authenticate Yarn
working_directory: /home/circleci/code
command: |
cat \<< EOF > ~/.yarnrc.yml
npmRegistries:
"https://registry.yarnpkg.com":
npmAuthToken: ${NPM_TOKEN}
EOF
8 changes: 8 additions & 0 deletions src/commands/std/std_checkout.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
steps:
- run:
name: Checkout Repository
working_directory: /home/circleci
command: |
git clone "https://${GITHUB_USERNAME}:${GITHUB_TOKEN}@github.com/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}" code
cd code
git checkout "${CIRCLE_SHA1}"
13 changes: 13 additions & 0 deletions src/commands/std/std_clone_repo.yml
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std_checkout and std_clone can be a single job since they are basically the same (default to $CIRCLE_SHA1 and $CIRCLE_PROJECT_REPONAME)

do we have anywhere that we need multiple branches or commits upfront? CircleCI checkout defaults to a blobless checkout. But I think we may only need 2 kinds:

  • single branch shallow clone: the latest object state of single commit without history (building, linting, sonarcloud, hadolint)
  • treeless clone of master with tags: semantic-release uses commits and tags for determining next version. however, semantic-release may be doing git commands internally, i'd have to look again

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
parameters:
repo_name:
type: string
directory:
type: string
branch:
type: string
steps:
- run:
name: Clone Repository
working_directory: /home/circleci
command: |
git clone --branch << parameters.branch >> "https://${GITHUB_USERNAME}:${GITHUB_TOKEN}@github.com/${CIRCLE_PROJECT_USERNAME}/<< parameters.repo_name >>" << parameters.directory >>
29 changes: 29 additions & 0 deletions src/commands/std/std_restore_cache.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
parameters:
cache_name:
type: string
default_branch:
type: string
default: master
use_lockfile:
type: boolean
default: false
steps:
- when:
condition: << parameters.use_lockfile >>
steps:
- restore_cache:
name: Restore << parameters.cache_name >> Cache
keys:
- << parameters.cache_name >>-cache-{{ .Environment.CACHE_VERSION }}--lockfile--{{ checksum "/home/circleci/code/yarn.lock" }}
- << parameters.cache_name >>-cache-{{ .Environment.CACHE_VERSION }}--branch--{{ .Branch }}--{{ .Revision }}
- << parameters.cache_name >>-cache-{{ .Environment.CACHE_VERSION }}--branch--{{ .Branch }}--
- << parameters.cache_name >>-cache-{{ .Environment.CACHE_VERSION }}--branch--<< parameters.default_branch >>--
- unless:
condition: << parameters.use_lockfile >>
steps:
- restore_cache:
name: Restore << parameters.cache_name >> Cache
keys:
- << parameters.cache_name >>-cache-{{ .Environment.CACHE_VERSION }}--branch--{{ .Branch }}--{{ .Revision }}
- << parameters.cache_name >>-cache-{{ .Environment.CACHE_VERSION }}--branch--{{ .Branch }}--
- << parameters.cache_name >>-cache-{{ .Environment.CACHE_VERSION }}--branch--<< parameters.default_branch >>--
49 changes: 49 additions & 0 deletions src/commands/std/std_save_cache.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
parameters:
cache_name:
type: string
path:
type: string
use_lockfile:
type: boolean
default: false
path_2:
type: string
default: ""
steps:
- unless:
condition: << parameters.path_2 >>
steps:
- save_cache:
name: Save << parameters.cache_name >> Cache
key: << parameters.cache_name >>-cache-{{ .Environment.CACHE_VERSION }}--branch--{{ .Branch }}--{{ .Revision }}
paths:
- << parameters.path >>
- when:
condition: << parameters.path_2 >>
steps:
- save_cache:
name: Save << parameters.cache_name >> Cache
key: << parameters.cache_name >>-cache-{{ .Environment.CACHE_VERSION }}--branch--{{ .Branch }}--{{ .Revision }}
paths:
- << parameters.path >>
- << parameters.path_2 >>
- when:
condition: << parameters.use_lockfile >>
steps:
- unless:
condition: << parameters.path_2 >>
steps:
- save_cache:
name: Save << parameters.cache_name >> Cache
key: << parameters.cache_name >>-cache-{{ .Environment.CACHE_VERSION }}--lockfile--{{ checksum "/home/circleci/code/yarn.lock" }}
paths:
- << parameters.path >>
- when:
condition: << parameters.path_2 >>
steps:
- save_cache:
name: Save << parameters.cache_name >> Cache
key: << parameters.cache_name >>-cache-{{ .Environment.CACHE_VERSION }}--lockfile--{{ checksum "/home/circleci/code/yarn.lock" }}
paths:
- << parameters.path >>
- << parameters.path_2 >>
28 changes: 28 additions & 0 deletions src/jobs/std/std_build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
parameters:
executor:
type: executor
executor: << parameters.executor >>
working_directory: /home/circleci/code
steps:
- std_checkout
- std_restore_cache:
cache_name: node
use_lockfile: true
- std_restore_cache:
cache_name: build
- run:
name: Build
command: |
yarn ci:build
- run:
name: Collect OpenAPI Schemas
working_directory: /home/circleci/code/apps
command: |
mkdir -p /tmp/openapi-schemas
cp -v --parents */openapi.next.json /tmp/openapi-schemas
- store_artifacts:
path: /tmp/openapi-schemas
destination: /
- std_save_cache:
cache_name: build
path: /home/circleci/code/.turbo/cache
22 changes: 22 additions & 0 deletions src/jobs/std/std_docker_publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
parameters:
executor:
type: executor
ecr_url:
type: string
executor: << parameters.executor >>
working_directory: /home/circleci/code
environment:
ECR_URL: << parameters.ecr_url >>
steps:
- setup_remote_docker
- std_checkout
- std_restore_cache:
cache_name: node
use_lockfile: true
- std_restore_cache:
cache_name: build
- run:
name: Docker Publish
command: |
docker buildx create --use --bootstrap --name buildy-trying
yarn ci:docker:publish
45 changes: 45 additions & 0 deletions src/jobs/std/std_install_node_and_yarn_cache.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
parameters:
executor:
type: executor
executor: << parameters.executor >>
steps:
- run:
name: Sparse Clone for Install
working_directory: /home/circleci
command: |
git clone --sparse "https://${GITHUB_USERNAME}:${GITHUB_TOKEN}@github.com/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}" code
cd code
git checkout "${CIRCLE_SHA1}"
- run:
name: Checkout Critical Files for Install
working_directory: /home/circleci/code
command: |
git sparse-checkout set --no-cone .yarn/ .yalc/ /.yarnrc.yml /yarn.lock /package.json

# get patterns for package.json files in workspace
globs=$(cat package.json | jq '.workspaces[] | . + "/package.json"' -r)

for glob in ${globs}; do
git sparse-checkout add "${glob}"
done
- std_authenticate_yarn
- std_restore_cache:
cache_name: yarn
use_lockfile: true
- std_restore_cache:
cache_name: node
use_lockfile: true
- run:
name: Install Dependencies
working_directory: /home/circleci/code
command: |
yarn install --immutable
- std_save_cache:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i have found that CircleCI save_cache/restore_cache is good for caching between workflows, and that persist_to_workspace/attach_workspace is good for caching between jobs of the same workspace.

So we would still want to persist .yarn/cache and ./node_modules to the workspace and then any job that needs them (build, test_*, etc) would require this job and attach_workspace.

This is especially true for anything that requires the build job. Since restore_cache could pull a stale cache from a different workflow we didn't really want, but attach_workspace guarantees that whatever is attach was put there from this workflow.

ref

cache_name: yarn
path: /home/circleci/code/.yarn/cache
path_2: /home/circleci/code/.yarn/install-state.gz
use_lockfile: true
- std_save_cache:
cache_name: node
path: /home/circleci/code/node_modules
use_lockfile: true
25 changes: 25 additions & 0 deletions src/jobs/std/std_lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
parameters:
executor:
type: executor
executor: << parameters.executor >>
working_directory: /home/circleci/code
steps:
- std_checkout
- std_restore_cache:
cache_name: node
use_lockfile: true
- std_restore_cache:
cache_name: lint
- run:
name: Run Linting
command: |
yarn ci:lint
- store_artifacts:
path: reports/lint.report.xml
destination: lint.report.xml
- store_test_results:
path: reports/lint.report.xml
- std_save_cache:
cache_name: lint
path: /home/circleci/code/.eslintcache
path_2: /home/circleci/code/node_modules/.cache/prettier
14 changes: 14 additions & 0 deletions src/jobs/std/std_sonarcloud_scan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
parameters:
executor:
type: executor
executor: << parameters.executor >>
working_directory: /home/circleci/code
steps:
- std_checkout
- std_restore_cache:
cache_name: node
use_lockfile: true
- attach_workspace:
at: /home/circleci/code
- sonarcloud/scan:
cache_version: 1
21 changes: 21 additions & 0 deletions src/jobs/std/std_test_dependencies.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
parameters:
executor:
type: executor
executor: << parameters.executor >>
working_directory: /home/circleci/code
steps:
- std_checkout
- std_restore_cache:
cache_name: node
use_lockfile: true
- std_restore_cache:
cache_name: build
- std_restore_cache:
cache_name: test-dependencies
- run:
name: Run Dependency Tests
command: |
yarn ci:test:dependencies
- std_save_cache:
cache_name: test-dependencies
path: /home/circleci/code/.turbo/cache
32 changes: 32 additions & 0 deletions src/jobs/std/std_test_integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
parameters:
executor:
type: executor
executor: << parameters.executor >>
working_directory: /home/circleci/code
steps:
- setup_remote_docker
- std_checkout
- std_restore_cache:
cache_name: node
use_lockfile: true
- std_restore_cache:
cache_name: build
- std_restore_cache:
cache_name: vitest-integration
- run:
name: Run Integration Tests
command: |
yarn ci:test:integration
- store_artifacts:
path: integration.report.xml
- store_artifacts:
path: sonar
- store_test_results:
path: integration.report.xml
- persist_to_workspace:
root: /home/circleci/code
paths:
- sonar/integration-coverage
- std_save_cache:
cache_name: vitest-integration
path: /home/circleci/code/node_modules/.experimental-vitest-cache
26 changes: 26 additions & 0 deletions src/jobs/std/std_test_openapi_schema.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
parameters:
executor:
type: executor
executor: << parameters.executor >>
working_directory: /home/circleci/code
steps:
- setup_remote_docker
- std_checkout
- std_clone_repo:
repo_name: openapi-schemas
directory: schemas
branch: master
- std_restore_cache:
cache_name: node
use_lockfile: true
- std_restore_cache:
cache_name: build
- run:
name: Restore OpenAPI Schemas
working_directory: /home/circleci/schemas
command: |
cp -v --parents apps/*/openapi.json /home/circleci/code
- run:
name: Test OpenAPI Schema
command: |
yarn ci:schema:validate
21 changes: 21 additions & 0 deletions src/jobs/std/std_test_types.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
parameters:
executor:
type: executor
executor: << parameters.executor >>
working_directory: /home/circleci/code
steps:
- std_checkout
- std_restore_cache:
cache_name: node
use_lockfile: true
- std_restore_cache:
cache_name: build
- std_restore_cache:
cache_name: test-types
- run:
name: Check Types
command: |
yarn ci:test:types
- std_save_cache:
cache_name: test-types
path: /home/circleci/code/.turbo/cache
31 changes: 31 additions & 0 deletions src/jobs/std/std_test_unit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
parameters:
executor:
type: executor
executor: << parameters.executor >>
working_directory: /home/circleci/code
steps:
- std_checkout
- std_restore_cache:
cache_name: node
use_lockfile: true
- std_restore_cache:
cache_name: build
- std_restore_cache:
cache_name: vitest-unit
- run:
name: Run Unit Tests
command: |
yarn ci:test:unit
- store_artifacts:
path: unit.report.xml
- store_artifacts:
path: sonar
- store_test_results:
path: unit.report.xml
- persist_to_workspace:
root: /home/circleci/code
paths:
- sonar/unit-coverage
- std_save_cache:
cache_name: vitest-unit
path: /home/circleci/code/node_modules/.experimental-vitest-cache