-
-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: update website configuration to match typegoose
this means there is now versioning also means that it is now in-sync with typegoose again
- Loading branch information
Showing
13 changed files
with
858 additions
and
225 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 |
---|---|---|
|
@@ -27,12 +27,4 @@ jobs: | |
with: | ||
node-version: 18.x | ||
- name: Install & Build | ||
run: bash ./ghPagesPre.sh | ||
- name: Deploy to Github Pages | ||
uses: JamesIves/[email protected] | ||
with: | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
branch: gh-pages | ||
folder: . # the root, because the provided script already moves files | ||
git-config-email: <> # disable gh-pages commits to have a email assigned to them | ||
git-config-name: 'actions-deploy' # set a custom name, so that the original author of the commit that triggered the website build is not associated with this commit, which was not made by them | ||
run: node scripts/ghPagesDeploy.js |
This file was deleted.
Oops, something went wrong.
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,44 @@ | ||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
/* | ||
* Script to get deployment information | ||
*/ | ||
|
||
module.exports = function getDeployInfo() { | ||
/** Branch we are currently on and will be used for edit branch */ | ||
let branch = 'master'; | ||
/** Name of the deploy */ | ||
let deployName = ''; | ||
let packagejson = require('../packages/mongodb-memory-server-core/package.json'); | ||
|
||
function checkDeploy() { | ||
if (process.env['CI'] === 'true' && process.env['GITHUB_REF_NAME']) { | ||
const refName = process.env['GITHUB_REF_NAME']; | ||
|
||
const oldBranchMatches = /^old\/(\d+\.x)/.exec(refName); | ||
|
||
if (oldBranchMatches) { | ||
branch = 'old/' + oldBranchMatches[1]; | ||
deployName = oldBranchMatches[1]; | ||
|
||
return; | ||
} | ||
|
||
if (refName === 'beta') { | ||
branch = deployName = 'beta'; | ||
|
||
return; | ||
} | ||
} | ||
} | ||
|
||
checkDeploy(); | ||
|
||
return { | ||
branch, | ||
// change deploy name to be the deploy path in version directory | ||
deployPath: !!deployName ? `versions/${deployName}` : '', | ||
// deploy name should always be defined, if not set via the above, use the package.json major version | ||
deployName: !!deployName ? deployName : packagejson.version.split('.')[0] + '.x', | ||
searchName: deployName.length === 0 ? 'current' : deployName, | ||
}; | ||
}; |
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,201 @@ | ||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
const deployInfo = require('./getDeployInfo')(); | ||
const { execSync } = require('node:child_process'); | ||
const fs = require('node:fs'); | ||
const path = require('node:path'); | ||
|
||
/* Constants / Config */ | ||
|
||
/** keep ".git", ".github", "website" and "scripts" */ | ||
const keepRegex = /^(?:\.git|website|scripts|versions)/; | ||
/** Regex to filter and get versions output from git ls-tree */ | ||
const versionsFilter = /^versions\/(\d+\.x|beta)\/?$/; | ||
/** Which branch to deploy to */ | ||
const pagesBranch = 'gh-pages'; | ||
/** As who should the deploy commit be made as */ | ||
const commiterInfo = { | ||
name: 'github-pages-deploy', | ||
email: '<>', | ||
}; | ||
/** Commit message to use, from commit will be automatically added */ | ||
const commitMessage = `Deploying to ${pagesBranch}`; | ||
|
||
/** | ||
* This Script should not be run outside of a CI or a testing directory | ||
*/ | ||
|
||
function main() { | ||
// ensure this script is not accidentally run | ||
if (process.env['CI'] !== 'true') { | ||
console.log( | ||
'No CI detected, refusing to run\n' + | ||
'Make sure you are running this script in a copy and set Environment Variable CI to true' | ||
); | ||
|
||
process.exit(1); | ||
} | ||
|
||
// ensure the gh-pages branch exists and is up-to-date | ||
execSync(`git fetch origin ${pagesBranch}:${pagesBranch}`, { stdio: 'inherit' }); | ||
|
||
// setup commiter info | ||
execSync(`git config user.name "${commiterInfo.name}"`, { stdio: 'inherit' }); | ||
execSync(`git config user.email "${commiterInfo.email}"`, { stdio: 'inherit' }); | ||
|
||
console.log('\nInstall & Build of website\n'); | ||
|
||
// make sure everything is correctly installed | ||
execSync('yarn --cwd ./website install', { stdio: 'inherit' }); | ||
|
||
// build the website | ||
execSync('yarn --cwd ./website build', { stdio: 'inherit' }); | ||
|
||
console.log('\nSwitching Branches\n'); | ||
|
||
// ensure there is nothing blocking from changing branches | ||
execSync('git add -A', { stdio: 'inherit' }); | ||
execSync('git stash push', { stdio: 'inherit' }); | ||
|
||
// works because "website" does not exist on the gh-pages branch | ||
execSync(`git checkout ${pagesBranch}`, { stdio: 'inherit' }); | ||
|
||
console.log('\nRemoving & Moving build\n'); | ||
|
||
// create deployAs directory, if not empty | ||
if (!!deployInfo.deployPath) { | ||
fs.mkdirSync(deployInfo.deployPath, { recursive: true }); | ||
} | ||
|
||
// remove everything except from the "keep" regex | ||
const deployCleanDir = path.join('.', deployInfo.deployPath); | ||
for (const entry of fs.readdirSync(deployCleanDir)) { | ||
if (entry.match(keepRegex)) { | ||
continue; | ||
} | ||
|
||
const rmPath = path.join(deployCleanDir, entry); | ||
|
||
console.log('rm', rmPath); // always log what is removed | ||
fs.rmSync(rmPath, { recursive: true }); | ||
} | ||
|
||
// move all files from "website/build" to "deployAs" | ||
const websiteDir = 'website/build'; | ||
for (const entry of fs.readdirSync(websiteDir)) { | ||
if (entry.match(keepRegex)) { | ||
console.error('Website build contained entry from keep. Skipping! entry:', entry); | ||
continue; | ||
} | ||
|
||
const from = path.join(websiteDir, entry); | ||
const to = path.join(deployInfo.deployPath, entry); | ||
console.log('rename', from, '->', to); // always log what is renamed | ||
fs.renameSync(from, to); | ||
} | ||
|
||
// remove website | ||
fs.rmSync('website', { recursive: true }); | ||
|
||
// generate versions.json file | ||
const versions = generateVersions(); | ||
fs.writeFileSync('versions.json', JSON.stringify(versions)); | ||
|
||
console.log('\nCommiting Changes\n'); | ||
|
||
// add stage all changes | ||
execSync('git add *', { stdio: 'inherit' }); | ||
|
||
let commitmsg = commitMessage; | ||
const githubSHA = process.env['GITHUB_SHA']; | ||
|
||
if (githubSHA) { | ||
commitmsg += ` from @ ${githubSHA}`; | ||
} | ||
|
||
// commit the changes | ||
execSync(`git commit -m "${commitmsg}"`, { stdio: 'inherit' }); | ||
|
||
// refuse to push changes when not being in a CI (even if CI=true) for local testing | ||
if (!githubSHA) { | ||
console.log( | ||
'Refusing to push changes, because not in a CI (missing evironment variable "GITHUB_SHA")' | ||
); | ||
process.exit(2); | ||
} | ||
|
||
console.log('\nPushing Changes\n'); | ||
|
||
execSync(`git push --set-upstream origin ${pagesBranch}`, { stdio: 'inherit' }); | ||
} | ||
|
||
main(); | ||
|
||
/** | ||
* Generate the versions.json file | ||
* @returns Object with keys sorted so that "beta" is first and otherwise the highest number descending | ||
*/ | ||
function generateVersions() { | ||
console.log('\nGenerating Versions\n'); | ||
|
||
const versions_map = new Map(); | ||
|
||
try { | ||
// get existing versions.json file to include version that to merge them | ||
const pagesVersions = execSync(`git show ${pagesBranch}:versions.json`).toString(); | ||
|
||
const parsed = JSON.parse(pagesVersions); | ||
|
||
if (Array.isArray(parsed)) { | ||
throw new Error('versions.json is a array, expected object'); | ||
} | ||
|
||
for (const [key, path] of Object.entries(parsed)) { | ||
versions_map.set(key, path); | ||
} | ||
} catch (err) { | ||
console.log('failed to get existing versions.json:', err); | ||
} | ||
|
||
// get all existing versions from the gh-pages branch and merge them with existing versions.json | ||
const versions_tree = execSync(`git ls-tree --name-only ${pagesBranch} versions/`); | ||
|
||
// parse all versions from the git output | ||
for (const line of versions_tree.toString().split('\n')) { | ||
const caps = versionsFilter.exec(line); | ||
|
||
if (caps) { | ||
versions_map.set(caps[1], line); | ||
continue; | ||
} | ||
|
||
// ignore a empty line (to log no warning) | ||
if (line.length === 0) { | ||
continue; | ||
} | ||
|
||
console.log('no match found for version line:', line); | ||
} | ||
|
||
// always add the current version | ||
versions_map.set(deployInfo.deployName, deployInfo.deployPath); | ||
|
||
// sort the versions so that named branches are at specific places and numbers are highest descending | ||
const versions = Array.from(versions_map.entries()).sort(([versionA], [versionB]) => { | ||
if (versionA === 'beta' && versionB === 'beta') { | ||
return 0; | ||
} | ||
if (versionA === 'beta') { | ||
return -1; | ||
} | ||
if (versionB === 'beta') { | ||
return 1; | ||
} | ||
|
||
const parsedA = parseInt(versionA.split('.')[0]); | ||
const parsedB = parseInt(versionB.split('.')[0]); | ||
|
||
return parsedB - parsedA; | ||
}); | ||
|
||
return Object.fromEntries(versions); | ||
} |
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
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 |
---|---|---|
@@ -1,31 +1,33 @@ | ||
This website is built using [Docusaurus 2](https://v2.docusaurus.io/), a modern static website generator. | ||
|
||
### Installation | ||
Note: `yarn` is required otherwise, some plugins don't work | ||
|
||
``` | ||
## Installation | ||
|
||
```sh | ||
yarn | ||
``` | ||
|
||
### Local Development | ||
## Local Development | ||
|
||
``` | ||
```sh | ||
yarn start | ||
``` | ||
|
||
This command starts a local development server and open up a browser window. Most changes are reflected live without having to restart the server. | ||
This command starts a local development server and opens up a browser window. Most changes are reflected live without having to restart the server. | ||
|
||
### Build | ||
## Build | ||
|
||
``` | ||
```sh | ||
yarn build | ||
``` | ||
|
||
This command generates static content into the `build` directory and can be served using any static contents hosting service. | ||
|
||
### Deployment | ||
## Deployment | ||
|
||
``` | ||
$ GIT_USER=<Your GitHub username> USE_SSH=true yarn deploy | ||
```sh | ||
GIT_USER=<Your GitHub username> USE_SSH=true yarn deploy | ||
``` | ||
|
||
If you are using GitHub pages for hosting, this command is a convenient way to build the website and push to the `gh-pages` branch. |
Oops, something went wrong.