forked from gatsbyjs/gatsby
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(actions): Add Site Showcase Validator Action (gatsbyjs#14363)
* feat(actions): Add Gatsby Site Showcase Validator Action * Update workflow file
- Loading branch information
1 parent
936ccf6
commit 585a9d3
Showing
5 changed files
with
124 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
FROM node:10-slim | ||
|
||
LABEL com.github.actions.name="gatsby-site-showcase-validator" | ||
LABEL com.github.actions.description="Check Gatsby's Site Showcase to validate all sites are built with Gatsby" | ||
LABEL com.github.actions.icon="monitor" | ||
LABEL com.github.actions.color="purple" | ||
|
||
# Copy the action's code into the container | ||
COPY . . | ||
|
||
# Install dependencies | ||
RUN yarn | ||
|
||
# Start node app | ||
ENTRYPOINT [ "node", "/index.js" ] |
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,5 @@ | ||
# Gatsby Site Showcase Validator | ||
|
||
A simple node script that visits and checks all of the sites in the [Site Showcase](https://www.gatsbyjs.org/showcase/) for Gatsby. | ||
|
||
Run locally [using act](https://github.com/nektos/act): `act -a "gatsby-site-showcase-validator"` |
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,80 @@ | ||
// Load in modules | ||
const fetch = require("node-fetch") | ||
const yaml = require("js-yaml") | ||
const cheerio = require("cheerio") | ||
const chalk = require("chalk") | ||
|
||
async function run() { | ||
// Grab down sites.yml | ||
let url = | ||
"https://raw.githubusercontent.com/gatsbyjs/gatsby/master/docs/sites.yml" | ||
|
||
let yamlStr | ||
|
||
try { | ||
yamlStr = await fetch(url).then(resp => resp.text()) | ||
} catch (err) { | ||
console.log(`[Err]: ${err.message}`) | ||
process.exit(1) | ||
} | ||
|
||
// Parse YAML | ||
let parsedYaml = yaml.safeLoad(yamlStr, "utf8") | ||
|
||
let sitesVisited = 0 | ||
let nonGatsbySiteCount = 0 | ||
let erroredOut = 0 | ||
let totalSitesCount = parsedYaml.length | ||
|
||
// Loop over each site | ||
for (let site of parsedYaml) { | ||
let siteUrl = site.main_url | ||
|
||
let siteHtml | ||
|
||
// Fetch site | ||
try { | ||
siteHtml = await fetch(siteUrl).then(resp => resp.text()) | ||
} catch (err) { | ||
console.log( | ||
`${chalk.red(`[Err]`)}: ${site.title} (${siteUrl}) ran into an error: ${ | ||
err.message | ||
}` | ||
) | ||
sitesVisited++ | ||
erroredOut++ | ||
continue // Skip the rest of the check for this particular site | ||
} | ||
|
||
// Pass html into a parser | ||
let $ = cheerio.load(siteHtml) | ||
|
||
// Most Gatsby sites have an id of "___gatsby" | ||
let gatsbyContainer = $("#___gatsby") | ||
|
||
if (gatsbyContainer.length !== 0) { | ||
// The site is a gatsby site don't do anything | ||
sitesVisited++ | ||
} else { | ||
// The site is not a gatsby site, print out some info | ||
console.log( | ||
`${chalk.yellow(`[Notice]`)}: ${ | ||
site.title | ||
} (${siteUrl}) is not a Gatsby site` | ||
) | ||
sitesVisited++ | ||
nonGatsbySiteCount++ | ||
} | ||
} | ||
|
||
console.log( | ||
chalk.green( | ||
`We visited ${sitesVisited}/${totalSitesCount} sites. Out of them, ${nonGatsbySiteCount} sites were not a Gatsby site and ${erroredOut} errored out when visiting it.` | ||
) | ||
) | ||
|
||
// If there are any non Gatsby sites, fail (non-zero exit code) | ||
process.exit(nonGatsbySiteCount > 0 ? 1 : 0) | ||
} | ||
|
||
run() |
15 changes: 15 additions & 0 deletions
15
.github/actions/gatsby-site-showcase-validator/package.json
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,15 @@ | ||
{ | ||
"name": "gatsby-site-showcase-validator-action", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"private": true, | ||
"dependencies": { | ||
"chalk": "^2.4.2", | ||
"cheerio": "^1.0.0-rc.2", | ||
"js-yaml": "^3.12.2", | ||
"node-fetch": "^2.3.0" | ||
}, | ||
"scripts": { | ||
"start": "node ./index.js" | ||
} | ||
} |
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