Skip to content

Commit 6d21bba

Browse files
committed
feat!: postinstall for dependabot template-oss PR
BREAKING CHANGE: `validate-npm-package-name` is now compatible with the following semver range for node: `^14.17.0 || ^16.13.0 || >=18.0.0`
1 parent da17ef2 commit 6d21bba

File tree

9 files changed

+196
-136
lines changed

9 files changed

+196
-136
lines changed

.github/dependabot.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version: 2
44

55
updates:
66
- package-ecosystem: npm
7-
directory: "/"
7+
directory: /
88
schedule:
99
interval: daily
1010
allow:

.github/workflows/audit.yml

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,33 @@ name: Audit
55
on:
66
workflow_dispatch:
77
schedule:
8-
# "At 01:00 on Monday" https://crontab.guru/#0_1_*_*_1
9-
- cron: "0 1 * * 1"
8+
# "At 08:00 UTC (01:00 PT) on Monday" https://crontab.guru/#0_8_*_*_1
9+
- cron: "0 8 * * 1"
1010

1111
jobs:
1212
audit:
13+
name: Audit Dependencies
14+
if: github.repository_owner == 'npm'
1315
runs-on: ubuntu-latest
16+
defaults:
17+
run:
18+
shell: bash
1419
steps:
15-
- uses: actions/checkout@v3
16-
- name: Setup git user
20+
- name: Checkout
21+
uses: actions/checkout@v3
22+
- name: Setup Git User
1723
run: |
1824
git config --global user.email "[email protected]"
1925
git config --global user.name "npm CLI robot"
20-
- uses: actions/setup-node@v3
26+
- name: Setup Node
27+
uses: actions/setup-node@v3
2128
with:
22-
node-version: 16.x
23-
- name: Update npm to latest
29+
node-version: 18.x
30+
- name: Install npm@latest
2431
run: npm i --prefer-online --no-fund --no-audit -g npm@latest
25-
- run: npm -v
26-
- run: npm i --ignore-scripts --no-audit --no-fund --package-lock
27-
- run: npm audit
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 Audit
37+
run: npm audit

.github/workflows/ci.yml

Lines changed: 53 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,66 +5,83 @@ name: CI
55
on:
66
workflow_dispatch:
77
pull_request:
8-
branches:
9-
- '*'
108
push:
119
branches:
1210
- main
1311
- latest
1412
schedule:
15-
# "At 02:00 on Monday" https://crontab.guru/#0_2_*_*_1
16-
- cron: "0 2 * * 1"
13+
# "At 09:00 UTC (02:00 PT) on Monday" https://crontab.guru/#0_9_*_*_1
14+
- cron: "0 9 * * 1"
1715

1816
jobs:
1917
lint:
18+
name: Lint
19+
if: github.repository_owner == 'npm'
2020
runs-on: ubuntu-latest
21+
defaults:
22+
run:
23+
shell: bash
2124
steps:
22-
- uses: actions/checkout@v3
23-
- name: Setup git user
25+
- name: Checkout
26+
uses: actions/checkout@v3
27+
- name: Setup Git User
2428
run: |
2529
git config --global user.email "[email protected]"
2630
git config --global user.name "npm CLI robot"
27-
- uses: actions/setup-node@v3
31+
- name: Setup Node
32+
uses: actions/setup-node@v3
2833
with:
29-
node-version: 16.x
30-
- name: Update npm to latest
34+
node-version: 18.x
35+
- name: Install npm@latest
3136
run: npm i --prefer-online --no-fund --no-audit -g npm@latest
32-
- run: npm -v
33-
- run: npm i --ignore-scripts --no-audit --no-fund
34-
- run: npm run lint
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
3545

