-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Netlify: ignore PRs without changes in the docs directory (#5328)
* Ignore PRs w/o files in the docs directory * Fix return and comment * debug * try adding origin * add logging * handle remote already existing * debug again * use git remote -v to check * final logging * final final logging
- Loading branch information
Showing
2 changed files
with
49 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// We only want Netlify to build the site if a PR changes files in this `docs` directory. | ||
// See https://docs.netlify.com/configure-builds/ignore-builds. | ||
// Note: Netilfy runs this via Node.js 12. | ||
|
||
const { execSync } = require('child_process') | ||
|
||
console.log('------------------------') | ||
console.log("Running 'docs/ignore_build.js'") | ||
|
||
const remoteExists = execSync('git remote -v').toString().includes('origin') | ||
|
||
if (remoteExists) { | ||
console.log('Remote exists') | ||
} else { | ||
console.log('Adding remote') | ||
execSync('git remote add origin https://github.com/redwoodjs/redwood.git') | ||
} | ||
|
||
console.log('Fetching main') | ||
execSync('git fetch origin main') | ||
|
||
console.log('Diffing changed files against main (name only)') | ||
const changedFiles = execSync('git diff origin/main --name-only') | ||
.toString() | ||
.trim() | ||
.split('\n') | ||
.filter(Boolean) | ||
console.log({ | ||
changedFiles, | ||
}) | ||
|
||
const shouldBuild = changedFiles.some((changedFile) => | ||
changedFile.startsWith('docs') | ||
) | ||
console.log({ | ||
shouldBuild, | ||
}) | ||
|
||
// We've done all the logic based on whether we should build the site, | ||
// but since this is an ignore script, we have to flip the logic here. | ||
if (shouldBuild) { | ||
console.log(`PR '${process.env.HEAD}' has doc changes. Proceeding`) | ||
process.exitCode = 1 | ||
} else { | ||
console.log(`PR '${process.env.HEAD}' doesn't have doc changes. Ignoring`) | ||
} | ||
console.log('------------------------') |
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