Skip to content

Commit

Permalink
chore: fix puppeteer@next race condition (#3209)
Browse files Browse the repository at this point in the history
When we merge commits to master, Travis kicks job to build a new commit
and to publish new version of puppeteer@next.

If two commits are landed in almost the same time, then travis starts
two parallel jobs to build each commit. This race condition results
in the incorrect puppeteer@next revision.

This patch teaches apply_next_version.js to verify if current HEAD
is matching upstream HEAD. If it doesn't, the predeploy hook fails
which (hopefully) aborts deployment.

Fixes #2925.
  • Loading branch information
aslushnikov committed Sep 6, 2018
1 parent f230722 commit b7e922b
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion utils/apply_next_version.js
@@ -1,5 +1,20 @@
const path = require('path');
const fs = require('fs');
const child_process = require('child_process');

// Compare current HEAD to upstream master SHA.
// If they are not equal - refuse to publish since
// we're not tip-of-tree.
const upstream_sha = `git ls-remote https://github.com/GoogleChrome/puppeteer --tags master | cut -f1`;
const current_sha = `git rev-parse HEAD`;
const command = `if [[ $(${upstream_sha}) == $(${current_sha}) ]]; then echo "yes"; else echo "no"; fi`;
const output = child_process.execSync(command).toString('utf8');
if (output.trim() !== 'yes') {
console.log('REFUSING TO PUBLISH: this is not tip-of-tree!');
process.exit(1);
return;
}


const package = require('../package.json');
let version = package.version;
Expand All @@ -9,4 +24,4 @@ if (dashIndex !== -1)
version += '-next.' + Date.now();
console.log('Setting version to ' + version);
package.version = version;
fs.writeFileSync(path.join(__dirname, '..', 'package.json'), JSON.stringify(package, undefined, 2) + '\n');
fs.writeFileSync(path.join(__dirname, '..', 'package.json'), JSON.stringify(package, undefined, 2) + '\n');

0 comments on commit b7e922b

Please sign in to comment.