Skip to content

Commit dede971

Browse files
authored
feat: build cli content from registry (npm#239)
This change will allow the CLI content to be built from the docs published in the registry tarball. This is necessary now that the CLI repo will no longer contain the generated docs in source countro. There still exists a fallback for fetching from GitHub for legacy versions of the CLI that have more recent content in a branc that was never published to the registry. Because of this change, the CLI is no longer checked in as submodules. In order to avoid fetching more often than necessary, a `resolved` field is stored in the `releases.json` manifest. This commit also introduced `@npmcli/template-oss` as a dev dep to the CLI workspace to standardize the development workflow.
1 parent 995d8c1 commit dede971

35 files changed

+27909
-23375
lines changed

.github/CODEOWNERS

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
# Assign cli team to cli related PRs
55
# In general these should be closed and pointed towards the CLI
66
# repo... we should automate this
7-
/cli @npm/cli
8-
/content/cli @npm/cli
7+
/cli @npm/cli-team
8+
/content/cli @npm/cli-team

.github/dependabot.yml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# This file is automatically added by @npmcli/template-oss. Do not edit.
2+
3+
version: 2
4+
5+
updates:
6+
- package-ecosystem: npm
7+
directory: cli/
8+
schedule:
9+
interval: daily
10+
allow:
11+
- dependency-type: direct
12+
versioning-strategy: increase-if-necessary
13+
commit-message:
14+
prefix: deps
15+
prefix-development: chore
16+
labels:
17+
- "Dependencies"

.github/matchers/tap.json

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"//@npmcli/template-oss": "This file is automatically added by @npmcli/template-oss. Do not edit.",
3+
"problemMatcher": [
4+
{
5+
"owner": "tap",
6+
"pattern": [
7+
{
8+
"regexp": "^\\s*not ok \\d+ - (.*)",
9+
"message": 1
10+
},
11+
{
12+
"regexp": "^\\s*---"
13+
},
14+
{
15+
"regexp": "^\\s*at:"
16+
},
17+
{
18+
"regexp": "^\\s*line:\\s*(\\d+)",
19+
"line": 1
20+
},
21+
{
22+
"regexp": "^\\s*column:\\s*(\\d+)",
23+
"column": 1
24+
},
25+
{
26+
"regexp": "^\\s*file:\\s*(.*)",
27+
"file": 1
28+
}
29+
]
30+
}
31+
]
32+
}

.github/workflows/ci-cli.yml

