Skip to content

Commit 6010883

Browse files
committed
chore: postinstall for dependabot template-oss PR
1 parent 802a66d commit 6010883

File tree

3 files changed

+85
-7
lines changed

3 files changed

+85
-7
lines changed

Diff for: .github/workflows/ci.yml

+48
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,54 @@ 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+
- 10.0.0
29+
runs-on: ${{ matrix.platform.os }}
30+
defaults:
31+
run:
32+
shell: ${{ matrix.platform.shell }}
33+
steps:
34+
- name: Checkout
35+
uses: actions/checkout@v3
36+
- name: Setup Git User
37+
run: |
38+
git config --global user.email "[email protected]"
39+
git config --global user.name "npm CLI robot"
40+
- name: Setup Node
41+
uses: actions/setup-node@v3
42+
with:
43+
node-version: ${{ matrix.node-version }}
44+
- name: Update Windows npm
45+
# node 12 and 14 ship with npm@6, which is known to fail when updating itself in windows
46+
if: matrix.platform.os == 'windows-latest' && (startsWith(matrix.node-version, '12.') || startsWith(matrix.node-version, '14.'))
47+
run: |
48+
curl -sO https://registry.npmjs.org/npm/-/npm-7.5.4.tgz
49+
tar xf npm-7.5.4.tgz
50+
cd package
51+
node lib/npm.js install --no-fund --no-audit -g ..\npm-7.5.4.tgz
52+
cd ..
53+
rmdir /s /q package
54+
- name: Install npm@7
55+
if: startsWith(matrix.node-version, '10.')
56+
run: npm i --prefer-online --no-fund --no-audit -g npm@7
57+
- name: Install npm@latest
58+
if: ${{ !startsWith(matrix.node-version, '10.') }}
59+
run: npm i --prefer-online --no-fund --no-audit -g npm@latest
60+
- name: npm Version
61+
run: npm -v
62+
- name: Install Dependencies
63+
run: npm i --ignore-scripts --no-audit --no-fund --engines-strict
64+
1765
lint:
1866
name: Lint
1967
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
@@ -53,7 +53,7 @@
5353
"author": "GitHub Inc.",
5454
"templateOSS": {
5555
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
56-
"version": "4.3.2",
56+
"version": "4.4.4",
5757
"engines": ">=10",
5858
"ciVersions": [
5959
"10.0.0",

0 commit comments

Comments
 (0)