Skip to content

Commit

Permalink
Run lint, unit, and E2E tests on Buildkite (issue with caching)
Browse files Browse the repository at this point in the history
  • Loading branch information
mokagio committed Apr 24, 2024
1 parent 78e62b2 commit 2b6c499
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 3 deletions.
51 changes: 51 additions & 0 deletions .buildkite/commands/install-node-dependencies.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/bash -eu

PLATFORM=$(uname -s)
ARCHITECTURE=$(uname -m)
NODE_VERSION=$(node --version)
PACKAGE_HASH=$(hash_file package-lock.json)

CACHEKEY="$BUILDKITE_PIPELINE_SLUG-npm-$PLATFORM-$ARCHITECTURE-node-$NODE_VERSION-$PACKAGE_HASH"

LOCAL_NPM_CACHE=./vendor/npm
mkdir -p $LOCAL_NPM_CACHE
echo "--- :npm: Set npm to use $LOCAL_NPM_CACHE for cache"
npm set cache $LOCAL_NPM_CACHE
echo "npm cache set to $(npm get cache)"

echo "--- :npm: Restore npm cache if present"
restore_cache "$CACHEKEY"

echo "--- :npm: Install Node dependencies"

MAX_SOCKETS=15 # Default value from npm

# To avoid constant ECONNRESET errors a limit is set for Linux,
# as this is not happening with the Mac jobs.
# This issue is being tracked here:
# https://github.com/npm/cli/issues/4652
if [ "$PLATFORM" = "Linux" ]; then
MAX_SOCKETS=1
fi

npm ci \
--unsafe-perm \
--prefer-offline \
--no-audit \
--no-progress \
--maxsockets "$MAX_SOCKETS" \
"$@"

echo "--- :npm: Save cache if necessary"
# Notice that we don't cache the local node_modules.
# Those get regenerated by npm ci as per Node reccomendations.
# What we are caching is the root npm folder, which stores pacakge downloads so they are available if the package.json resolution demands them.
#
# npm stores temporary files in ~/.npm that we don't want to extract because they might run into naming conflicts.
# So, before archiving it, we remove those tmp files.
#
# Example: https://buildkite.com/automattic/gutenberg-mobile/builds/8857#018e37eb-7afc-4280-b736-cba76f02f1a3/524
rm -rf "$LOCAL_NPM_CACHE/_cacache/tmp"
save_cache "$LOCAL_NPM_CACHE" "$CACHEKEY"

tar -czf "$LOCAL_NPM_CACHE" cache.tar.gz
38 changes: 35 additions & 3 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Nodes with values to reuse in the pipeline.
common_params:
plugins: &common_plugins
- automattic/a8c-ci-toolkit#3.1.0
- automattic/a8c-ci-toolkit#3.3.0
- automattic/nvm#0.3.0

# All current steps use the same agent and environment; we can define them as top-level
Expand All @@ -11,13 +11,45 @@ env:
IMAGE_ID: xcode-15.2

steps:
- label: Lint
key: lint
command: |
.buildkite/commands/install-node-dependencies.sh
echo '--- :eslint: Lint'
npm run lint
agents:
queue: default
plugins: *common_plugins
artifact_paths:
- cache.tar.gz

- label: Unit Tests
key: unit_tests
command: |
.buildkite/commands/install-node-dependencies.sh
echo '--- :npm: Run Unit Tests'
npm run test
agents:
queue: default
plugins: *common_plugins

- label: End To End (macOS only)
key: e2e_macos
plugins: *common_plugins
command: |
.buildkite/commands/install-node-dependencies.sh
echo '--- :package: Build app'
npm run package
echo '--- Run E2E Tests'
npm run e2e
- label: '🔨 Create Dev Build'
key: 'dev'
command: |
.buildkite/commands/prepare-environment.sh
.buildkite/commands/install-node-dependencies.sh
echo "--- :node: Building Binary"
npm install
node ./scripts/prepare-dev-build-version.mjs
npm run make:macos-x64
npm run make:macos-arm64
Expand All @@ -36,9 +68,9 @@ steps:
key: 'release'
command: |
.buildkite/commands/prepare-environment.sh
.buildkite/commands/install-node-dependencies.sh
echo "--- :node: Building Binary"
npm install
node ./scripts/confirm-tag-matches-version.mjs
npm run make:macos-x64
npm run make:macos-arm64
Expand Down

0 comments on commit 2b6c499

Please sign in to comment.