Skip to content

Commit

Permalink
Merge pull request #1448 from ckeditor/t/1392
Browse files Browse the repository at this point in the history
Internal: Introduced a script which cleans up the repository that contains the project's documentation. Closes #1392.
  • Loading branch information
Reinmar authored Jan 10, 2019
2 parents ef2a854 + 7e5fedb commit 3719b14
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion scripts/docs/build-and-publish-nightly.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ if ( process.env.TRAVIS_EVENT_TYPE !== 'cron' ) {
}

const path = require( 'path' );
const ROOT_PATH = process.cwd();
const { tools } = require( '@ckeditor/ckeditor5-dev-utils' );

const mainRepoUrl = 'https://github.com/CKEditor5/ckeditor5.github.io';
Expand Down Expand Up @@ -58,7 +59,7 @@ exec( 'rm -rf ckeditor5.github.io/docs/nightly/ckeditor5/latest' );
exec( `cp -R ckeditor5.github.io/docs/nightly/ckeditor5/${ projectVersion } ckeditor5.github.io/docs/nightly/ckeditor5/latest` );

// Change work directory in order to make a commit in CKEditor 5 page's repository.
process.chdir( path.join( process.cwd(), 'ckeditor5.github.io' ) );
process.chdir( path.join( ROOT_PATH, 'ckeditor5.github.io' ) );

exec( `echo "https://${ process.env.GITHUB_TOKEN }:@github.com" > .git/credentials 2> /dev/null` );
exec( 'git config credential.helper "store --file=.git/credentials"' );
Expand All @@ -75,6 +76,30 @@ if ( exec( 'git diff --name-only docs/' ).trim().length ) {
console.log( 'Nothing to commit. Documentation is up to date.' );
}

// Every 10th day of the month, we would like to clean the history of the documentation repository.
if ( new Date().getDate() === 10 ) {
// Copy a commit which will be a new root in the repository.
const commit = exec( 'git log --oneline --reverse -5 --format="%h" | head -n 1' ).trim();

// Checkout to the status of the git repo at commit. Create a temporary branch.
exec( `git checkout --orphan temp ${ commit }` );

// Create a new commit that is to be the new root commit.
exec( 'git commit -m "Documentation build."' );

// Rebase the part of history from <commit> to master on the temporary branch.
exec( `git rebase --onto temp ${ commit } master` );

// Remove the temporary branch.
exec( 'git branch -D temp' );

// Pray.
exec( 'git push -f' );
}

// Change work directory to the previous value.
process.chdir( ROOT_PATH );

function exec( command ) {
try {
return tools.shExec( command, { verbosity: 'error' } );
Expand Down

0 comments on commit 3719b14

Please sign in to comment.