Skip to content

Commit f9fe5ce

Browse files
committed
ci: integrated scripts/choco-install.ps1 and scripts/brew-install.sh and all jobs use nix-shell --run
1 parent fc0f586 commit f9fe5ce

File tree

4 files changed

+92
-48
lines changed

4 files changed

+92
-48
lines changed

.gitlab-ci.yml

Lines changed: 47 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,33 @@ workflow:
55
when: never
66
- when: always
77

8-
default:
9-
interruptible: true
10-
118
variables:
9+
GIT_SUBMODULE_STRATEGY: recursive
1210
GH_PROJECT_PATH: "MatrixAI/${CI_PROJECT_NAME}"
1311
GH_PROJECT_URL: "https://${GITHUB_TOKEN}@github.com/${GH_PROJECT_PATH}.git"
14-
GIT_SUBMODULE_STRATEGY: recursive
1512
# Cache .npm
1613
NPM_CONFIG_CACHE: "${CI_PROJECT_DIR}/tmp/npm"
1714
# Prefer offline node module installation
1815
NPM_CONFIG_PREFER_OFFLINE: "true"
1916
# Homebrew cache only used by macos runner
2017
HOMEBREW_CACHE: "${CI_PROJECT_DIR}/tmp/Homebrew"
2118

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+
2226
# Cached directories shared between jobs & pipelines per-branch per-runner
2327
cache:
2428
key: $CI_COMMIT_REF_SLUG
2529
paths:
2630
- ./tmp/npm/
2731
# Homebrew cache is only used by the macos runner
2832
- ./tmp/Homebrew
33+
# Chocolatey cache is only used by the windows runner
34+
- ./tmp/chocolatey/
2935
# `jest` cache is configured in jest.config.js
3036
- ./tmp/jest/
3137

