Add netlify process
continuous-integration/woodpecker the build was successful
Details
continuous-integration/woodpecker the build was successful
Details
Signed-off-by: jolheiser <john.olheiser@gmail.com>
parent
49129bb471
commit
944443b27e
|
@ -10,3 +10,5 @@ dist/
|
||||||
|
|
||||||
# Node
|
# Node
|
||||||
node_modules/
|
node_modules/
|
||||||
|
# Local Netlify folder
|
||||||
|
.netlify
|
||||||
|
|
|
@ -0,0 +1,71 @@
|
||||||
|
const slugify = require('slugify')
|
||||||
|
const {exec} = require('child_process')
|
||||||
|
const axios = require('axios')
|
||||||
|
|
||||||
|
const siteId = process.env.NETLIFY_SITE_ID
|
||||||
|
const branchSlug = slugify(process.env.DRONE_SOURCE_BRANCH)
|
||||||
|
const prNumber = process.env.CI_PULL_REQUEST
|
||||||
|
|
||||||
|
const alias = `${prNumber}-${branchSlug}`
|
||||||
|
|
||||||
|
const promiseExec = cmd => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
exec(cmd, (error, stdout, stderr) => {
|
||||||
|
if (error) {
|
||||||
|
reject(error)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
resolve(stdout)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
(async function () {
|
||||||
|
let stdout = await promiseExec(`./node_modules/.bin/netlify link --id ${siteId}`)
|
||||||
|
console.log(stdout)
|
||||||
|
stdout = await promiseExec(`./node_modules/.bin/netlify deploy --alias ${alias}`)
|
||||||
|
console.log(stdout)
|
||||||
|
})()
|
||||||
|
|
||||||
|
|
||||||
|
// We need the user id of the bot to prevent multiple comments as the PR gets updated
|
||||||
|
const BOT_USER_ID = 8
|
||||||
|
// The gitea token from the pipeline settings
|
||||||
|
const giteaToken = process.env.BOT_TOKEN
|
||||||
|
// The second, hard coded part of this url is something you need to set in Netlify's site settings.
|
||||||
|
const fullPreviewUrl = `https://${alias}--canopymc.netlify.app`
|
||||||
|
|
||||||
|
const prIssueCommentsUrl = `https://git.jojodev.com/api/v1/repos/Canopy/website/issues/${prNumber}/comments`;
|
||||||
|
|
||||||
|
(async function () {
|
||||||
|
|
||||||
|
// Here we get all comments through Gitea's API to see if there's already a comment from our bot
|
||||||
|
const {data} = await axios.get(prIssueCommentsUrl)
|
||||||
|
const hasComment = data.some(c => c.user.id === BOT_USER_ID)
|
||||||
|
|
||||||
|
if (hasComment) {
|
||||||
|
console.log(`PR #${prNumber} already has a comment with a link, not sending another comment.`)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Once we arrive here we know for sure there's no other comment yet. That means we can proceed to post one.
|
||||||
|
await axios.post(prIssueCommentsUrl, {
|
||||||
|
body: `
|
||||||
|
Hi ${process.env.CI_COMMIT_AUTHOR}!
|
||||||
|
|
||||||
|
Thank you for creating a PR!
|
||||||
|
|
||||||
|
[I've deployed a preview of the changes here.](${fullPreviewUrl})
|
||||||
|
|
||||||
|
> Beep boop, I'm a bot. :robot:
|
||||||
|
`,
|
||||||
|
}, {
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'accept': 'application/json',
|
||||||
|
'Authorization': `token ${giteaToken}`,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
console.log(`Preview comment sent successfully to PR #${prNumber}!`)
|
||||||
|
})()
|
|
@ -0,0 +1,11 @@
|
||||||
|
[build]
|
||||||
|
command = "npm build"
|
||||||
|
publish = "dist"
|
||||||
|
|
||||||
|
[[headers]]
|
||||||
|
for = "/*"
|
||||||
|
[headers.values]
|
||||||
|
X-Frame-Options = "DENY"
|
||||||
|
X-XSS-Protection = "1; mode=block"
|
||||||
|
X-Robots-Tag = "noindex"
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -18,12 +18,16 @@
|
||||||
"url": "https://git.jojodev.com/Canopy/canopymc.net.git"
|
"url": "https://git.jojodev.com/Canopy/canopymc.net.git"
|
||||||
},
|
},
|
||||||
"author": "",
|
"author": "",
|
||||||
"license": "IST",
|
"license": "MIT",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@fortawesome/fontawesome-free": "^5.15.1",
|
"@fortawesome/fontawesome-free": "^5.15.1",
|
||||||
"copyfiles": "^2.4.0",
|
"copyfiles": "^2.4.0",
|
||||||
"dart-sass": "^1.25.0",
|
"dart-sass": "^1.25.0",
|
||||||
"front-matter": "^4.0.2",
|
"front-matter": "^4.0.2",
|
||||||
"showdown": "^1.9.1"
|
"showdown": "^1.9.1",
|
||||||
|
"slugify": "^1.6.3",
|
||||||
|
"axios": "^0.24.0",
|
||||||
|
"netlify": "^10.0.0",
|
||||||
|
"netlify-cli": "^8.0.19"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
-->
|
-->
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>The Canopy</title>
|
<title>The Canopy MC</title>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<meta
|
<meta
|
||||||
name="viewport"
|
name="viewport"
|
||||||
|
|
Loading…
Reference in New Issue