|
| 1 | +workflow: |
| 2 | + rules: |
| 3 | + # Disable merge request pipelines |
| 4 | + - if: $CI_MERGE_REQUEST_ID |
| 5 | + when: never |
| 6 | + - when: always |
| 7 | + |
| 8 | +variables: |
| 9 | + GIT_SUBMODULE_STRATEGY: recursive |
| 10 | + GH_PROJECT_PATH: "MatrixAI/${CI_PROJECT_NAME}" |
| 11 | + GH_PROJECT_URL: "https://${GITHUB_TOKEN}@github.com/${GH_PROJECT_PATH}.git" |
| 12 | + # Cache .npm |
| 13 | + npm_config_cache: "${CI_PROJECT_DIR}/tmp/npm" |
| 14 | + # Prefer offline node module installation |
| 15 | + npm_config_prefer_offline: "true" |
| 16 | + # Homebrew cache only used by macos runner |
| 17 | + HOMEBREW_CACHE: "${CI_PROJECT_DIR}/tmp/Homebrew" |
| 18 | + |
| 19 | +default: |
| 20 | + interruptible: true |
| 21 | + before_script: |
| 22 | + # Replace this in windows runners that use powershell |
| 23 | + # with `mkdir -Force "$CI_PROJECT_DIR/tmp"` |
| 24 | + - mkdir -p "$CI_PROJECT_DIR/tmp" |
| 25 | + |
| 26 | +# Cached directories shared between jobs & pipelines per-branch per-runner |
| 27 | +cache: |
| 28 | + key: $CI_COMMIT_REF_SLUG |
| 29 | + # Preserve cache even if job fails |
| 30 | + when: 'always' |
| 31 | + paths: |
| 32 | + - ./tmp/npm/ |
| 33 | + # Homebrew cache is only used by the macos runner |
| 34 | + - ./tmp/Homebrew |
| 35 | + # Chocolatey cache is only used by the windows runner |
| 36 | + - ./tmp/chocolatey/ |
| 37 | + # `jest` cache is configured in jest.config.js |
| 38 | + - ./tmp/jest/ |
| 39 | + |
| 40 | +stages: |
| 41 | + - check # Linting, unit tests |
| 42 | + - build # Cross-platform library compilation, unit tests |
| 43 | + - integration # Cross-platform application bundling, integration tests, and pre-release |
| 44 | + - release # Cross-platform distribution and deployment |
| 45 | + |
| 46 | +image: registry.gitlab.com/matrixai/engineering/maintenance/gitlab-runner |
| 47 | + |
| 48 | +check:lint: |
| 49 | + stage: check |
| 50 | + needs: [] |
| 51 | + script: |
| 52 | + - > |
| 53 | + nix-shell --arg ci true --run $' |
| 54 | + npm run lint; |
| 55 | + npm run lint-shell; |
| 56 | + ' |
| 57 | + rules: |
| 58 | + # Runs on feature and staging commits and ignores version commits |
| 59 | + - if: $CI_COMMIT_BRANCH =~ /^(?:feature.*|staging)$/ && $CI_COMMIT_TITLE !~ /^[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/ |
| 60 | + # Runs on tag pipeline where the tag is a prerelease or release version |
| 61 | + - if: $CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/ |
| 62 | + # Manually run on commits other than master and ignore version commits |
| 63 | + - if: $CI_COMMIT_BRANCH && $CI_COMMIT_BRANCH != 'master' && $CI_COMMIT_TITLE !~ /^[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/ |
| 64 | + when: manual |
| 65 | + |
| 66 | +check:test: |
| 67 | + stage: check |
| 68 | + needs: [] |
| 69 | + script: |
| 70 | + - > |
| 71 | + nix-shell --arg ci true --run $' |
| 72 | + npm test -- --ci --coverage; |
| 73 | + ' |
| 74 | + artifacts: |
| 75 | + when: always |
| 76 | + reports: |
| 77 | + junit: |
| 78 | + - ./tmp/junit/junit.xml |
| 79 | + coverage_report: |
| 80 | + coverage_format: cobertura |
| 81 | + path: ./tmp/coverage/cobertura-coverage.xml |
| 82 | + coverage: '/All files[^|]*\|[^|]*\s+([\d\.]+)/' |
| 83 | + rules: |
| 84 | + # Runs on feature commits and ignores version commits |
| 85 | + - if: $CI_COMMIT_BRANCH =~ /^feature.*$/ && $CI_COMMIT_TITLE !~ /^[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/ |
| 86 | + # Manually run on commits other than master and staging and ignore version commits |
| 87 | + - if: $CI_COMMIT_BRANCH && $CI_COMMIT_BRANCH !~ /^(?:master|staging)$/ && $CI_COMMIT_TITLE !~ /^[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/ |
| 88 | + when: manual |
| 89 | + |
| 90 | +build:merge: |
| 91 | + stage: build |
| 92 | + needs: [] |
| 93 | + allow_failure: true |
| 94 | + script: |
| 95 | + # Required for `gh pr create` |
| 96 | + - git remote add upstream "$GH_PROJECT_URL" |
| 97 | + - > |
| 98 | + nix-shell --arg ci true --run $' |
| 99 | + gh pr create \ |
| 100 | + --head staging \ |
| 101 | + --base master \ |
| 102 | + --title "ci: merge staging to master" \ |
| 103 | + --body "This is an automatic PR generated by the pipeline CI/CD. This will be automatically fast-forward merged if successful." \ |
| 104 | + --assignee "@me" \ |
| 105 | + --no-maintainer-edit \ |
| 106 | + --repo "$GH_PROJECT_PATH" || true; |
| 107 | + printf "Pipeline Attempt on ${CI_PIPELINE_ID} for ${CI_COMMIT_SHA}\n\n${CI_PIPELINE_URL}" \ |
| 108 | + | gh pr comment staging \ |
| 109 | + --body-file - \ |
| 110 | + --repo "$GH_PROJECT_PATH"; |
| 111 | + ' |
| 112 | + rules: |
| 113 | + # Runs on staging commits and ignores version commits |
| 114 | + - if: $CI_COMMIT_BRANCH == 'staging' && $CI_COMMIT_TITLE !~ /^[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/ |
| 115 | + # Runs on tag pipeline where the tag is a prerelease or release version |
| 116 | + - if: $CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/ |
| 117 | + |
| 118 | +build:dist: |
| 119 | + stage: build |
| 120 | + needs: [] |
| 121 | + script: |
| 122 | + - > |
| 123 | + nix-shell --arg ci true --run $' |
| 124 | + npm run build --verbose; |
| 125 | + ' |
| 126 | + artifacts: |
| 127 | + when: always |
| 128 | + paths: |
| 129 | + - ./dist |
| 130 | + rules: |
| 131 | + # Runs on staging commits and ignores version commits |
| 132 | + - if: $CI_COMMIT_BRANCH == 'staging' && $CI_COMMIT_TITLE !~ /^[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/ |
| 133 | + # Runs on tag pipeline where the tag is a prerelease or release version |
| 134 | + - if: $CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/ |
| 135 | + |
| 136 | +build:linux: |
| 137 | + stage: build |
| 138 | + needs: [] |
| 139 | + script: |
| 140 | + - > |
| 141 | + nix-shell --arg ci true --run $' |
| 142 | + npm test -- --ci --coverage; |
| 143 | + npm run bench; |
| 144 | + ' |
| 145 | + artifacts: |
| 146 | + when: always |
| 147 | + reports: |
| 148 | + junit: |
| 149 | + - ./tmp/junit/junit.xml |
| 150 | + coverage_report: |
| 151 | + coverage_format: cobertura |
| 152 | + path: ./tmp/coverage/cobertura-coverage.xml |
| 153 | + metrics: ./benches/results/metrics.txt |
| 154 | + coverage: '/All files[^|]*\|[^|]*\s+([\d\.]+)/' |
| 155 | + rules: |
| 156 | + # Runs on staging commits and ignores version commits |
| 157 | + - if: $CI_COMMIT_BRANCH == 'staging' && $CI_COMMIT_TITLE !~ /^[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/ |
| 158 | + # Runs on tag pipeline where the tag is a prerelease or release version |
| 159 | + - if: $CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/ |
| 160 | + |
| 161 | +build:windows: |
| 162 | + stage: build |
| 163 | + needs: [] |
| 164 | + tags: |
| 165 | + - windows |
| 166 | + before_script: |
| 167 | + - mkdir -Force "$CI_PROJECT_DIR/tmp" |
| 168 | + script: |
| 169 | + - .\scripts\choco-install.ps1 |
| 170 | + - refreshenv |
| 171 | + - npm install --ignore-scripts |
| 172 | + - $env:Path = "$(npm root)\.bin;" + $env:Path |
| 173 | + - npm test -- --ci --coverage |
| 174 | + - npm run bench |
| 175 | + artifacts: |
| 176 | + when: always |
| 177 | + reports: |
| 178 | + junit: |
| 179 | + - ./tmp/junit/junit.xml |
| 180 | + coverage_report: |
| 181 | + coverage_format: cobertura |
| 182 | + path: ./tmp/coverage/cobertura-coverage.xml |
| 183 | + metrics: ./benches/results/metrics.txt |
| 184 | + coverage: '/All files[^|]*\|[^|]*\s+([\d\.]+)/' |
| 185 | + rules: |
| 186 | + # Runs on staging commits and ignores version commits |
| 187 | + - if: $CI_COMMIT_BRANCH == 'staging' && $CI_COMMIT_TITLE !~ /^[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/ |
| 188 | + # Runs on tag pipeline where the tag is a prerelease or release version |
| 189 | + - if: $CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/ |
| 190 | + |
| 191 | +build:macos: |
| 192 | + stage: build |
| 193 | + needs: [] |
| 194 | + tags: |
| 195 | + - saas-macos-medium-m1 |
| 196 | + image: macos-12-xcode-14 |
| 197 | + script: |
| 198 | + - eval "$(brew shellenv)" |
| 199 | + - ./scripts/brew-install.sh |
| 200 | + - hash -r |
| 201 | + - npm install --ignore-scripts |
| 202 | + - export PATH="$(npm root)/.bin:$PATH" |
| 203 | + - npm test -- --ci --coverage |
| 204 | + - npm run bench |
| 205 | + artifacts: |
| 206 | + when: always |
| 207 | + reports: |
| 208 | + junit: |
| 209 | + - ./tmp/junit/junit.xml |
| 210 | + coverage_report: |
| 211 | + coverage_format: cobertura |
| 212 | + path: ./tmp/coverage/cobertura-coverage.xml |
| 213 | + metrics: ./benches/results/metrics.txt |
| 214 | + coverage: '/All files[^|]*\|[^|]*\s+([\d\.]+)/' |
| 215 | + rules: |
| 216 | + # Runs on staging commits and ignores version commits |
| 217 | + - if: $CI_COMMIT_BRANCH == 'staging' && $CI_COMMIT_TITLE !~ /^[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/ |
| 218 | + # Runs on tag pipeline where the tag is a prerelease or release version |
| 219 | + - if: $CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/ |
| 220 | + |
| 221 | +build:prerelease: |
| 222 | + stage: build |
| 223 | + needs: |
| 224 | + - build:dist |
| 225 | + - build:linux |
| 226 | + - build:windows |
| 227 | + - build:macos |
| 228 | + # Don't interrupt publishing job |
| 229 | + interruptible: false |
| 230 | + script: |
| 231 | + - echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ./.npmrc |
| 232 | + - echo 'Publishing library prerelease' |
| 233 | + - > |
| 234 | + nix-shell --arg ci true --run $' |
| 235 | + npm publish --tag prerelease --access public; |
| 236 | + ' |
| 237 | + after_script: |
| 238 | + - rm -f ./.npmrc |
| 239 | + rules: |
| 240 | + # Only runs on tag pipeline where the tag is a prerelease version |
| 241 | + # This requires dependencies to also run on tag pipeline |
| 242 | + # However version tag comes with a version commit |
| 243 | + # Dependencies must not run on the version commit |
| 244 | + - if: $CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+-.*[0-9]+$/ |
| 245 | + |
| 246 | +integration:merge: |
| 247 | + stage: integration |
| 248 | + needs: |
| 249 | + - build:merge |
| 250 | + - job: build:linux |
| 251 | + optional: true |
| 252 | + - job: build:windows |
| 253 | + optional: true |
| 254 | + - job: build:macos |
| 255 | + optional: true |
| 256 | + # Requires mutual exclusion |
| 257 | + resource_group: integration:merge |
| 258 | + allow_failure: true |
| 259 | + variables: |
| 260 | + # Ensure that CI/CD is fetching all commits |
| 261 | + # this is necessary to checkout origin/master |
| 262 | + # and to also merge origin/staging |
| 263 | + GIT_DEPTH: 0 |
| 264 | + script: |
| 265 | + - > |
| 266 | + nix-shell --arg ci true --run $' |
| 267 | + printf "Pipeline Succeeded on ${CI_PIPELINE_ID} for ${CI_COMMIT_SHA}\n\n${CI_PIPELINE_URL}" \ |
| 268 | + | gh pr comment staging \ |
| 269 | + --body-file - \ |
| 270 | + --repo "$GH_PROJECT_PATH"; |
| 271 | + ' |
| 272 | + - git remote add upstream "$GH_PROJECT_URL" |
| 273 | + - git checkout origin/master |
| 274 | + # Merge up to the current commit (not the latest commit) |
| 275 | + - git merge --ff-only "$CI_COMMIT_SHA" |
| 276 | + - git push upstream HEAD:master |
| 277 | + rules: |
| 278 | + # Runs on staging commits and ignores version commits |
| 279 | + - if: $CI_COMMIT_BRANCH == 'staging' && $CI_COMMIT_TITLE !~ /^[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/ |
| 280 | + # Runs on tag pipeline where the tag is a prerelease or release version |
| 281 | + - if: $CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/ |
| 282 | + |
| 283 | +release:distribution: |
| 284 | + stage: release |
| 285 | + needs: |
| 286 | + - build:dist |
| 287 | + - build:linux |
| 288 | + - build:windows |
| 289 | + - build:macos |
| 290 | + - integration:merge |
| 291 | + # Don't interrupt publishing job |
| 292 | + interruptible: false |
| 293 | + script: |
| 294 | + - echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ./.npmrc |
| 295 | + - echo 'Publishing library' |
| 296 | + - > |
| 297 | + nix-shell --arg ci true --run $' |
| 298 | + npm publish --access public; |
| 299 | + ' |
| 300 | + after_script: |
| 301 | + - rm -f ./.npmrc |
| 302 | + rules: |
| 303 | + # Only runs on tag pipeline where the tag is a release version |
| 304 | + # This requires dependencies to also run on tag pipeline |
| 305 | + # However version tag comes with a version commit |
| 306 | + # Dependencies must not run on the version commit |
| 307 | + - if: $CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+$/ |
0 commit comments