feat: add deploy script
continuous-integration/drone/pr Build is passing Details

This commit is contained in:
kolaente 2021-11-10 21:38:32 +01:00
parent 10389c492e
commit 0dd9a26926
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
4 changed files with 63 additions and 3 deletions

View File

@ -144,10 +144,10 @@ steps:
from_secret: netlify_auth_token
NETLIFY_SITE_ID:
from_secret: netlify_site_id
GITEA_TOKEN:
from_secret: gitea_token
commands:
- ./node_modules/.bin/netlify link --id $NETLIFY_SITE_ID
- ./node_modules/.bin/netlify deploy
- env
- node ./scripts/deploy-preview-netlify.js
depends_on:
- build-prod

View File

@ -75,6 +75,7 @@
"rollup": "2.59.0",
"rollup-plugin-visualizer": "5.5.2",
"sass": "1.43.4",
"slugify": "^1.6.2",
"ts-jest": "27.0.7",
"typescript": "4.4.4",
"vite": "2.6.14",

View File

@ -0,0 +1,54 @@
const slugify = require('slugify')
const {exec} = require('child_process')
const axios = require('axios')
const giteaToken = process.env.GITEA_TOKEN
const siteId = process.env.NETLIFY_SITE_ID
const branchSlug = slugify(process.env.DRONE_SOURCE_BRANCH)
const prNumber = process.env.DRONE_PULL_REQUEST
const prIssueUrl = `https://kolaente.dev/api/v1/repos/vikunja/frontend/issues/${prNumber}/comments`
const alias = `${prNumber}-${branchSlug}`
const fullPreviewUrl = `https://${alias}--vikunja-frontend-preview.netlify.app`
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)
await axios.post(prIssueUrl, {
body: `
Hi!
I've deployed the changes of this PR on a preview environment under this URL: ${fullPreviewUrl}
You can use this url to view the changes live and test them out.
You will need to manually connect this to an api running somehwere. The easiest to use is https://try.vikunja.io/.
Have a nice day!
> Beep boop, I'm a bot.
`,
}, {
headers: {
'Content-Type': 'application/json',
'accept': 'application/json',
'Authorization': `token ${giteaToken}`,
},
})
.catch(err => console.log('Error sending comment:', err))
})()

View File

@ -11849,6 +11849,11 @@ slice-ansi@^4.0.0:
astral-regex "^2.0.0"
is-fullwidth-code-point "^3.0.0"
slugify@^1.6.2:
version "1.6.2"
resolved "https://registry.yarnpkg.com/slugify/-/slugify-1.6.2.tgz#4cb97220a2278e1b86fb017c6da668e6a865354c"
integrity sha512-XMtI8qD84LwCpthLMBHlIhcrj10cgA+U/Ot8G6FD6uFuWZtMfKK75JO7l81nzpFJsPlsW6LT+VKqWQJW3+6New==
snake-case@3.0.4:
version "3.0.4"
resolved "https://registry.yarnpkg.com/snake-case/-/snake-case-3.0.4.tgz#4f2bbd568e9935abdfd593f34c691dadb49c452c"