3646
test:
47+
name: Test - ${{ matrix.platform.name }} - ${{ matrix.node-version }}
48+
if: github.repository_owner == 'npm'
3749
strategy:
3850
fail-fast: false
3951
matrix:
40-
node-version:
41-
- 12.13.0
42-
- 12.x
43-
- 14.15.0
44-
- 14.x
45-
- 16.0.0
46-
- 16.x
4752
platform:
48-
- os: ubuntu-latest
53+
- name: Linux
54+
os: ubuntu-latest
4955
shell: bash
50-
- os: macos-latest
56+
- name: macOS
57+
os: macos-latest
5158
shell: bash
52-
- os: windows-latest
59+
- name: Windows
60+
os: windows-latest
5361
shell: cmd
62+
node-version:
63+
- 14.17.0
64+
- 14.x
65+
- 16.13.0
66+
- 16.x
67+
- 18.0.0
68+
- 18.x
5469
runs-on: ${{ matrix.platform.os }}
5570
defaults:
5671
run:
5772
shell: ${{ matrix.platform.shell }}
5873
steps:
59-
- uses: actions/checkout@v3
60-
- name: Setup git user
74+
- name: Checkout
75+
uses: actions/checkout@v3
76+
- name: Setup Git User
6177
run: |
6278
git config --global user.email "[email protected]"
6379
git config --global user.name "npm CLI robot"
64-
- uses: actions/setup-node@v3
80+
- name: Setup Node
81+
uses: actions/setup-node@v3
6582
with:
6683
node-version: ${{ matrix.node-version }}
67-
- name: Update to workable npm (windows)
84+
- name: Update Windows npm
6885
# node 12 and 14 ship with npm@6, which is known to fail when updating itself in windows
6986
if: matrix.platform.os == 'windows-latest' && (startsWith(matrix.node-version, '12.') || startsWith(matrix.node-version, '14.'))
7087
run: |
@@ -74,13 +91,17 @@ jobs:
7491
node lib/npm.js install --no-fund --no-audit -g ..\npm-7.5.4.tgz
7592
cd ..
7693
rmdir /s /q package
77-
- name: Update npm to 7
78-
# If we do test on npm 10 it needs npm7
94+
- name: Install npm@7
7995
if: startsWith(matrix.node-version, '10.')
8096
run: npm i --prefer-online --no-fund --no-audit -g npm@7
81-
- name: Update npm to latest
97+
- name: Install npm@latest
8298
if: ${{ !startsWith(matrix.node-version, '10.') }}
8399
run: npm i --prefer-online --no-fund --no-audit -g npm@latest
84-
- run: npm -v
85-
- run: npm i --ignore-scripts --no-audit --no-fund
86-
- run: npm test --ignore-scripts
100+
- name: npm Version
101+
run: npm -v
102+
- name: Install Dependencies
103+
run: npm i --ignore-scripts --no-audit --no-fund
104+
- name: Add Problem Matcher
105+
run: echo "::add-matcher::.github/matchers/tap.json"
106+
- name: Test
107+
run: npm test --ignore-scripts -iwr
Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
# This file is automatically added by @npmcli/template-oss. Do not edit.
22

3-
name: "CodeQL"
3+
name: CodeQL
44

55
on:
66
push:
77
branches:
88
- main
99
- latest
1010
pull_request:
11-
# The branches below must be a subset of the branches above
1211
branches:
1312
- main
1413
- latest
1514
schedule:
16-
# "At 03:00 on Monday" https://crontab.guru/#0_3_*_*_1
17-
- cron: "0 3 * * 1"
15+
# "At 10:00 UTC (03:00 PT) on Monday" https://crontab.guru/#0_10_*_*_1
16+
- cron: "0 10 * * 1"
1817

1918
jobs:
2019
analyze:
@@ -24,21 +23,16 @@ jobs:
2423
actions: read
2524
contents: read
2625
security-events: write
27-
28-
strategy:
29-
fail-fast: false
30-
matrix:
31-
language: [ javascript ]
32-
3326
steps:
34-
- uses: actions/checkout@v3
35-
- name: Setup git user
27+
- name: Checkout
28+
uses: actions/checkout@v3
29+
- name: Setup Git User
3630
run: |
3731
git config --global user.email "[email protected]"
3832
git config --global user.name "npm CLI robot"
3933
- name: Initialize CodeQL
40-
uses: github/codeql-action/init@v1
34+
uses: github/codeql-action/init@v2
4135
with:
42-
languages: ${{ matrix.language }}
36+
languages: javascript
4337
- name: Perform CodeQL Analysis
44-
uses: github/codeql-action/analyze@v1
38+
uses: github/codeql-action/analyze@v2
Lines changed: 67 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,91 @@
11
# This file is automatically added by @npmcli/template-oss. Do not edit.
22

