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
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
0 commit comments