Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bundle npm&npx #230

Closed
wants to merge 31 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
b4a8c15
Use abs path of npm
tianfeng92 Sep 5, 2023
91a718a
Bundle npm&npx
tianfeng92 Sep 6, 2023
c30c29c
add bundle to path?
tianfeng92 Sep 6, 2023
4ede102
copy dereference files
tianfeng92 Sep 6, 2023
e580d06
print PATH
tianfeng92 Sep 6, 2023
91c89f5
bundle npm&npx through download link
tianfeng92 Sep 6, 2023
34c38f3
oops
tianfeng92 Sep 6, 2023
b6254f2
update nodeBin
tianfeng92 Sep 6, 2023
19e43b2
what about this one?
tianfeng92 Sep 6, 2023
f95b176
use amd64
tianfeng92 Sep 6, 2023
79e636b
update downloading script
tianfeng92 Sep 6, 2023
c58f6f8
fix test
tianfeng92 Sep 6, 2023
cb51af1
update win bundle
tianfeng92 Sep 6, 2023
172d12b
use curl
tianfeng92 Sep 6, 2023
6313ec0
am I blind?
tianfeng92 Sep 6, 2023
21d915c
log platform name
tianfeng92 Sep 6, 2023
638ab97
maybe windows needs cmd?
tianfeng92 Sep 7, 2023
8271d9b
npmBin needs js
tianfeng92 Sep 7, 2023
520188d
do I need to set the PATH?
tianfeng92 Sep 7, 2023
ece9b29
Revert "do I need to set the PATH?"
tianfeng92 Sep 7, 2023
4c119f8
remove debug code
tianfeng92 Sep 7, 2023
2c1e657
use path.delimiter
tianfeng92 Sep 7, 2023
4cd9b3c
modify nodeBin location
tianfeng92 Sep 7, 2023
fb20f3b
file and folder cannot use the same name
tianfeng92 Sep 7, 2023
6a5e8e7
update npmBin location
tianfeng92 Sep 7, 2023
33d9755
print nodeBin
tianfeng92 Sep 7, 2023
d92dc07
set the only node
tianfeng92 Sep 7, 2023
ceaf28c
Revert "set the only node"
tianfeng92 Sep 7, 2023
a1b6034
fix relative path of npm for mac platform
tianfeng92 Sep 7, 2023
7b45f2a
cleanup code
tianfeng92 Sep 7, 2023
9ecb7b1
update comment
tianfeng92 Sep 7, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ jobs:

- name: Bundle Directory
if: ${{ steps.prep.outputs.asset_id == '' }}
run: bash ./scripts/bundle.sh
run: bash ./scripts/bundle-win.sh

- name: List Bundle Contents
if: ${{ steps.prep.outputs.asset_id == '' }}
Expand Down Expand Up @@ -211,7 +211,7 @@ jobs:

- name: Bundle Directory
if: ${{ steps.prep.outputs.asset_id == '' }}
run: bash ./scripts/bundle.sh
run: bash ./scripts/bundle-mac.sh