3-
name: Post Dependabot Actions
3+
name: Post Dependabot
44

55
on: pull_request
66

7-
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#permissions
87
permissions:
98
contents: write
109

1110
jobs:
12-
template-oss-apply:
11+
template-oss:
12+
name: template-oss
13+
if: github.repository_owner == 'npm' && github.actor == 'dependabot[bot]'
1314
runs-on: ubuntu-latest
14-
if: github.actor == 'dependabot[bot]'
15+
defaults:
16+
run:
17+
shell: bash
1518
steps:
16-
- uses: actions/checkout@v3
17-
- name: Setup git user
19+
- name: Checkout
20+
uses: actions/checkout@v3
21+
with:
22+
ref: ${{ github.event.pull_request.head_ref }}
23+
- name: Setup Git User
1824
run: |
1925
git config --global user.email "[email protected]"
2026
git config --global user.name "npm CLI robot"
21-
- uses: actions/setup-node@v3
27+
- name: Setup Node
28+
uses: actions/setup-node@v3
2229
with:
23-
node-version: 16.x
24-
- name: Update npm to latest
30+
node-version: 18.x
31+
- name: Install npm@latest
2532
run: npm i --prefer-online --no-fund --no-audit -g npm@latest
26-
- run: npm -v
27-
- name: Dependabot metadata
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
2838
id: metadata
29-
uses: dependabot/fetch-metadata@v1.1.1
39+
uses: dependabot/fetch-metadata@v1
3040
with:
31-
github-token: "${{ secrets.GITHUB_TOKEN }}"
32-
- name: npm install and commit
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
3346
if: contains(steps.metadata.outputs.dependency-names, '@npmcli/template-oss')
47+
id: flags
48+
run: |
49+
if [[ "${{ steps.metadata.outputs.directory }}" == "/" ]]; then
50+
echo "::set-output name=workspace::-iwr"
51+
else
52+
echo "::set-output name=workspace::-w ${{ steps.metadata.outputs.directory }}"
53+
fi
54+
55+
- name: Apply Changes
56+
if: steps.flags.outputs.workspace
57+
id: apply
58+
run: |
59+
npm run template-oss-apply ${{ steps.flags.outputs.workspace }}
60+
if [[ `git status --porcelain` ]]; then
61+
echo "::set-output name=changes::true"
62+
fi
63+
64+
# This step will fail if template-oss has made any workflow updates. It is impossible
65+
# for a workflow to update other workflows. In the case it does fail, we continue
66+
# and then try to apply only a portion of the changes in the next step
67+
- name: Push All Changes
68+
if: steps.apply.outputs.changes
69+
id: push
70+
continue-on-error: true
71+
env:
72+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
73+
run: |
74+
git commit -am "chore: postinstall for dependabot template-oss PR"
75+
git push
76+
77+
- name: Push All Changes Except Workflows
78+
if: steps.push.outcome == 'failure'
3479
env:
3580
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3681
run: |
37-
gh pr checkout ${{ github.event.pull_request.number }}
38-
npm install --ignore-scripts --no-audit --no-fund
39-
npm run template-oss-apply
40-
git add .
82+
git reset HEAD~
83+
git checkout HEAD -- .github/workflows/
84+
git clean -fd .github/workflows/
4185
git commit -am "chore: postinstall for dependabot template-oss PR"
4286
git push
43-
npm run lint
87+
88+
- name: Check Changes
89+
if: steps.apply.outputs.changes
90+
run: |
91+
npm exec --offline ${{ steps.flags.outputs.workspace }} -- template-oss-check

0 commit comments

Comments
 (0)