|
| 1 | +#!/usr/bin/env node |
| 2 | + |
| 3 | +'use strict'; |
| 4 | + |
| 5 | +const {exec, spawn} = require('child-process-promise'); |
| 6 | +const {join} = require('path'); |
| 7 | +const {readFileSync} = require('fs'); |
| 8 | +const theme = require('./theme'); |
| 9 | +const {logPromise, printDiff} = require('./utils'); |
| 10 | + |
| 11 | +const cwd = join(__dirname, '..', '..'); |
| 12 | + |
| 13 | +const CIRCLE_CI_BUILD = 12707; |
| 14 | +const COMMIT = 'b3d1a81a9'; |
| 15 | +const VERSION = '1.2.3'; |
| 16 | + |
| 17 | +const run = async () => { |
| 18 | + const defaultOptions = { |
| 19 | + cwd, |
| 20 | + env: process.env, |
| 21 | + }; |
| 22 | + |
| 23 | + try { |
| 24 | + // Start with a known build/revision: |
| 25 | + // https://circleci.com/gh/facebook/react/12707 |
| 26 | + let promise = spawn( |
| 27 | + 'node', |
| 28 | + ['./scripts/release/prepare-canary.js', `--build=${CIRCLE_CI_BUILD}`], |
| 29 | + defaultOptions |
| 30 | + ); |
| 31 | + logPromise( |
| 32 | + promise, |
| 33 | + theme`Checking out canary build {version ${CIRCLE_CI_BUILD}}` |
| 34 | + ); |
| 35 | + await promise; |
| 36 | + |
| 37 | + // Upgrade the above build top a known React version. |
| 38 | + // Note that using the --local flag skips NPM checkout. |
| 39 | + // This isn't totally necessary but is useful if we want to test an unpublished canary. |
| 40 | + promise = spawn( |
| 41 | + 'node', |
| 42 | + [ |
| 43 | + './scripts/release/prepare-stable.js', |
| 44 | + `--version=0.0.0-${COMMIT}`, |
| 45 | + '--local', |
| 46 | + ], |
| 47 | + defaultOptions |
| 48 | + ); |
| 49 | + promise.childProcess.stdin.setEncoding('utf-8'); |
| 50 | + promise.childProcess.stdout.setEncoding('utf-8'); |
| 51 | + promise.childProcess.stdout.on('data', data => { |
| 52 | + if (data.includes('✓ Version for')) { |
| 53 | + // Update all packages to a stable version |
| 54 | + promise.childProcess.stdin.write(VERSION); |
| 55 | + } else if (data.includes('(y/N)')) { |
| 56 | + // Accept all of the confirmation prompts |
| 57 | + promise.childProcess.stdin.write('y'); |
| 58 | + } |
| 59 | + }); |
| 60 | + logPromise(promise, theme`Preparing stable release {version ${VERSION}}`); |
| 61 | + await promise; |
| 62 | + |
| 63 | + const beforeContents = readFileSync( |
| 64 | + 'scripts/release/test.snapshot', |
| 65 | + 'utf-8', |
| 66 | + {cwd} |
| 67 | + ); |
| 68 | + await exec('cp build/temp.diff scripts/release/test.snapshot'); |
| 69 | + const afterContents = readFileSync( |
| 70 | + 'scripts/release/test.snapshot', |
| 71 | + 'utf-8', |
| 72 | + {cwd} |
| 73 | + ); |
| 74 | + |
| 75 | + if (beforeContents === afterContents) { |
| 76 | + console.log(theme.header`Snapshot test passed.`); |
| 77 | + } else { |
| 78 | + printDiff('scripts/release/test.snapshot', beforeContents, afterContents); |
| 79 | + console.log(); |
| 80 | + console.error(theme.error('Snapshot test failed!')); |
| 81 | + console.log(); |
| 82 | + console.log( |
| 83 | + 'If this failure was expected, please update the contents of the snapshot file:' |
| 84 | + ); |
| 85 | + console.log( |
| 86 | + theme` {command git add} {path scripts/release/test.snapshot}` |
| 87 | + ); |
| 88 | + console.log( |
| 89 | + theme` {command git commit -m "Updating release script snapshot file."}` |
| 90 | + ); |
| 91 | + process.exit(1); |
| 92 | + } |
| 93 | + } catch (error) { |
| 94 | + console.error(theme.error(error)); |
| 95 | + process.exit(1); |
| 96 | + } |
| 97 | +}; |
| 98 | + |
| 99 | +run(); |
0 commit comments