- name: List Bundle Contents
if: ${{ steps.prep.outputs.asset_id == '' }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ jobs:
run: npm version --no-git-tag-version 1.0.0

- name: Bundle Directory
run: bash ./scripts/bundle.sh
run: bash ./scripts/bundle-win.sh

- name: Archive Bundle
uses: azure/powershell@v1
Expand Down Expand Up @@ -171,7 +171,7 @@ jobs:
run: npm version --no-git-tag-version 1.0.0

- name: Bundle Directory
run: bash ./scripts/bundle.sh
run: bash ./scripts/bundle-mac.sh

- name: Archive Bundle
run: zip --symlinks -r playwright-macos-amd64.zip bundle/
Expand Down
35 changes: 35 additions & 0 deletions scripts/bundle-mac.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
set -e
echo "Using: $(which node)"
export PLAYWRIGHT_BROWSERS_PATH=$PWD/bundle/Cache/
echo $PLAYWRIGHT_BROWSERS_PATH
NODE_VERSION=$(node --version)
NODE_URL="https://nodejs.org/dist/$NODE_VERSION/node-$NODE_VERSION-darwin-x64.tar.gz"
NODE_TAR_FILE="node-$NODE_VERSION-darwin-x64.tar.gz"
NODE_DIR="node-$NODE_VERSION-darwin-x64"

rm -rf ./bundle/
mkdir ./bundle/

# Build src
npm ci
npm run build
cp -r ./lib/ ./bundle/lib/
cp -r bin/ bundle/bin/
cp package.json bundle/package.json
cp package-lock.json bundle/package-lock.json
cp $(which node) bundle/
curl -o $NODE_TAR_FILE $NODE_URL
tar xf $NODE_TAR_FILE
mv $NODE_DIR bundle/node_dir

pushd bundle/

npm cache clean --force
npm ci --omit=dev


npx playwright install
npx playwright install-deps
npx playwright --version

popd
11 changes: 8 additions & 3 deletions scripts/bundle.sh → scripts/bundle-win.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ set -e
echo "Using: $(which node)"
export PLAYWRIGHT_BROWSERS_PATH=$PWD/bundle/Cache/
echo $PLAYWRIGHT_BROWSERS_PATH
NODE_VERSION=$(node --version)
NODE_URL="https://nodejs.org/dist/$NODE_VERSION/node-$NODE_VERSION-win-x64.zip"
NODE_TAR_FILE="node-$NODE_VERSION-win-x64.zip"
NODE_DIR="node-$NODE_VERSION-win-x64"

rm -rf ./bundle/
mkdir ./bundle/
Expand All @@ -10,12 +14,13 @@ mkdir ./bundle/
npm ci
npm run build
cp -r ./lib/ ./bundle/lib/

cp -r bin/ bundle/bin/
cp package.json bundle/package.json
cp package-lock.json bundle/package-lock.json
cp "$(which node)" bundle/

cp $(which node) bundle/
curl -o $NODE_TAR_FILE $NODE_URL
unzip $NODE_TAR_FILE
mv $NODE_DIR bundle/node_dir

pushd bundle/

Expand Down
19 changes: 18 additions & 1 deletion src/playwright-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import {spawn} from 'node:child_process';
import * as path from 'node:path';
import * as fs from 'node:fs';
import * as os from 'node:os';

import _ from 'lodash';
import {getArgs, prepareNpmEnv, loadRunConfig, escapeXML, preExec} from 'sauce-testrunner-utils';
Expand Down Expand Up @@ -34,7 +35,7 @@
if (!xmlData) {
return;
}
let result = convert.xml2js(xmlData, {compact: true}) as any;

Check warning on line 38 in src/playwright-runner.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type
if (!result.testsuites || !result.testsuites.testsuite) {
return;
}
Expand All @@ -43,14 +44,14 @@
result.testsuites.testsuite = [result.testsuites.testsuite];
}

const testsuites: any[] = [];

Check warning on line 47 in src/playwright-runner.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type
let totalTests = 0;
let totalErrs = 0;
let totalFailures = 0;
let totalSkipped = 0;
let totalTime = 0;
for (let i = 0; i < result.testsuites.testsuite.length; i++) {
const testsuite = result.testsuites.testsuite[i] as any;

Check warning on line 54 in src/playwright-runner.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type
if (testsuite._attributes) {
totalTests += +testsuite._attributes.tests || 0;
totalFailures += +testsuite._attributes.failures || 0;
Expand Down Expand Up @@ -168,6 +169,22 @@
console.log(`Sauce Playwright Runner ${packageInfo.version}`);
console.log(`Running Playwright ${packageInfo.dependencies?.playwright || ''}`);

// Modify nodeBin location to downloaded node binaries.
const nodeDir = path.resolve(path.dirname(nodeBin));
if (os.platform() === 'win32') {
nodeBin = path.join(nodeDir, 'node_dir', 'node.exe');
} else {
// The previous bundled nodeBin(/Users/chef/payload/bundle/bundle/node) should be removed on Mac platform.
// Otherwise, `npx` would be point to `/Users/chef/payload/bundle/lib/` according to the `node` path, which is wrong.
fs.unlink(nodeBin, (err) => {
if (err) throw err;
console.log('previous bundled nodeBin was deleted');
});
nodeBin = path.join(nodeDir, 'node_dir', 'bin', 'node');
}
const currentPATH = process.env.PATH || '';
process.env.PATH = `${currentPATH}${path.delimiter}${path.resolve(path.dirname(nodeBin))}`

let result: RunResult;
if (runCfg.Kind === 'playwright-cucumberjs') {
result = await runCucumber(nodeBin, runCfg);
Expand Down Expand Up @@ -276,7 +293,7 @@
const metrics: Metrics[] = [];

// Define node/npm path for execution
const npmBin = path.join(path.dirname(nodeBin), 'node_modules', 'npm', 'bin', 'npm-cli.js');
const npmBin = path.join(__dirname, '..', 'node_modules', 'npm', 'bin', 'npm-cli.js');
const nodeCtx = { nodePath: nodeBin, npmPath: npmBin };

// runCfg.path must be set for prepareNpmEnv to find node_modules. :(
Expand Down
Loading