Skip to content

Commit d4e601a

Browse files
committed
chore: add template oss
1 parent 73e6a0f commit d4e601a

15 files changed

+477
-4
lines changed

.eslintrc.js

Lines changed: 17 additions & 0 deletions
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+
'use strict'
4+
5+
const { readdirSync: readdir } = require('fs')
6+
7+
const localConfigs = readdir(__dirname)
8+
.filter((file) => file.startsWith('.eslintrc.local.'))
9+
.map((file) => `./${file}`)
10+
11+
module.exports = {
12+
root: true,
13+
extends: [
14+
'@npmcli',
15+
...localConfigs,
16+
],
17+
}

.github/CODEOWNERS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# This file is automatically added by @npmcli/template-oss. Do not edit.
2+
3+
* @npm/cli-team

.github/ISSUE_TEMPLATE/config.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# This file is automatically added by @npmcli/template-oss. Do not edit.
2+
3+
blank_issues_enabled: true

.github/dependabot.yml

Lines changed: 17 additions & 0 deletions
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: /
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

Lines changed: 32 additions & 0 deletions
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/audit.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# This file is automatically added by @npmcli/template-oss. Do not edit.
2+
3+
name: Audit
4+
5+
on:
6+
workflow_dispatch:
7+
schedule:
8+
# "At 08:00 UTC (01:00 PT) on Monday" https://crontab.guru/#0_8_*_*_1
9+
- cron: "0 8 * * 1"
10+
11+
jobs:
12+
audit:
13+
name: Audit Dependencies
14+
if: github.repository_owner == 'npm'
15+
runs-on: ubuntu-latest
16+
defaults:
17+
run:
18+
shell: bash
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v3
22+
- name: Setup Git User
23+
run: |
24+
git config --global user.email "[email protected]"
25+
git config --global user.name "npm CLI robot"
26+
- name: Setup Node
27+
uses: actions/setup-node@v3
28+
with:
29+
node-version: 18.x
30+
- name: Install npm@latest
31+
run: npm i --prefer-online --no-fund --no-audit -g npm@latest
32+
- name: npm Version
33+
run: npm -v
34+
- name: Install Dependencies
35+
run: npm i --ignore-scripts --no-audit --no-fund --package-lock
36+
- name: Run Production Audit
37+
run: npm audit --omit=dev
38+
- name: Run Full Audit
39+
run: npm audit --audit-level=none

.github/workflows/ci.yml

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# This file is automatically added by @npmcli/template-oss. Do not edit.
2+
3+
name: CI
4+
5+
on:
6+
workflow_dispatch:
7+
pull_request:
8+
push:
9+
branches:
10+
- main
11+
- latest
12+
schedule:
13+
# "At 09:00 UTC (02:00 PT) on Monday" https://crontab.guru/#0_9_*_*_1
14+
- cron: "0 9 * * 1"
15+
16+
jobs:
17+
lint:
18+
name: Lint
19+
if: github.repository_owner == 'npm'
20+
runs-on: ubuntu-latest
21+
defaults:
22+
run:
23+
shell: bash
24+
steps:
25+
- name: Checkout
26+
uses: actions/checkout@v3
27+
- name: Setup Git User
28+
run: |
29+
git config --global user.email "[email protected]"
30+
git config --global user.name "npm CLI robot"
31+
- name: Setup Node
32+
uses: actions/setup-node@v3
33+
with:
34+
node-version: 18.x
35+
- name: Install npm@latest
36+
run: npm i --prefer-online --no-fund --no-audit -g npm@latest
37+
- name: npm Version
38+
run: npm -v
39+
- name: Install Dependencies
40+
run: npm i --ignore-scripts --no-audit --no-fund
41+
- name: Lint
42+
run: npm run lint --ignore-scripts
43+
- name: Post Lint
44+
run: npm run postlint --ignore-scripts
45+
46+
test:
47+
name: Test - ${{ matrix.platform.name }} - ${{ matrix.node-version }}
48+
if: github.repository_owner == 'npm'
49+
strategy:
50+
fail-fast: false
51+
matrix:
52+
platform:
53+
- name: Linux
54+
os: ubuntu-latest
55+
shell: bash
56+
node-version:
57+
- 18.x
58+
runs-on: ${{ matrix.platform.os }}
59+
defaults:
60+
run:
61+
shell: ${{ matrix.platform.shell }}
62+
steps:
63+
- name: Checkout
64+
uses: actions/checkout@v3
65+
- name: Setup Git User
66+
run: |
67+
git config --global user.email "[email protected]"
68+
git config --global user.name "npm CLI robot"
69+
- name: Setup Node
70+
uses: actions/setup-node@v3
71+
with:
72+
node-version: ${{ matrix.node-version }}
73+
- name: Update Windows npm
74+
# node 12 and 14 ship with npm@6, which is known to fail when updating itself in windows
75+
if: matrix.platform.os == 'windows-latest' && (startsWith(matrix.node-version, '12.') || startsWith(matrix.node-version, '14.'))
76+
run: |
77+
curl -sO https://registry.npmjs.org/npm/-/npm-7.5.4.tgz
78+
tar xf npm-7.5.4.tgz
79+
cd package
80+
node lib/npm.js install --no-fund --no-audit -g ..\npm-7.5.4.tgz
81+
cd ..
82+
rmdir /s /q package
83+
- name: Install npm@7
84+
if: startsWith(matrix.node-version, '10.')
85+
run: npm i --prefer-online --no-fund --no-audit -g npm@7
86+
- name: Install npm@latest
87+
if: ${{ !startsWith(matrix.node-version, '10.') }}
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: Add Problem Matcher
94+
run: echo "::add-matcher::.github/matchers/tap.json"
95+
- name: Test
96+
run: npm test --ignore-scripts

.github/workflows/codeql-analysis.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# This file is automatically added by @npmcli/template-oss. Do not edit.
2+
3+
name: CodeQL
4+
5+
on:
6+
push:
7+
branches:
8+
- main
9+
- latest
10+
pull_request:
11+
branches:
12+
- main
13+
- latest
14+
schedule:
15+
# "At 10:00 UTC (03:00 PT) on Monday" https://crontab.guru/#0_10_*_*_1
16+
- cron: "0 10 * * 1"
17+
18+
jobs:
19+
analyze:
20+
name: Analyze
21+
runs-on: ubuntu-latest
22+
permissions:
23+
actions: read
24+
contents: read
25+
security-events: write
26+
steps:
27+
- name: Checkout
28+
uses: actions/checkout@v3
29+
- name: Setup Git User
30+
run: |
31+
git config --global user.email "[email protected]"
32+
git config --global user.name "npm CLI robot"
33+
- name: Initialize CodeQL
34+
uses: github/codeql-action/init@v2
35+
with:
36+
languages: javascript
37+
- name: Perform CodeQL Analysis
38+
uses: github/codeql-action/analyze@v2

.github/workflows/post-dependabot.yml

Lines changed: 121 additions & 0 deletions
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.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.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)