Hey there Netlify community!
I’m trying to configure my Netlify builds to ignore PRs opened by Dependabot.
I found this blog post describing how to do it, but it didn’t seem to work.
My app is open source so you can see a recent build . If you +F for “ignore” you’ll see
5:08:28 PM: Detected ignore command in Netlify configuration file. Proceeding with the specified command: ‘git log -1 --pretty=%B | grep dependabot’
…and yet, the build proceeded.
I’d love any help diagnosing this + figuring out how to configure these builds to stop! They’re really eating up our monthly resources.
Thanks!
luke
July 6, 2020, 5:34am
2
Hi, @samselikoff , I think it is because there is no local branch for the PR and to the command is exiting with a 1 (which continues the build) instead of the expected exit code of 0 (which grep
will use if there are any matching lines).
Here is what I see in testing:
$ git clone <repo url here>
Cloning into 'site'...
remote: Enumerating objects: 6, done.
remote: Counting objects: 100% (6/6), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 4649 (delta 3), reused 2 (delta 2), pack-reused 4643
Receiving objects: 100% (4649/4649), 46.77 MiB | 10.58 MiB/s, done.
Resolving deltas: 100% (3077/3077), done.
$ cd site
$ git fetch origin pull/764/head
From https://github.com/miragejs/site
* branch refs/pull/764/head -> FETCH_HEAD
$ git log -1 --pretty=%B | grep dependabot ; echo $?
1
The exit code above is 1
which, again, will continue no cancel a build because there were no matching lines.
The following might work though:
$ git checkout -b pullrequest FETCH_HEAD ; git log -1 --pretty=%B | grep dependabot ; echo $?
fatal: A branch named 'pullrequest' already exists.
Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
0
So, (removing the exit code test echo
command), this would be:
git checkout -b pullrequest FETCH_HEAD ; git log -1 --pretty=%B | grep dependabot
Would you please test making that line above the build.ignore
command?
If that doesn’t work or if there are any questions, please let us know.
Ah, I see. (Just curious, how were you able to see that git fetch origin pull/764/head
is what Netlify does during its build, rather than checking out a branch?)
Will give this a shot! Thanks for the fast response
1 Like
Hey @luke , here’s a PR build from last night:
It looks like Netlify still built the Dependabot PR.
Any other ideas?
Scott
July 7, 2020, 12:54pm
6
Hey @samselikoff ,
Hmm, maybe we’ll try something else! How about this suggestion from our very own Marcus?
You could also customise Dependabot’s commit message to include [skip ci]
or [skip netlify]
, too!
Thanks for the link! I think Marcus’ suggestion of
git log -1 --pretty=%B | grep dependabot
was the same I tried originally from the blog post. And here you can see an example where the command was picked up but it didn’t work.
I didn’t know you could customize Dependabot’s commit messages. I did some digging on how to do that but couldn’t find anything, either in GitHub’s app integration settings or on dependabot.com . Could you point me to some instructions on how to do that?
Scott
July 7, 2020, 2:23pm
8
Hey @samselikoff ,
That’s gonna be this handy doc right here if you’re using the none-native Dependabot or this for the native version!
1 Like
Oh awesome! Missed this one.
Gonna give it a shot!
Looks like it worked!!
miragejs:master
← miragejs:dependabot/npm_and_yarn/gatsby-2.23.22
opened 07:49PM - 07 Jul 20 UTC
Bumps [gatsby](https://github.com/gatsbyjs/gatsby) from 2.23.21 to 2.23.22.
<det… ails>
<summary>Commits</summary>
<ul>
<li><a href="https://github.com/gatsbyjs/gatsby/commit/425fdac890ac5260edb7419635f97bec1e58871b"><code>425fdac</code></a> chore(release): Publish</li>
<li><a href="https://github.com/gatsbyjs/gatsby/commit/e5ce35b9456784288634f2070a0f319b8fe76873"><code>e5ce35b</code></a> feat(gatsby): Use state machine for query running in develop (<a href="https://github-redirect.dependabot.com/gatsbyjs/gatsby/issues/25378">#25378</a>)</li>
<li><a href="https://github.com/gatsbyjs/gatsby/commit/38db76e19af35fc335a1ca56b9a3d2cb72f5f4bd"><code>38db76e</code></a> chore(blog): Uupdate some of my mentions (<a href="https://github-redirect.dependabot.com/gatsbyjs/gatsby/issues/25564">#25564</a>)</li>
<li><a href="https://github.com/gatsbyjs/gatsby/commit/a9303504d162d24f45336e561fca90c141adb0f2"><code>a930350</code></a> refactor(www): clean up get-prev-and-next (<a href="https://github-redirect.dependabot.com/gatsbyjs/gatsby/issues/25561">#25561</a>)</li>
<li><a href="https://github.com/gatsbyjs/gatsby/commit/d5bec224e838bc0c81d5ed2ee6c5cf23407b0e4f"><code>d5bec22</code></a> remove console statement in component (<a href="https://github-redirect.dependabot.com/gatsbyjs/gatsby/issues/25563">#25563</a>)</li>
<li><a href="https://github.com/gatsbyjs/gatsby/commit/3428e3783376db4f17b5adaf2ed456c70735d149"><code>3428e37</code></a> chore(www): tidy breakout component (<a href="https://github-redirect.dependabot.com/gatsbyjs/gatsby/issues/25551">#25551</a>)</li>
<li><a href="https://github.com/gatsbyjs/gatsby/commit/c146df9741795665cd3379964cb71170008993ec"><code>c146df9</code></a> fix brand name: Agility CMS (<a href="https://github-redirect.dependabot.com/gatsbyjs/gatsby/issues/25527">#25527</a>)</li>
<li><a href="https://github.com/gatsbyjs/gatsby/commit/945b61180b01b379ad805d27bf813b423059a632"><code>945b611</code></a> remove local domain (<a href="https://github-redirect.dependabot.com/gatsbyjs/gatsby/issues/25555">#25555</a>)</li>
<li><a href="https://github.com/gatsbyjs/gatsby/commit/3ef2e6e5aef10ec9602a4ede32b999e4b6f4583a"><code>3ef2e6e</code></a> chore(docs): Add 21yunbox for deployment (<a href="https://github-redirect.dependabot.com/gatsbyjs/gatsby/issues/24429">#24429</a>)</li>
<li><a href="https://github.com/gatsbyjs/gatsby/commit/c05e44515b1a84277d749ba98628b6069b0a0749"><code>c05e445</code></a> fix(docs): Add better messaging on how to add new words to the dictionary for...</li>
<li>Additional commits viewable in <a href="https://github.com/gatsbyjs/gatsby/compare/gatsby@2.23.21...gatsby@2.23.22">compare view</a></li>
</ul>
</details>
<br />
[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=gatsby&package-manager=npm_and_yarn&previous-version=2.23.21&new-version=2.23.22)](https://help.github.com/articles/configuring-automated-security-fixes)
Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.
[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)
---
<details>
<summary>Dependabot commands and options</summary>
<br />
You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
</details>
Thanks @Scott , I think this should be the accepted answer.
I also think the original blog post I linked to should probably be updated, because (1) it’s an official Netlify guide & tutorial, (2) I don’t believe it works as stated (as others said in the other thread), and (3) it’s one of the first search results that comes up when you search for “Netlify and Dependabot”.
Thank you so much for your help!
Question: Once I merge a PR into master, I do want Netlify to build + deploy my site.
Can you think of how to do this, where the [skip netlify] prefix is in the commit message but Netlify always builds/deploys on the master
branch?
Scott
July 7, 2020, 11:04pm
12
We can’t circumvent the [skip ci/netlify] ignore, unfortunately! Is it not possible to update the commit message when merging?
If not, we’d be back to using a script and deploy contexts .
Hm that would be possible but most Dependabot PRs are auto merged. So I think that means I should explore the script approach.
I’ve never seen the script approach, do you have a guide or example you could point me to there?
Scott
July 9, 2020, 9:43am
14
Hey @samselikoff , it’s similar to Marcus’ suggestion above which you’ve tried, only in a script! This is what I envision and you can even try the ‘exit 0’ script first to ensure that a Dependabot-specific script is going to work .
Another suggestion is write a build plugin that cancels the build based on your criteria.
Here’s some untested pseudo-code:
module.exports = {
onPreBuild: ({ utils }) => {
if (utils.git.commits[0].committer.name.includes('dependabot')) {
utils.build.cancelBuild('Cancelling dependabot PR.')
}
},
}