+153
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
# This file is automatically added by @npmcli/template-oss. Do not edit.
2+
3+
name: CI - cli
4+
5+
on:
6+
workflow_dispatch:
7+
pull_request:
8+
paths:
9+
- cli/**
10+
push:
11+
branches:
12+
- main
13+
- latest
14+
paths:
15+
- cli/**
16+
schedule:
17+
# "At 09:00 UTC (02:00 PT) on Monday" https://crontab.guru/#0_9_*_*_1
18+
- cron: "0 9 * * 1"
19+
20+
jobs:
21+
engines:
22+
name: Engines - ${{ matrix.platform.name }} - ${{ matrix.node-version }}
23+
if: github.repository_owner == 'npm'
24+
strategy:
25+
fail-fast: false
26+
matrix:
27+
platform:
28+
- name: Linux
29+
os: ubuntu-latest
30+
shell: bash
31+
node-version:
32+
- 18.0.0
33+
runs-on: ${{ matrix.platform.os }}
34+
defaults:
35+
run:
36+
shell: ${{ matrix.platform.shell }}
37+
steps:
38+
- name: Checkout
39+
uses: actions/checkout@v3
40+
- name: Setup Git User
41+
run: |
42+
git config --global user.email "[email protected]"
43+
git config --global user.name "npm CLI robot"
44+
- name: Setup Node
45+
uses: actions/setup-node@v3
46+
with:
47+
node-version: ${{ matrix.node-version }}
48+
- name: Update Windows npm
49+
# node 12 and 14 ship with npm@6, which is known to fail when updating itself in windows
50+
if: matrix.platform.os == 'windows-latest' && (startsWith(matrix.node-version, '12.') || startsWith(matrix.node-version, '14.'))
51+
run: |
52+
curl -sO https://registry.npmjs.org/npm/-/npm-7.5.4.tgz
53+
tar xf npm-7.5.4.tgz
54+
cd package
55+
node lib/npm.js install --no-fund --no-audit -g ..\npm-7.5.4.tgz
56+
cd ..
57+
rmdir /s /q package
58+
- name: Install npm@7
59+
if: startsWith(matrix.node-version, '10.')
60+
run: npm i --prefer-online --no-fund --no-audit -g npm@7
61+
- name: Install npm@latest
62+
if: ${{ !startsWith(matrix.node-version, '10.') }}
63+
run: npm i --prefer-online --no-fund --no-audit -g npm@latest
64+
- name: npm Version
65+
run: npm -v
66+
- name: Install Dependencies
67+
run: npm i --ignore-scripts --no-audit --no-fund --engines-strict
68+
69+
lint:
70+
name: Lint
71+
if: github.repository_owner == 'npm'
72+
runs-on: ubuntu-latest
73+
defaults:
74+
run:
75+
shell: bash
76+
steps:
77+
- name: Checkout
78+
uses: actions/checkout@v3
79+
- name: Setup Git User
80+
run: |
81+
git config --global user.email "[email protected]"
82+
git config --global user.name "npm CLI robot"
83+
- name: Setup Node
84+
uses: actions/setup-node@v3
85+
with:
86+
node-version: 18.x
87+
- name: Install npm@latest
88+
run: npm i --prefer-online --no-fund --no-audit -g npm@latest
89+
- name: npm Version
90+
run: npm -v
91+
- name: Install Dependencies
92+
run: npm i --ignore-scripts --no-audit --no-fund
93+
- name: Lint
94+
run: npm run lint --ignore-scripts -w cli
95+
- name: Post Lint
96+
run: npm run postlint --ignore-scripts -w cli
97+
98+
test:
99+
name: Test - ${{ matrix.platform.name }} - ${{ matrix.node-version }}
100+
if: github.repository_owner == 'npm'
101+
strategy:
102+
fail-fast: false
103+
matrix:
104+
platform:
105+
- name: Linux
106+
os: ubuntu-latest
107+
shell: bash
108+
- name: Windows
109+
os: windows-latest
110+
shell: cmd
111+
node-version:
112+
- 18.x
113+
runs-on: ${{ matrix.platform.os }}
114+
defaults:
115+
run:
116+
shell: ${{ matrix.platform.shell }}
117+
steps:
118+
- name: Checkout
119+
uses: actions/checkout@v3
120+
- name: Setup Git User
121+
run: |
122+
git config --global user.email "[email protected]"
123+
git config --global user.name "npm CLI robot"
124+
- name: Setup Node
125+
uses: actions/setup-node@v3
126+
with:
127+
node-version: ${{ matrix.node-version }}
128+
- name: Update Windows npm
129+
# node 12 and 14 ship with npm@6, which is known to fail when updating itself in windows
130+
if: matrix.platform.os == 'windows-latest' && (startsWith(matrix.node-version, '12.') || startsWith(matrix.node-version, '14.'))
131+
run: |
132+
curl -sO https://registry.npmjs.org/npm/-/npm-7.5.4.tgz
133+
tar xf npm-7.5.4.tgz
134+
cd package
135+
node lib/npm.js install --no-fund --no-audit -g ..\npm-7.5.4.tgz
136+
cd ..
137+
rmdir /s /q package
138+
- name: Install npm@7
139+
if: startsWith(matrix.node-version, '10.')
140+
run: npm i --prefer-online --no-fund --no-audit -g npm@7
141+
- name: Install npm@latest
142+
if: ${{ !startsWith(matrix.node-version, '10.') }}
143+
run: npm i --prefer-online --no-fund --no-audit -g npm@latest
144+
- name: npm Version
145+
run: npm -v
146+
- name: Install Dependencies
147+
run: npm i --ignore-scripts --no-audit --no-fund
148+
- name: Add Problem Matcher
149+
run: echo "::add-matcher::.github/matchers/tap.json"
150+
- name: Test
151+
run: npm test --ignore-scripts -w cli
152+
env:
153+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+4-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
name: REUSE Compliance Check
22

3-
on: [pull_request]
3+
on: pull_request
44

55
jobs:
66
test:
77
runs-on: ubuntu-latest
88
steps:
9-
- uses: actions/checkout@v2
10-
- name: REUSE Compliance Check
11-
uses: fsfe/reuse-action@v1
9+
- uses: actions/checkout@v2
10+
- name: REUSE Compliance Check
11+
uses: fsfe/reuse-action@v1

.github/workflows/post-dependabot.yml

+121
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# This file is automatically added by @npmcli/template-oss. Do not edit.
2+
3+
name: Post Dependabot
4+
5+
on: pull_request
6+
7+
permissions:
8+
contents: write
9+
10+
jobs:
11+
template-oss:
12+
name: template-oss
13+
if: github.repository_owner == 'npm' && github.actor == 'dependabot[bot]'
14+
runs-on: ubuntu-latest
15+
defaults:
16+
run:
17+
shell: bash
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v3
21+
with:
22+
ref: ${{ github.event.pull_request.head.ref }}
23+
- name: Setup Git User
24+
run: |
25+
git config --global user.email "[email protected]"
26+
git config --global user.name "npm CLI robot"
27+
- name: Setup Node
28+
uses: actions/setup-node@v3
29+
with:
30+
node-version: 18.x
31+
- name: Install npm@latest
32+
run: npm i --prefer-online --no-fund --no-audit -g npm@latest
33+
- name: npm Version
34+
run: npm -v
35+
- name: Install Dependencies
36+
run: npm i --ignore-scripts --no-audit --no-fund
37+
- name: Fetch Dependabot Metadata
38+
id: metadata
39+
uses: dependabot/fetch-metadata@v1
40+
with:
41+
github-token: ${{ secrets.GITHUB_TOKEN }}
42+
43+
# Dependabot can update multiple directories so we output which directory
44+
# it is acting on so we can run the command for the correct root or workspace
45+
- name: Get Dependabot Directory
46+
if: contains(steps.metadata.outputs.dependency-names, '@npmcli/template-oss')
47+
id: flags
48+
run: |
49+
dependabot_dir="${{ steps.metadata.outputs.directory }}"
50+
if [[ "$dependabot_dir" == "/" ]]; then
51+
echo "::set-output name=workspace::-iwr"
52+
else
53+
# strip leading slash from directory so it works as a
54+
# a path to the workspace flag
55+
echo "::set-output name=workspace::-w ${dependabot_dir#/}"
56+
fi
57+
58+
- name: Apply Changes
59+
if: steps.flags.outputs.workspace
60+
id: apply
61+
run: |
62+
npm run template-oss-apply ${{ steps.flags.outputs.workspace }}
63+
if [[ `git status --porcelain` ]]; then
64+
echo "::set-output name=changes::true"
65+
fi
66+
# This only sets the conventional commit prefix. This workflow can't reliably determine
67+
# what the breaking change is though. If a BREAKING CHANGE message is required then
68+
# this PR check will fail and the commit will be amended with stafftools
69+
if [[ "${{ steps.dependabot-metadata.outputs.update-type }}" == "version-update:semver-major" ]]; then
70+
prefix='feat!'
71+
else
72+
prefix='chore!'
73+
fi
74+
echo "::set-output name=message::$prefix: postinstall for dependabot template-oss PR"
75+
76+
# This step will fail if template-oss has made any workflow updates. It is impossible
77+
# for a workflow to update other workflows. In the case it does fail, we continue
78+
# and then try to apply only a portion of the changes in the next step
79+
- name: Push All Changes
80+
if: steps.apply.outputs.changes
81+
id: push
82+
continue-on-error: true
83+
env:
84+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
85+
run: |
86+
git commit -am "${{ steps.apply.outputs.message }}"
87+
git push
88+
89+
# If the previous step failed, then reset the commit and remove any workflow changes
90+
# and attempt to commit and push again. This is helpful because we will have a commit
91+
# with the correct prefix that we can then --amend with @npmcli/stafftools later.
92+
- name: Push All Changes Except Workflows
93+
if: steps.apply.outputs.changes && steps.push-all.outcome == 'failure'
94+
env:
95+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
96+
run: |
97+
git reset HEAD~
98+
git checkout HEAD -- .github/workflows/
99+
git clean -fd .github/workflows/
100+
git commit -am "${{ steps.apply.outputs.message }}"
101+
git push
102+
103+
# Check if all the necessary template-oss changes were applied. Since we continued
104+
# on errors in one of the previous steps, this check will fail if our follow up
105+
# only applied a portion of the changes and we need to followup manually.
106+
#
107+
# Note that this used to run `lint` and `postlint` but that will fail this action
108+
# if we've also shipped any linting changes separate from template-oss. We do
109+
# linting in another action, so we want to fail this one only if there are
110+
# template-oss changes that could not be applied.
111+
- name: Check Changes
112+
if: steps.apply.outputs.changes
113+
run: |
114+
npm exec --offline ${{ steps.flags.outputs.workspace }} -- template-oss-check
115+
116+
- name: Fail on Breaking Change
117+
if: steps.apply.outputs.changes && startsWith(steps.apply.outputs.message, 'feat!')
118+
run: |
119+
echo "This PR has a breaking change. Run 'npx -p @npmcli/stafftools gh template-oss-fix'"
120+
echo "for more information on how to fix this with a BREAKING CHANGE footer."
121+
exit 1

0 commit comments

Comments
 (0)