19
19
- name : Checkout
20
20
uses : actions/checkout@v3
21
21
with :
22
- ref : ${{ github.event.pull_request.head_ref }}
22
+ ref : ${{ github.ref_name }}
23
23
- name : Setup Git User
24
24
run : |
25
25
git config --global user.email "[email protected] "
@@ -46,10 +46,13 @@ jobs:
46
46
if : contains(steps.metadata.outputs.dependency-names, '@npmcli/template-oss')
47
47
id : flags
48
48
run : |
49
- if [[ "${{ steps.metadata.outputs.directory }}" == "/" ]]; then
49
+ dependabot_dir="${{ steps.metadata.outputs.directory }}"
50
+ if [[ "$dependabot_dir" == "/" ]]; then
50
51
echo "::set-output name=workspace::-iwr"
51
52
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#/}"
53
56
fi
54
57
55
58
- name : Apply Changes
60
63
if [[ `git status --porcelain` ]]; then
61
64
echo "::set-output name=changes::true"
62
65
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"
63
75
64
76
# This step will fail if template-oss has made any workflow updates. It is impossible
65
77
# for a workflow to update other workflows. In the case it does fail, we continue
@@ -71,21 +83,39 @@ jobs:
71
83
env :
72
84
GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
73
85
run : |
74
- git commit -am "chore: postinstall for dependabot template-oss PR "
86
+ git commit -am "${{ steps.apply.outputs.message }} "
75
87
git push
76
88
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.
77
92
- name : Push All Changes Except Workflows
78
- if : steps.push.outcome == 'failure'
93
+ if : steps.apply.outputs.changes && steps. push-all .outcome == 'failure'
79
94
env :
80
95
GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
81
96
run : |
82
97
git reset HEAD~
83
98
git checkout HEAD -- .github/workflows/
84
99
git clean -fd .github/workflows/
85
- git commit -am "chore: postinstall for dependabot template-oss PR "
100
+ git commit -am "${{ steps.apply.outputs.message }} "
86
101
git push
87
102
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.
88
111
- name : Check Changes
89
112
if : steps.apply.outputs.changes
90
113
run : |
91
114
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