Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make doc generation more robust #783

Merged
merged 2 commits into from
Jul 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions scripts/publish-website.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ if [ "$TRAVIS_PULL_REQUEST" = "false" ] && [ "$TRAVIS_BRANCH" = "master" ]; then

cd website
npm install
npm run gatherDocs
GIT_USER=$GIT_USER CURRENT_BRANCH=master npm run publish-gh-pages
else
echo 'Not deploying the website'
Expand Down
52 changes: 40 additions & 12 deletions website/gatherDocs.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,7 @@ function generateAndCopyDocusaurusVersion(tempDir, version) {
);
}

async function cleanUp(tempDir) {
console.log('Cleanup temporary clone');
await fs.remove(tempDir);
}

(async function() {
const versions = await getVersions();
await cleanupExistingVersions();

fs.writeFileSync('./versions.json', JSON.stringify(versions), 'utf8');
const tempDir = fs.mkdtempSync('detox-documentation-generation');
async function generateDocumentation(versions, tempDir) {
const repo = await git.Clone(REPO_URL, tempDir);

for (let version of versions) {
Expand All @@ -115,5 +105,43 @@ async function cleanUp(tempDir) {
repo.cleanup(tempDir);
console.log(`Done with ${version}\n\n`);
}
await cleanUp(tempDir);
}

async function generate(versions, currentAttempt = 1) {
const maxAttempts = 3;
let success;
const tempDir = fs.mkdtempSync('detox-documentation-generation');
try {
await generateDocumentation(versions, tempDir);
success = true;
} catch (e) {
console.log('Error while generating documentation', e);
success = false;
} finally {
await cleanUp(tempDir);
}

if (success) {
return;
}

if (currentAttempt < maxAttempts) {
await generate(versions, currentAttempt + 1);
} else {
console.error(`Generation failed ${maxAttempts} times, there seems to be a real problem, please file an issue`);
process.exit(1);
}
}

async function cleanUp(tempDir) {
console.log('Cleanup temporary clone');
await fs.remove(tempDir);
}

(async function() {
const versions = await getVersions();
await cleanupExistingVersions();
fs.writeFileSync('./versions.json', JSON.stringify(versions), 'utf8');

await generate(versions);
})();