Bladeren bron

Merge pull request #1448 from ckeditor/t/1392

Internal: Introduced a script which cleans up the repository that contains the project's documentation. Closes #1392.
Piotrek Koszuliński 7 jaren geleden
bovenliggende
commit
3719b14556
1 gewijzigde bestanden met toevoegingen van 26 en 1 verwijderingen
  1. 26 1
      scripts/docs/build-and-publish-nightly.js

+ 26 - 1
scripts/docs/build-and-publish-nightly.js

@@ -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';
@@ -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"' );
@@ -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' } );