This repository has been archived by the owner on Jul 1, 2024. It is now read-only.
"pull_request npm/cli#6895" #2429
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This file is automatically added by @npmcli/template-oss. Do not edit. | |
name: Benchmark CLI | |
on: repository_dispatch | |
jobs: | |
benchmark: | |
name: Benchmark CLI | |
if: github.repository_owner == 'npm' && startsWith(github.event.action, 'pull_request') || startsWith(github.event.action, 'issue_comment') | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
shell: bash | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Setup Git User | |
run: | | |
git config --global user.email "npm-cli+bot@github.com" | |
git config --global user.name "npm CLI robot" | |
- name: Setup Node | |
uses: actions/setup-node@v3 | |
id: node | |
with: | |
node-version: 20.x | |
check-latest: contains('20.x', '.x') | |
cache: npm | |
# node 10/12/14 ship with npm@6, which is known to fail when updating itself in windows | |
- name: Update Windows npm | |
if: | | |
matrix.platform.os == 'windows-latest' && ( | |
startsWith(steps.node.outputs.node-version, 'v10.') || startsWith(steps.node.outputs.node-version, 'v12.') || startsWith(steps.node.outputs.node-version, 'v14.') | |
) | |
run: | | |
curl -sO https://registry.npmjs.org/npm/-/npm-7.5.4.tgz | |
tar xf npm-7.5.4.tgz | |
cd package | |
node lib/npm.js install --no-fund --no-audit -g ..\npm-7.5.4.tgz | |
cd .. | |
rmdir /s /q package | |
# Start on Node 10 because we dont test on anything lower | |
- name: Install npm@7 on Node 10 | |
shell: bash | |
if: startsWith(steps.node.outputs.node-version, 'v10.') | |
id: npm-7 | |
run: | | |
npm i --prefer-online --no-fund --no-audit -g npm@7 | |
echo "updated=true" >> "$GITHUB_OUTPUT" | |
- name: Install npm@8 on Node 12 | |
shell: bash | |
if: startsWith(steps.node.outputs.node-version, 'v12.') | |
id: npm-8 | |
run: | | |
npm i --prefer-online --no-fund --no-audit -g npm@8 | |
echo "updated=true" >> "$GITHUB_OUTPUT" | |
- name: Install npm@9 on Node 14/16/18.0 | |
shell: bash | |
if: startsWith(steps.node.outputs.node-version, 'v14.') || startsWith(steps.node.outputs.node-version, 'v16.') || startsWith(steps.node.outputs.node-version, 'v18.0.') | |
id: npm-9 | |
run: | | |
npm i --prefer-online --no-fund --no-audit -g npm@9 | |
echo "updated=true" >> "$GITHUB_OUTPUT" | |
- name: Install npm@latest on Node | |
if: ${{ !(steps.npm-7.outputs.updated || steps.npm-8.outputs.updated || steps.npm-9.outputs.updated) }} | |
run: npm i --prefer-online --no-fund --no-audit -g npm@latest | |
- name: npm Version | |
run: npm -v | |
- name: Install Dependencies | |
run: npm i --ignore-scripts --no-audit --no-fund | |
- name: Install Hyperfine | |
run: | | |
wget https://github.com/sharkdp/hyperfine/releases/download/v1.13.0/hyperfine_1.13.0_amd64.deb | |
sudo dpkg -i hyperfine_1.13.0_amd64.deb | |
- name: Run Benchmark (Pull-Request) | |
env: | |
PR_ID: ${{ github.event.client_payload.pr_id }} | |
TARGET_SPEC: ${{ github.event.client_payload.target_spec || 'latest' }} | |
run: | | |
./bin/benchmark.js \ | |
-m npm@${TARGET_SPEC} npm@npm/cli#pull/${PR_ID}/head \ | |
-f app-large app-medium \ | |
-r | |
- name: Upload Results | |
uses: actions/upload-artifact@v3 | |
with: | |
name: results | |
path: results/temp/ | |
- name: Post Comment | |
uses: actions/github-script@v6 | |
env: | |
PR_ID: ${{ github.event.client_payload.pr_id }} | |
REPO: ${{ github.event.client_payload.repo }} | |
OWNER: ${{ github.event.client_payload.owner }} | |
with: | |
github-token: ${{ secrets.CLI_ISSUE_COMMENT_TOKEN }} | |
script: | | |
const fs = require('fs') | |
const path = require('path') | |
const { PR_ID, REPO, OWNER } = process.env | |
const COMMENT = fs.readFileSync(path.join('results/temp', 'report.md')) | |
const updateComment = await github.paginate(github.rest.issues.listComments, { | |
owner: OWNER, | |
repo: REPO, | |
issue_number: PR_ID, | |
}).then(cs => cs.find((c) => c.user.login === 'npm-cli-bot')) | |
if (updateComment) { | |
await github.rest.issues.updateComment({ | |
owner: OWNER, | |
repo: REPO, | |
comment_id: updateComment.id, | |
body: COMMENT, | |
}) | |
} else { | |
await github.issues.createComment({ | |
owner: OWNER, | |
repo: REPO, | |
issue_number: PR_ID, | |
body: COMMENT, | |
}) | |
} |