@@ -87,20 +93,20 @@ build:merge:
8793
# Required for `gh pr create`
8894
- git remote add upstream "$GH_PROJECT_URL"
8995
- >
90-
nix-shell -I nixpkgs=./pkgs.nix --packages gitAndTools.gh --run '
91-
gh pr create \
92-
--head staging \
93-
--base master \
94-
--title "ci: merge staging to master" \
95-
--body "This is an automatic PR generated by the pipeline CI/CD. This will be automatically fast-forward merged if successful." \
96-
--assignee "@me" \
97-
--no-maintainer-edit \
98-
--repo "$GH_PROJECT_PATH" || true;
99-
printf "Pipeline Attempt on ${CI_PIPELINE_ID} for ${CI_COMMIT_SHA}\n\n${CI_PIPELINE_URL}" \
100-
| gh pr comment staging \
101-
--body-file - \
102-
--repo "$GH_PROJECT_PATH";
103-
'
96+
nix-shell --run '
97+
gh pr create \
98+
--head staging \
99+
--base master \
100+
--title "ci: merge staging to master" \
101+
--body "This is an automatic PR generated by the pipeline CI/CD. This will be automatically fast-forward merged if successful." \
102+
--assignee "@me" \
103+
--no-maintainer-edit \
104+
--repo "$GH_PROJECT_PATH" || true;
105+
printf "Pipeline Attempt on ${CI_PIPELINE_ID} for ${CI_COMMIT_SHA}\n\n${CI_PIPELINE_URL}" \
106+
| gh pr comment staging \
107+
--body-file - \
108+
--repo "$GH_PROJECT_PATH";
109+
'
104110
rules:
105111
# Runs on staging commits and ignores version commits
106112
- if: $CI_COMMIT_BRANCH == 'staging' && $CI_COMMIT_TITLE !~ /^[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/
@@ -112,10 +118,10 @@ build:linux:
112118
needs: []
113119
script:
114120
- >
115-
nix-shell --run '
116-
npm run build --verbose;
117-
npm test -- --ci --coverage;
118-
'
121+
nix-shell --run '
122+
npm run build --verbose;
123+
npm test -- --ci --coverage;
124+
'
119125
artifacts:
120126
when: always
121127
reports:
@@ -140,10 +146,10 @@ build:windows:
140146
tags:
141147
- windows
142148
before_script:
143-
- choco install nodejs --version=16.14.2 -y
144-
- refreshenv
149+
- mkdir -Force "$CI_PROJECT_DIR/tmp"
145150
script:
146-
- npm config set msvs_version 2019
151+
- .\scripts\choco-install.ps1
152+
- refreshenv
147153
- npm install --ignore-scripts
148154
- $env:Path = "$(npm bin);" + $env:Path
149155
- npm run build --verbose
@@ -165,15 +171,10 @@ build:macos:
165171
tags:
166172
- shared-macos-amd64
167173
image: macos-11-xcode-12
168-
variables:
169-
HOMEBREW_NO_INSTALL_UPGRADE: "true"
170-
HOMEBREW_NO_INSTALL_CLEANUP: "true"
171-
before_script:
174+
script:
172175
- eval "$(brew shellenv)"
173-
- brew install node@16
174-
- brew link --overwrite node@16
176+
- ./scripts/brew-install.sh
175177
- hash -r
176-
script:
177178
- npm install --ignore-scripts
178179
- export PATH="$(npm bin):$PATH"
179180
- npm run build --verbose
@@ -197,14 +198,13 @@ build:prerelease:
197198
- build:macos
198199
# Don't interrupt publishing job
199200
interruptible: false
200-
before_script:
201-
- echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ./.npmrc
202201
script:
202+
- echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ./.npmrc
203203
- echo 'Publishing library prerelease'
204204
- >
205-
nix-shell --run '
206-
npm publish --tag prerelease --access public;
207-
'
205+
nix-shell --run '
206+
npm publish --tag prerelease --access public;
207+
'
208208
after_script:
209209
- rm -f ./.npmrc
210210
rules:
@@ -234,12 +234,12 @@ integration:merge:
234234
GIT_DEPTH: 0
235235
script:
236236
- >
237-
nix-shell -I nixpkgs=./pkgs.nix --packages gitAndTools.gh --run '
238-
printf "Pipeline Succeeded on ${CI_PIPELINE_ID} for ${CI_COMMIT_SHA}\n\n${CI_PIPELINE_URL}" \
239-
| gh pr comment staging \
240-
--body-file - \
241-
--repo "$GH_PROJECT_PATH";
242-
'
237+
nix-shell --run '
238+
printf "Pipeline Succeeded on ${CI_PIPELINE_ID} for ${CI_COMMIT_SHA}\n\n${CI_PIPELINE_URL}" \
239+
| gh pr comment staging \
240+
--body-file - \
241+
--repo "$GH_PROJECT_PATH";
242+
'
243243
- git remote add upstream "$GH_PROJECT_URL"
244244
- git checkout origin/master
245245
# Merge up to the current commit (not the latest commit)
@@ -260,14 +260,13 @@ release:distribution:
260260
- integration:merge
261261
# Don't interrupt publishing job
262262
interruptible: false
263-
before_script:
264-
- echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ./.npmrc
265263
script:
264+
- echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ./.npmrc
266265
- echo 'Publishing library'
267266
- >
268-
nix-shell --run '
269-
npm publish --access public;
270-
'
267+
nix-shell --run '
268+
npm publish --access public;
269+
'
271270
after_script:
272271
- rm -f ./.npmrc
273272
rules:

scripts/brew-install.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
3+
set -o errexit # abort on nonzero exitstatus
4+
set -o nounset # abort on unbound variable
5+
set -o pipefail # don't hide errors within pipes
6+
7+
export HOMEBREW_NO_INSTALL_UPGRADE=1
8+
export HOMEBREW_NO_INSTALL_CLEANUP=1
9+
export HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK=1
10+
export HOMEBREW_NO_AUTO_UPDATE=1
11+
export HOMEBREW_NO_ANALYTICS=1
12+
13+
brew install node@16
14+
brew link --overwrite node@16

scripts/choco-install.ps1

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
function Save-ChocoPackage {
2+
param (
3+
$PackageName
4+
)
5+
Rename-Item -Path "$env:ChocolateyInstall\lib\$PackageName\$PackageName.nupkg" -NewName "$PackageName.nupkg.zip" -ErrorAction:SilentlyContinue
6+
Expand-Archive -LiteralPath "$env:ChocolateyInstall\lib\$PackageName\$PackageName.nupkg.zip" -DestinationPath "$env:ChocolateyInstall\lib\$PackageName" -Force
7+
Remove-Item "$env:ChocolateyInstall\lib\$PackageName\_rels" -Recurse
8+
Remove-Item "$env:ChocolateyInstall\lib\$PackageName\package" -Recurse
9+
Remove-Item "$env:ChocolateyInstall\lib\$PackageName\[Content_Types].xml"
10+
New-Item -Path "${PSScriptRoot}\..\tmp\chocolatey\$PackageName" -ItemType "directory" -ErrorAction:SilentlyContinue
11+
choco pack "$env:ChocolateyInstall\lib\$PackageName\$PackageName.nuspec" --outdir "${PSScriptRoot}\..\tmp\chocolatey\$PackageName"
12+
}
13+
14+
# Check for existence of required environment variables
15+
if ( $null -eq $env:ChocolateyInstall ) {
16+
[Console]::Error.WriteLine('Missing $env:ChocolateyInstall environment variable')
17+
exit 1
18+
}
19+
20+
# Add the cached packages with source priority 1 (Chocolatey community is 0)
21+
New-Item -Path "${PSScriptRoot}\..\tmp\chocolatey" -ItemType "directory" -ErrorAction:SilentlyContinue
22+
choco source add --name="cache" --source="${PSScriptRoot}\..\tmp\chocolatey" --priority=1
23+
24+
# Install nodejs v16.15.1 (will use cache if exists)
25+
$nodejs = "nodejs.install"
26+
choco install "$nodejs" --version="16.15.1" --require-checksums -y
27+
# Internalise nodejs to cache if doesn't exist
28+
if ( -not (Test-Path -Path "${PSScriptRoot}\..\tmp\chocolatey\$nodejs\$nodejs.16.15.1.nupkg" -PathType Leaf) ) {
29+
Save-ChocoPackage -PackageName $nodejs
30+
}

shell.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ with pkgs;
44
mkShell {
55
nativeBuildInputs = [
66
nodejs
7+
gitAndTools.gh
78
];
89
shellHook = ''
910
echo "Entering $(npm pkg get name)"

0 commit comments

Comments
 (0)