Skip to content

Commit

Permalink
Merge pull request #40 from infinitered/workflow
Browse files Browse the repository at this point in the history
unify circle-ci configs
  • Loading branch information
trevor-coleman authored Sep 19, 2023
2 parents 1dafd70 + a0d8075 commit cb04b54
Show file tree
Hide file tree
Showing 29 changed files with 114 additions and 410 deletions.
6 changes: 6 additions & 0 deletions .changeset/dry-pugs-attend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"docusaurus": patch
"@infinitered/infinite-red-ai": patch
---

Fix test issues and broken links.
222 changes: 29 additions & 193 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,211 +1,47 @@
# Config for the setup workflow and common resources (jobs, commands) for main workflows
# `common-` prefix is added for common resources (to avoid conflicts with module resources)

version: 2.1

setup: << pipeline.parameters.run-setup >>

# All pipeline parameters need to be defined equally both for the setup workflow and main workflows
# These parameters will be passed to both of them
parameters:
run-setup:
description: Whether it is a setup workflow or a continuation
type: boolean
default: true
force-all:
description: Emergency valve - forcibly build all the modules
type: boolean
default: false
custom-parameter:
description: Some string to pass
type: string
default: ""
# Docker defaults
defaults: &defaults
docker:
- image: cimg/node:18.16.1
working_directory: /mnt/ramdisk/repo

# Custom commands aimed for the main workflows and jobs

commands:
common-install-deps:
# Jobs
jobs:
test_and_build:
<<: *defaults
steps:
- checkout
# Restore Yarn cache (Yarn 3 uses .yarn/cache directory)
- restore_cache:
name: Restore Yarn Package Cache
name: Restore Yarn Cache
keys:
- yarn-packages-{{ checksum "yarn.lock" }}
- yarn-cache-{{ checksum "yarn.lock" }}
- run:
name: Use local Yarn version
command: echo "export PATH=$(pwd)/.yarn/releases:$PATH" >> $BASH_ENV
- run:
name: Install Dependencies
command: yarn install --immutable
# Save Yarn cache
- save_cache:
name: Save Yarn Package Cache
key: yarn-packages-{{ checksum "yarn.lock" }}
name: Save Yarn Cache
key: yarn-cache-{{ checksum "yarn.lock" }}
paths:
- .yarn/cache
- .yarn/unplugged
common-static-tests:
parameters:
working_directory:
description: Path to the directory where the tests are run
type: string
default: .
steps:
- run:
working_directory: << parameters.working_directory >>
name: Run static tests
command: yarn lint && yarn test
no_output_timeout: 5m
common-build-core:
steps:
name: Lint code
command: yarn lint
- run:
working_directory: /mnt/ramdisk/repo/modules/react-native-mlkit-core
name: Build core library
command: yarn build
common-build:
parameters:
working_directory:
description: Path to the directory where the tests are run
type: string
default: .
steps:
name: Run tests
command: yarn test
- run:
working_directory: << parameters.working_directory >>
name: Build package
command: yarn build

name: Build everything including docs
command: yarn ci:build

