-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: postinstall for dependabot template-oss PR
- Loading branch information
1 parent
dc3be3c
commit cb6e8ef
Showing
3 changed files
with
87 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,56 @@ on: | |
- cron: "0 9 * * 1" | ||
|
||
jobs: | ||
engines: | ||
name: Engines - ${{ matrix.platform.name }} - ${{ matrix.node-version }} | ||
if: github.repository_owner == 'npm' | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
platform: | ||
- name: Linux | ||
os: ubuntu-latest | ||
shell: bash | ||
node-version: | ||
- 14.17.0 | ||
- 16.13.0 | ||
- 18.0.0 | ||
runs-on: ${{ matrix.platform.os }} | ||
defaults: | ||
run: | ||
shell: ${{ matrix.platform.shell }} | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
- name: Setup Git User | ||
run: | | ||
git config --global user.email "[email protected]" | ||
git config --global user.name "npm CLI robot" | ||
- name: Setup Node | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- name: Update Windows npm | ||
# node 12 and 14 ship with npm@6, which is known to fail when updating itself in windows | ||
if: matrix.platform.os == 'windows-latest' && (startsWith(matrix.node-version, '12.') || startsWith(matrix.node-version, '14.')) | ||
run: | | ||
curl -sO https://registry.npmjs.org/npm/-/npm-7.5.4.tgz | ||
tar xf npm-7.5.4.tgz | ||
cd package | ||
node lib/npm.js install --no-fund --no-audit -g ..\npm-7.5.4.tgz | ||
cd .. | ||
rmdir /s /q package | ||
- name: Install npm@7 | ||
if: startsWith(matrix.node-version, '10.') | ||
run: npm i --prefer-online --no-fund --no-audit -g npm@7 | ||
- name: Install npm@latest | ||
if: ${{ !startsWith(matrix.node-version, '10.') }} | ||
run: npm i --prefer-online --no-fund --no-audit -g npm@latest | ||
- name: npm Version | ||
run: npm -v | ||
- name: Install Dependencies | ||
run: npm i --ignore-scripts --no-audit --no-fund --engines-strict | ||
|
||
lint: | ||
name: Lint | ||
if: github.repository_owner == 'npm' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ jobs: | |
- name: Checkout | ||
uses: actions/checkout@v3 | ||
with: | ||
ref: ${{ github.event.pull_request.head_ref }} | ||
ref: ${{ github.ref_name }} | ||
- name: Setup Git User | ||
run: | | ||
git config --global user.email "[email protected]" | ||
|
@@ -46,10 +46,13 @@ jobs: | |
if: contains(steps.metadata.outputs.dependency-names, '@npmcli/template-oss') | ||
id: flags | ||
run: | | ||
if [[ "${{ steps.metadata.outputs.directory }}" == "/" ]]; then | ||
dependabot_dir="${{ steps.metadata.outputs.directory }}" | ||
if [[ "$dependabot_dir" == "/" ]]; then | ||
echo "::set-output name=workspace::-iwr" | ||
else | ||
echo "::set-output name=workspace::-w ${{ steps.metadata.outputs.directory }}" | ||
# strip leading slash from directory so it works as a | ||
# a path to the workspace flag | ||
echo "::set-output name=workspace::-w ${dependabot_dir#/}" | ||
fi | ||
- name: Apply Changes | ||
|
@@ -60,6 +63,15 @@ jobs: | |
if [[ `git status --porcelain` ]]; then | ||
echo "::set-output name=changes::true" | ||
fi | ||
# This only sets the conventional commit prefix. This workflow can't reliably determine | ||
# what the breaking change is though. If a BREAKING CHANGE message is required then | ||
# this PR check will fail and the commit will be amended with stafftools | ||
if [[ "${{ steps.dependabot-metadata.outputs.update-type }}" == "version-update:semver-major" ]]; then | ||
prefix='feat!' | ||
else | ||
prefix='chore!' | ||
fi | ||
echo "::set-output name=message::$prefix: postinstall for dependabot template-oss PR" | ||
# This step will fail if template-oss has made any workflow updates. It is impossible | ||
# for a workflow to update other workflows. In the case it does fail, we continue | ||
|
@@ -71,21 +83,39 @@ jobs: | |
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
git commit -am "chore: postinstall for dependabot template-oss PR" | ||
git commit -am "${{ steps.apply.outputs.message }}" | ||
git push | ||
# If the previous step failed, then reset the commit and remove any workflow changes | ||
# and attempt to commit and push again. This is helpful because we will have a commit | ||
# with the correct prefix that we can then --amend with @npmcli/stafftools later. | ||
- name: Push All Changes Except Workflows | ||
if: steps.push.outcome == 'failure' | ||
if: steps.apply.outputs.changes && steps.push-all.outcome == 'failure' | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
git reset HEAD~ | ||
git checkout HEAD -- .github/workflows/ | ||
git clean -fd .github/workflows/ | ||
git commit -am "chore: postinstall for dependabot template-oss PR" | ||
git commit -am "${{ steps.apply.outputs.message }}" | ||
git push | ||
# Check if all the necessary template-oss changes were applied. Since we continued | ||
# on errors in one of the previous steps, this check will fail if our follow up | ||
# only applied a portion of the changes and we need to followup manually. | ||
# | ||
# Note that this used to run `lint` and `postlint` but that will fail this action | ||
# if we've also shipped any linting changes separate from template-oss. We do | ||
# linting in another action, so we want to fail this one only if there are | ||
# template-oss changes that could not be applied. | ||
- name: Check Changes | ||
if: steps.apply.outputs.changes | ||
run: | | ||
npm exec --offline ${{ steps.flags.outputs.workspace }} -- template-oss-check | ||
- name: Fail on Breaking Change | ||
if: steps.apply.outputs.changes && startsWith(steps.apply.outputs.message, 'feat!') | ||
run: | | ||
echo "This PR has a breaking change. Run 'npx -p @npmcli/stafftools gh template-oss-fix'" | ||
echo "for more information on how to fix this with a BREAKING CHANGE footer." | ||
exit 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters