Skip to content

Commit 585a9d3

Browse files
lannonbrm-allanson
authored andcommitted
feat(actions): Add Site Showcase Validator Action (#14363)
* feat(actions): Add Gatsby Site Showcase Validator Action * Update workflow file
1 parent 936ccf6 commit 585a9d3

File tree

5 files changed

+124
-0
lines changed

5 files changed

+124
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM node:10-slim
2+
3+
LABEL com.github.actions.name="gatsby-site-showcase-validator"
4+
LABEL com.github.actions.description="Check Gatsby's Site Showcase to validate all sites are built with Gatsby"
5+
LABEL com.github.actions.icon="monitor"
6+
LABEL com.github.actions.color="purple"
7+
8+
# Copy the action's code into the container
9+
COPY . .
10+
11+
# Install dependencies
12+
RUN yarn
13+
14+
# Start node app
15+
ENTRYPOINT [ "node", "/index.js" ]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Gatsby Site Showcase Validator
2+
3+
A simple node script that visits and checks all of the sites in the [Site Showcase](https://www.gatsbyjs.org/showcase/) for Gatsby.
4+
5+
Run locally [using act](https://github.com/nektos/act): `act -a "gatsby-site-showcase-validator"`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// Load in modules
2+
const fetch = require("node-fetch")
3+
const yaml = require("js-yaml")
4+
const cheerio = require("cheerio")
5+
const chalk = require("chalk")
6+
7+
async function run() {
8+
// Grab down sites.yml
9+
let url =
10+
"https://raw.githubusercontent.com/gatsbyjs/gatsby/master/docs/sites.yml"
11+
12+
let yamlStr
13+
14+
try {
15+
yamlStr = await fetch(url).then(resp => resp.text())
16+
} catch (err) {
17+
console.log(`[Err]: ${err.message}`)
18+
process.exit(1)
19+
}
20+
21+
// Parse YAML
22+
let parsedYaml = yaml.safeLoad(yamlStr, "utf8")
23+
24+
let sitesVisited = 0
25+
let nonGatsbySiteCount = 0
26+
let erroredOut = 0
27+
let totalSitesCount = parsedYaml.length
28+
29+
// Loop over each site
30+
for (let site of parsedYaml) {
31+
let siteUrl = site.main_url
32+
33+
let siteHtml
34+
35+
// Fetch site
36+
try {
37+
siteHtml = await fetch(siteUrl).then(resp => resp.text())
38+
} catch (err) {
39+
console.log(
40+
`${chalk.red(`[Err]`)}: ${site.title} (${siteUrl}) ran into an error: ${
41+
err.message
42+
}`
43+
)
44+
sitesVisited++
45+
erroredOut++
46+
continue // Skip the rest of the check for this particular site
47+
}
48+
49+
// Pass html into a parser
50+
let $ = cheerio.load(siteHtml)
51+
52+
// Most Gatsby sites have an id of "___gatsby"
53+
let gatsbyContainer = $("#___gatsby")
54+
55+
if (gatsbyContainer.length !== 0) {
56+
// The site is a gatsby site don't do anything
57+
sitesVisited++
58+
} else {
59+
// The site is not a gatsby site, print out some info
60+
console.log(
61+
`${chalk.yellow(`[Notice]`)}: ${
62+
site.title
63+
} (${siteUrl}) is not a Gatsby site`
64+
)
65+
sitesVisited++
66+
nonGatsbySiteCount++
67+
}
68+
}
69+
70+
console.log(
71+
chalk.green(
72+
`We visited ${sitesVisited}/${totalSitesCount} sites. Out of them, ${nonGatsbySiteCount} sites were not a Gatsby site and ${erroredOut} errored out when visiting it.`
73+
)
74+
)
75+
76+
// If there are any non Gatsby sites, fail (non-zero exit code)
77+
process.exit(nonGatsbySiteCount > 0 ? 1 : 0)
78+
}
79+
80+
run()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "gatsby-site-showcase-validator-action",
3+
"version": "1.0.0",
4+
"main": "index.js",
5+
"private": true,
6+
"dependencies": {
7+
"chalk": "^2.4.2",
8+
"cheerio": "^1.0.0-rc.2",
9+
"js-yaml": "^3.12.2",
10+
"node-fetch": "^2.3.0"
11+
},
12+
"scripts": {
13+
"start": "node ./index.js"
14+
}
15+
}

.github/main.workflow

+9
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,12 @@ action "high-priority-prs" {
1111
"SLACK_CHANNEL_ID",
1212
]
1313
}
14+
15+
workflow "Site Showcase Validator workflow" {
16+
resolves = ["gatsby-site-showcase-validator"]
17+
on = "schedule(0 0 * * *)"
18+
}
19+
20+
action "gatsby-site-showcase-validator" {
21+
uses = "./.github/actions/gatsby-site-showcase-validator"
22+
}

0 commit comments

Comments
 (0)