# Workflows
workflows:
# The setup workflow
setup-workflow:
when: << pipeline.parameters.run-setup >>
jobs:
- config-splitting/setup-dynamic-config:
force-all: << pipeline.parameters.force-all >>
base-revision: main
# If A is modified, the job for A will run
# Similarly if B is modified, the job for B will run
# If C is modified, then the jobs for both C and B (as a dependency) will run
modules: |
modules/react-native-mlkit-core
modules/react-native-mlkit-face-detection
modules/react-native-mlkit-image-labeling
modules/react-native-mlkit-object-detection
orbs:
# An "embedded" orb to facilitate config splitting
config-splitting:
# Dependencies
orbs:
continuation: circleci/[email protected]
# Commands for the setup workflow
commands:
list-changed-modules:
parameters:
modules:
description: |
Directories which should be built upon changes.
Each row represents a space-separated list of the root directories for modules, each of which must has own `.circleci/config.yml`.
The first item of the list will be tested for changes, and will be added to the filtered list of modules if there are any changes.
The subsequent items, if there are any, will also be added to the filtered list of modules if there are any changes in the directory specified as the first item.
CAVEAT: Directory names having white spaces cannot be specified.
type: string
modules-filtered:
description: Path to the file where the filtered list of modules is generated
type: string
default: /tmp/modules-filtered.txt
base-revision:
description: Revision to compare with the current HEAD
type: string
default: main
force-all:
description: Emergency valve - forcibly build all the modules
type: boolean
default: false
steps:
- run:
name: Generate the list of modules having changes
command: |
# Add each module to `modules-filtered` if 1) `force-all` is set to `true`, 2) there is a diff against `base-revision`, 3) there is no `HEAD~1` (i.e., this is the very first commit for the repo) OR 4) there is a diff against the previous commit
cat \<< EOD | sed -e '/^$/d' | while read row; do module="$(echo "$row" | awk '{ print $1 }')"; if [ << parameters.force-all >> == 'true' ] || [ $(git diff --name-only << parameters.base-revision >> "$module" | wc -l) -gt 0 ] || (! git rev-parse --verify HEAD~1) || [ $(git diff --name-only HEAD~1 "$module" | wc -l) -gt 0 ]; then echo "$row" | sed -e 's/ /\n/g' >> << parameters.modules-filtered >>; fi; done
<< parameters.modules >>
EOD
merge-modular-configs:
parameters:
modules:
description: Path to the file for the list of the modules to build
type: string
default: /tmp/modules-filtered.txt
shared-config:
description: Path to the config providing shared resources (such as prerequisite jobs and common commands)
type: string
default: .circleci/config.yml
continue-config:
description: Path to the internally-used config for continuation
type: string
default: .circleci/continue-config.yml
steps:
- run:
name: Merge configs
command: |
# If `modules` is unavailable, stop this job without continuation
if [ ! -f "<< parameters.modules >>" ] || [ ! -s "<< parameters.modules >>" ]
then
echo 'Nothing to merge. Halting the job.'
circleci-agent step halt
exit
fi
# Convert a list of dirs to a list of config.yml
sed -i -e 's/$/\/.circleci\/config.yml/g' "<< parameters.modules >>"
# If `shared-config` exists, append it at the end of `modules`
if [ -f << parameters.shared-config >> ]
then
echo "<< parameters.shared-config >>" >> "<< parameters.modules >>"
fi
xargs -a "<< parameters.modules >>" yq -y -s 'reduce .[] as $item ({}; . * $item)' | tee "<< parameters.continue-config >>"
version: 2
build-and-test:
jobs:
# The job for the setup workflow
setup-dynamic-config:
parameters:
modules:
description: Directories which should be tested for changes; one directory per line. Each directory must have `.circleci/config.yml`.
type: string
base-revision:
description: Revision to compare with the current HEAD
type: string
default: main
force-all:
description: Emergency valve - forcibly build all the modules
type: boolean
default: false
modules-filtered:
description: Path to the file where the filtered list of modules is generated
type: string
default: /tmp/modules-filtered.txt
shared-config:
description: Path to the config providing shared resources (such as prerequisite jobs and common commands)
type: string
default: .circleci/config.yml
continue-config:
description: Path to the internally-used config for continuation
type: string
default: .circleci/continue-config.yml
docker:
- image: cimg/python:3.9
steps:
- checkout
- run:
name: Install yq
command: pip install yq
- list-changed-modules:
modules: << parameters.modules >>
modules-filtered: << parameters.modules-filtered >>
base-revision: << parameters.base-revision >>
force-all: << parameters.force-all >>
- merge-modular-configs:
modules: << parameters.modules-filtered >>
shared-config: << parameters.shared-config >>
continue-config: << parameters.continue-config >>
- continuation/continue:
configuration_path: << parameters.continue-config >>
parameters: '{"run-setup":false}'
- test_and_build
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
echo "::set-output name=published::false"
fi
deploy_docs:
name: Deploy to GitHub Pages
name: Deploy Docusaurus to GitHub Pages
runs-on: ubuntu-latest
needs: release # This job depends on the release job
if: needs.release.outputs.check-publish.published == 'true' # Check the output of the check-publish step
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,7 @@ $RECYCLE.BIN/
!.yarn/plugins
!.yarn/sdks
!.yarn/versions
.yarn/install-state.gz

# if you are NOT using Zero-installs, then:
# comment the following lines
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed .yarn/cache/ws-npm-8.14.1-65c71ef1c9-9e310be2b0.zip
Binary file not shown.
Binary file removed .yarn/install-state.gz
Binary file not shown.
13 changes: 11 additions & 2 deletions apps/InfiniteRedAI/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,21 @@ const { defaults: tsjPreset } = require("ts-jest/presets")
/** @type {import('@jest/types').Config.ProjectConfig} */
module.exports = {
...tsjPreset,
preset: "jest-expo",
transformIgnorePatterns: [
"<rootDir>/node_modules/(react-clone-referenced-element|@react-native-community|react-navigation|@react-navigation/.*|@unimodules/.*|native-base|react-native-code-push)",
"jest-runner",
],
testPathIgnorePatterns: ["<rootDir>/node_modules/", "<rootDir>/.maestro/", "@react-native"],
testEnvironment: "jsdom",
preset: "react-native",
transform: {
"^.+\\.jsx$": "babel-jest",
"^.+\\.tsx?$": [
"ts-jest",
{
tsconfig: "tsconfig.spec.json",
},
],
},
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
setupFiles: ["<rootDir>/test/setup.ts"],
}
6 changes: 6 additions & 0 deletions apps/InfiniteRedAI/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"jsx": "react"
}
}
37 changes: 0 additions & 37 deletions modules/react-native-mlkit-core/.circleci/config.yml

This file was deleted.

40 changes: 0 additions & 40 deletions modules/react-native-mlkit-face-detection/.circleci/config.yml

This file was deleted.

Loading

0 comments on commit cb04b54

Please sign in to comment.