|
| 1 | +workflow: |
| 2 | + rules: |
| 3 | + # Disable merge request pipelines |
| 4 | + - if: $CI_MERGE_REQUEST_ID |
| 5 | + when: never |
| 6 | + - when: always |
| 7 | + |
1 | 8 | default:
|
2 | 9 | interruptible: true
|
3 | 10 |
|
4 | 11 | variables:
|
| 12 | + GH_PROJECT_PATH: "MatrixAI/${CI_PROJECT_NAME}" |
| 13 | + GH_PROJECT_URL: "https://${GITHUB_TOKEN}@github.com/${GH_PROJECT_PATH}.git" |
5 | 14 | GIT_SUBMODULE_STRATEGY: recursive
|
| 15 | + # Cache .npm |
| 16 | + NPM_CONFIG_CACHE: "${CI_PROJECT_DIR}/tmp/npm" |
| 17 | + # Prefer offline node module installation |
| 18 | + NPM_CONFIG_PREFER_OFFLINE: "true" |
| 19 | + # `ts-node` has its own cache |
| 20 | + TS_CACHED_TRANSPILE_CACHE: "${CI_PROJECT_DIR}/tmp/ts-node-cache" |
| 21 | + TS_CACHED_TRANSPILE_PORTABLE: "true" |
| 22 | + # Homebrew cache only used by macos runner |
| 23 | + HOMEBREW_CACHE: "${CI_PROJECT_DIR}/tmp/Homebrew" |
| 24 | + |
| 25 | +# Cached directories shared between jobs & pipelines per-branch per-runner |
| 26 | +cache: |
| 27 | + key: $CI_COMMIT_REF_SLUG |
| 28 | + paths: |
| 29 | + - ./tmp/npm/ |
| 30 | + - ./tmp/ts-node-cache/ |
| 31 | + # Homebrew cache is only used by the macos runner |
| 32 | + - ./tmp/Homebrew |
| 33 | + # `jest` cache is configured in jest.config.js |
| 34 | + - ./tmp/jest/ |
6 | 35 |
|
7 | 36 | stages:
|
8 |
| - - check |
| 37 | + - check # Linting, unit tests |
| 38 | + - build # Cross-platform library compilation, unit tests |
| 39 | + - integration # Cross-platform application bundling, integration tests, and pre-release |
| 40 | + - release # Cross-platform distribution and deployment |
9 | 41 |
|
10 | 42 | image: registry.gitlab.com/matrixai/engineering/maintenance/gitlab-runner
|
11 | 43 |
|
12 |
| -lint: |
| 44 | +check:lint: |
13 | 45 | stage: check
|
14 |
| - interruptible: true |
| 46 | + needs: [] |
15 | 47 | script:
|
16 | 48 | - >
|
17 | 49 | nix-shell --run '
|
18 | 50 | npm run lint;
|
19 | 51 | '
|
| 52 | + rules: |
| 53 | + # Runs on feature and staging commits and ignores version commits |
| 54 | + - if: $CI_COMMIT_BRANCH =~ /^(?:feature.*|staging)$/ && $CI_COMMIT_TITLE !~ /^[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/ |
| 55 | + # Runs on tag pipeline where the tag is a prerelease or release version |
| 56 | + - if: $CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/ |
| 57 | + # Manually run on commits other than master and ignore version commits |
| 58 | + - if: $CI_COMMIT_BRANCH && $CI_COMMIT_BRANCH != 'master' && $CI_COMMIT_TITLE !~ /^[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/ |
| 59 | + when: manual |
20 | 60 |
|
21 |
| -test: |
| 61 | +check:nix-dry: |
22 | 62 | stage: check
|
23 |
| - interruptible: true |
| 63 | + needs: [] |
| 64 | + script: |
| 65 | + - nix-build -v -v --dry-run ./release.nix |
| 66 | + rules: |
| 67 | + # Runs on feature and staging commits and ignores version commits |
| 68 | + - if: $CI_COMMIT_BRANCH =~ /^(?:feature.*|staging)$/ && $CI_COMMIT_TITLE !~ /^[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/ |
| 69 | + # Runs on tag pipeline where the tag is a prerelease or release version |
| 70 | + - if: $CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/ |
| 71 | + # Manually run on commits other than master and ignore version commits |
| 72 | + - if: $CI_COMMIT_BRANCH && $CI_COMMIT_BRANCH != 'master' && $CI_COMMIT_TITLE !~ /^[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/ |
| 73 | + when: manual |
| 74 | + |
| 75 | +check:test: |
| 76 | + stage: check |
| 77 | + needs: [] |
| 78 | + script: |
| 79 | + - > |
| 80 | + nix-shell --run ' |
| 81 | + npm run build --verbose; |
| 82 | + npm test -- --ci; |
| 83 | + ' |
| 84 | + artifacts: |
| 85 | + when: always |
| 86 | + reports: |
| 87 | + junit: |
| 88 | + - ./tmp/junit.xml |
| 89 | + rules: |
| 90 | + # Runs on staging commits and ignores version commits |
| 91 | + - if: $CI_COMMIT_BRANCH =~ /^feature.*$/ && $CI_COMMIT_TITLE !~ /^[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/ |
| 92 | + # Manually run on commits other than master and staging and ignore version commits |
| 93 | + - if: $CI_COMMIT_BRANCH && $CI_COMMIT_BRANCH !~ /^(?:master|staging)$/ && $CI_COMMIT_TITLE !~ /^[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/ |
| 94 | + when: manual |
| 95 | + |
| 96 | +build:merge: |
| 97 | + stage: build |
| 98 | + needs: [] |
| 99 | + allow_failure: true |
| 100 | + script: |
| 101 | + # Required for `gh pr create` |
| 102 | + - git remote add upstream "$GH_PROJECT_URL" |
| 103 | + - > |
| 104 | + nix-shell -I nixpkgs=./pkgs.nix --packages gitAndTools.gh --run ' |
| 105 | + gh pr create \ |
| 106 | + --head staging \ |
| 107 | + --base master \ |
| 108 | + --title "ci: merge staging to master" \ |
| 109 | + --body "This is an automatic PR generated by the pipeline CI/CD. This will be automatically fast-forward merged if successful." \ |
| 110 | + --assignee "@me" \ |
| 111 | + --no-maintainer-edit \ |
| 112 | + --repo "$GH_PROJECT_PATH" || true; |
| 113 | + printf "Pipeline Attempt on ${CI_PIPELINE_ID} for ${CI_COMMIT_SHA}\n\n${CI_PIPELINE_URL}" \ |
| 114 | + | gh pr comment staging \ |
| 115 | + --body-file - \ |
| 116 | + --repo "$GH_PROJECT_PATH"; |
| 117 | + ' |
| 118 | + rules: |
| 119 | + # Runs on staging commits and ignores version commits |
| 120 | + - if: $CI_COMMIT_BRANCH == 'staging' && $CI_COMMIT_TITLE !~ /^[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/ |
| 121 | + # Runs on tag pipeline where the tag is a prerelease or release version |
| 122 | + - if: $CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/ |
| 123 | + |
| 124 | +build:linux: |
| 125 | + stage: build |
| 126 | + needs: |
| 127 | + - job: check:lint |
| 128 | + optional: true |
24 | 129 | script:
|
25 | 130 | - >
|
26 | 131 | nix-shell --run '
|
27 |
| - npm run test; |
| 132 | + npm run build --verbose; |
| 133 | + npm test -- --ci; |
| 134 | + ' |
| 135 | + artifacts: |
| 136 | + when: always |
| 137 | + reports: |
| 138 | + junit: |
| 139 | + - ./tmp/junit.xml |
| 140 | + paths: |
| 141 | + - ./prebuilds/ |
| 142 | + # Only the build:linux preserves the dist |
| 143 | + - ./dist |
| 144 | + rules: |
| 145 | + # Runs on staging commits and ignores version commits |
| 146 | + - if: $CI_COMMIT_BRANCH == 'staging' && $CI_COMMIT_TITLE !~ /^[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/ |
| 147 | + # Runs on tag pipeline where the tag is a prerelease or release version |
| 148 | + - if: $CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/ |
| 149 | + |
| 150 | +build:windows: |
| 151 | + stage: build |
| 152 | + needs: |
| 153 | + - job: check:lint |
| 154 | + optional: true |
| 155 | + tags: |
| 156 | + - windows |
| 157 | + before_script: |
| 158 | + - choco install nodejs --version=16.14.2 -y |
| 159 | + - choco install python --version=3.9.12 -y |
| 160 | + - refreshenv |
| 161 | + script: |
| 162 | + - npm config set msvs_version 2019 |
| 163 | + - npm install --ignore-scripts |
| 164 | + - $env:Path = "$(npm bin);" + $env:Path |
| 165 | + - npm run build --verbose |
| 166 | + - npm test -- --ci |
| 167 | + artifacts: |
| 168 | + when: always |
| 169 | + reports: |
| 170 | + junit: |
| 171 | + - ./tmp/junit.xml |
| 172 | + paths: |
| 173 | + - ./prebuilds/ |
| 174 | + rules: |
| 175 | + # Runs on staging commits and ignores version commits |
| 176 | + - if: $CI_COMMIT_BRANCH == 'staging' && $CI_COMMIT_TITLE !~ /^[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/ |
| 177 | + # Runs on tag pipeline where the tag is a prerelease or release version |
| 178 | + - if: $CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/ |
| 179 | + |
| 180 | +build:macos: |
| 181 | + stage: build |
| 182 | + needs: |
| 183 | + - job: check:lint |
| 184 | + optional: true |
| 185 | + tags: |
| 186 | + - shared-macos-amd64 |
| 187 | + image: macos-11-xcode-12 |
| 188 | + variables: |
| 189 | + HOMEBREW_NO_INSTALL_UPGRADE: "true" |
| 190 | + HOMEBREW_NO_INSTALL_CLEANUP: "true" |
| 191 | + before_script: |
| 192 | + - brew install node@16 |
| 193 | + - brew link --overwrite node@16 |
| 194 | + |
| 195 | + - brew link --overwrite [email protected] |
| 196 | + - hash -r |
| 197 | + script: |
| 198 | + - npm install --ignore-scripts |
| 199 | + - export PATH="$(npm bin):$PATH" |
| 200 | + - export PREBUILD_ARCH=x64+arm64 |
| 201 | + - npm run build --verbose |
| 202 | + - npm test -- --ci |
| 203 | + artifacts: |
| 204 | + when: always |
| 205 | + reports: |
| 206 | + junit: |
| 207 | + - ./tmp/junit.xml |
| 208 | + paths: |
| 209 | + - ./prebuilds/ |
| 210 | + rules: |
| 211 | + # Runs on staging commits and ignores version commits |
| 212 | + - if: $CI_COMMIT_BRANCH == 'staging' && $CI_COMMIT_TITLE !~ /^[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/ |
| 213 | + # Runs on tag pipeline where the tag is a prerelease or release version |
| 214 | + - if: $CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/ |
| 215 | + |
| 216 | +integration:merge: |
| 217 | + stage: integration |
| 218 | + needs: |
| 219 | + - build:merge |
| 220 | + # Requires mutual exclusion |
| 221 | + resource_group: integration:merge |
| 222 | + allow_failure: true |
| 223 | + variables: |
| 224 | + # Ensure that CI/CD is fetching all commits |
| 225 | + # this is necessary to checkout origin/master |
| 226 | + # and to also merge origin/staging |
| 227 | + GIT_DEPTH: 0 |
| 228 | + script: |
| 229 | + - > |
| 230 | + nix-shell -I nixpkgs=./pkgs.nix --packages gitAndTools.gh --run ' |
| 231 | + printf "Pipeline Succeeded on ${CI_PIPELINE_ID} for ${CI_COMMIT_SHA}\n\n${CI_PIPELINE_URL}" \ |
| 232 | + | gh pr comment staging \ |
| 233 | + --body-file - \ |
| 234 | + --repo "$GH_PROJECT_PATH"; |
28 | 235 | '
|
| 236 | + - git remote add upstream "$GH_PROJECT_URL" |
| 237 | + - git checkout origin/master |
| 238 | + # Merge up to the current commit (not the latest commit) |
| 239 | + - git merge --ff-only "$CI_COMMIT_SHA" |
| 240 | + - git push upstream HEAD:master |
| 241 | + rules: |
| 242 | + # Runs on staging commits and ignores version commits |
| 243 | + - if: $CI_COMMIT_BRANCH == 'staging' && $CI_COMMIT_TITLE !~ /^[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/ |
| 244 | + # Runs on tag pipeline where the tag is a prerelease or release version |
| 245 | + - if: $CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/ |
0 commit comments