Skip to content

Commit 4b99699

Browse files
committed
chore: postinstall for dependabot template-oss PR
1 parent 941abbf commit 4b99699

File tree

3 files changed

+87
-7
lines changed

3 files changed

+87
-7
lines changed

Diff for: .github/workflows/ci.yml

+50
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,56 @@ on:
1414
- cron: "0 9 * * 1"
1515

1616
jobs:
17+
engines:
18+
name: Engines - ${{ matrix.platform.name }} - ${{ matrix.node-version }}
19+
if: github.repository_owner == 'npm'
20+
strategy:
21+
fail-fast: false
22+
matrix:
23+
platform:
24+
- name: Linux
25+
os: ubuntu-latest
26+
shell: bash
27+
node-version:
28+
- 14.17.0
29+
- 16.13.0
30+
- 18.0.0
31+
runs-on: ${{ matrix.platform.os }}
32+
defaults:
33+
run:
34+
shell: ${{ matrix.platform.shell }}
35+
steps:
36+
- name: Checkout
37+
uses: actions/checkout@v3
38+
- name: Setup Git User
39+
run: |
40+
git config --global user.email "[email protected]"
41+
git config --global user.name "npm CLI robot"
42+
- name: Setup Node
43+
uses: actions/setup-node@v3
44+
with:
45+
node-version: ${{ matrix.node-version }}
46+
- name: Update Windows npm
47+
# node 12 and 14 ship with npm@6, which is known to fail when updating itself in windows
48+
if: matrix.platform.os == 'windows-latest' && (startsWith(matrix.node-version, '12.') || startsWith(matrix.node-version, '14.'))
49+
run: |
50+
curl -sO https://registry.npmjs.org/npm/-/npm-7.5.4.tgz
51+
tar xf npm-7.5.4.tgz
52+
cd package
53+
node lib/npm.js install --no-fund --no-audit -g ..\npm-7.5.4.tgz
54+
cd ..
55+
rmdir /s /q package
56+
- name: Install npm@7
57+
if: startsWith(matrix.node-version, '10.')
58+
run: npm i --prefer-online --no-fund --no-audit -g npm@7
59+
- name: Install npm@latest
60+
if: ${{ !startsWith(matrix.node-version, '10.') }}
61+
run: npm i --prefer-online --no-fund --no-audit -g npm@latest
62+
- name: npm Version
63+
run: npm -v
64+
- name: Install Dependencies
65+
run: npm i --ignore-scripts --no-audit --no-fund --engines-strict
66+
1767
lint:
1868
name: Lint
1969
if: github.repository_owner == 'npm'

Diff for: .github/workflows/post-dependabot.yml

+36-6
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
- name: Checkout
2020
uses: actions/checkout@v3
2121
with:
22-
ref: ${{ github.event.pull_request.head_ref }}
22+
ref: ${{ github.ref_name }}
2323
- name: Setup Git User
2424
run: |
2525
git config --global user.email "[email protected]"
@@ -46,10 +46,13 @@ jobs:
4646
if: contains(steps.metadata.outputs.dependency-names, '@npmcli/template-oss')
4747
id: flags
4848
run: |
49-
if [[ "${{ steps.metadata.outputs.directory }}" == "/" ]]; then
49+
dependabot_dir="${{ steps.metadata.outputs.directory }}"
50+
if [[ "$dependabot_dir" == "/" ]]; then
5051
echo "::set-output name=workspace::-iwr"
5152
else
52-
echo "::set-output name=workspace::-w ${{ steps.metadata.outputs.directory }}"
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#/}"
5356
fi
5457
5558
- name: Apply Changes
@@ -60,6 +63,15 @@ jobs:
6063
if [[ `git status --porcelain` ]]; then
6164
echo "::set-output name=changes::true"
6265
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"
6375
6476
# This step will fail if template-oss has made any workflow updates. It is impossible
6577
# for a workflow to update other workflows. In the case it does fail, we continue
@@ -71,21 +83,39 @@ jobs:
7183
env:
7284
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7385
run: |
74-
git commit -am "chore: postinstall for dependabot template-oss PR"
86+
git commit -am "${{ steps.apply.outputs.message }}"
7587
git push
7688
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.
7792
- name: Push All Changes Except Workflows
78-
if: steps.push.outcome == 'failure'
93+
if: steps.apply.outputs.changes && steps.push-all.outcome == 'failure'
7994
env:
8095
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8196
run: |
8297
git reset HEAD~
8398
git checkout HEAD -- .github/workflows/
8499
git clean -fd .github/workflows/
85-
git commit -am "chore: postinstall for dependabot template-oss PR"
100+
git commit -am "${{ steps.apply.outputs.message }}"
86101
git push
87102
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.
88111
- name: Check Changes
89112
if: steps.apply.outputs.changes
90113
run: |
91114
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

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
"templateOSS": {
7676
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
7777
"windowsCI": false,
78-
"version": "4.3.2"
78+
"version": "4.4.4"
7979
},
8080
"author": "GitHub Inc.",
8181
"tap": {

0 commit comments

Comments
 (0)