mirror of
				https://github.com/microsoft/playwright.git
				synced 2025-06-26 21:40:17 +00:00 
			
		
		
		
	 89007c8f3d
			
		
	
	
		89007c8f3d
		
			
		
	
	
	
	
		
			
			As of today, we have tooling in place that makes sure that our main README.md **roughly** represents the state of the last release: - browser versions and browser badges are those that we released last - links to our API point to the last-released API version This tooling, however, relies on the fact that every release is a sequence of two consecutive commits: - one commit that sets `package.json` version to a released version - the following that "bumps" version to `-post`. This release process is very unfortunate, because: - it made releasing from branch impossible - it required "freezing" commits to the master branch This patch removes all the tooling and transitions `README.md` to always represent tip-of-tree state. We will fully rely on `https://playwright.dev` to show versioned docs.
		
			
				
	
	
		
			135 lines
		
	
	
		
			4.6 KiB
		
	
	
	
		
			JavaScript
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			135 lines
		
	
	
		
			4.6 KiB
		
	
	
	
		
			JavaScript
		
	
	
		
			Executable File
		
	
	
	
	
| #!/usr/bin/env node
 | |
| /**
 | |
|  * Copyright 2017 Google Inc. All rights reserved.
 | |
|  *
 | |
|  * Licensed under the Apache License, Version 2.0 (the "License");
 | |
|  * you may not use this file except in compliance with the License.
 | |
|  * You may obtain a copy of the License at
 | |
|  *
 | |
|  *     http://www.apache.org/licenses/LICENSE-2.0
 | |
|  *
 | |
|  * Unless required by applicable law or agreed to in writing, software
 | |
|  * distributed under the License is distributed on an "AS IS" BASIS,
 | |
|  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | |
|  * See the License for the specific language governing permissions and
 | |
|  * limitations under the License.
 | |
|  */
 | |
| 
 | |
| const playwright = require('../../index.js');
 | |
| const path = require('path');
 | |
| const Source = require('./Source');
 | |
| 
 | |
| const {spawnSync} = require('child_process');
 | |
| 
 | |
| const os = require('os');
 | |
| 
 | |
| const PROJECT_DIR = path.join(__dirname, '..', '..');
 | |
| const VERSION = require(path.join(PROJECT_DIR, 'package.json')).version;
 | |
| 
 | |
| const RED_COLOR = '\x1b[31m';
 | |
| const YELLOW_COLOR = '\x1b[33m';
 | |
| const RESET_COLOR = '\x1b[0m';
 | |
| 
 | |
| run();
 | |
| 
 | |
| async function run() {
 | |
|   const startTime = Date.now();
 | |
| 
 | |
|   /** @type {!Array<!Message>} */
 | |
|   const messages = [];
 | |
|   let changedFiles = false;
 | |
| 
 | |
|   // Documentation checks.
 | |
|   {
 | |
|     const readme = await Source.readFile(path.join(PROJECT_DIR, 'README.md'));
 | |
|     const contributing = await Source.readFile(path.join(PROJECT_DIR, 'CONTRIBUTING.md'));
 | |
|     const api = await Source.readFile(path.join(PROJECT_DIR, 'docs', 'api.md'));
 | |
|     const troubleshooting = await Source.readFile(path.join(PROJECT_DIR, 'docs', 'troubleshooting.md'));
 | |
|     const mdSources = [readme, api, contributing, troubleshooting];
 | |
| 
 | |
|     const preprocessor = require('./preprocessor');
 | |
|     const browserVersions = await getBrowserVersions();
 | |
|     messages.push(...(await preprocessor.runCommands(mdSources, {
 | |
|       libversion: VERSION,
 | |
|       chromiumVersion: browserVersions.chromium,
 | |
|       firefoxVersion: browserVersions.firefox,
 | |
|     })));
 | |
|     messages.push(...preprocessor.ensureInternalLinksAreValid([api]));
 | |
| 
 | |
|     const browser = await playwright.chromium.launch();
 | |
|     const page = await browser.newPage();
 | |
|     const checkPublicAPI = require('./check_public_api');
 | |
|     const jsSources = await Source.readdir(path.join(PROJECT_DIR, 'src'));
 | |
|     messages.push(...await checkPublicAPI(page, mdSources, jsSources));
 | |
|     await browser.close();
 | |
| 
 | |
|     for (const source of mdSources) {
 | |
|       if (!source.hasUpdatedText())
 | |
|         continue;
 | |
|       await source.save();
 | |
|       changedFiles = true;
 | |
|     }
 | |
|   }
 | |
| 
 | |
|   // Report results.
 | |
|   const errors = messages.filter(message => message.type === 'error');
 | |
|   if (errors.length) {
 | |
|     console.log('DocLint Failures:');
 | |
|     for (let i = 0; i < errors.length; ++i) {
 | |
|       let error = errors[i].text;
 | |
|       error = error.split('\n').join('\n      ');
 | |
|       console.log(`  ${i + 1}) ${RED_COLOR}${error}${RESET_COLOR}`);
 | |
|     }
 | |
|   }
 | |
|   const warnings = messages.filter(message => message.type === 'warning');
 | |
|   if (warnings.length) {
 | |
|     console.log('DocLint Warnings:');
 | |
|     for (let i = 0; i < warnings.length; ++i) {
 | |
|       let warning = warnings[i].text;
 | |
|       warning = warning.split('\n').join('\n      ');
 | |
|       console.log(`  ${i + 1}) ${YELLOW_COLOR}${warning}${RESET_COLOR}`);
 | |
|     }
 | |
|   }
 | |
|   let clearExit = messages.length === 0;
 | |
|   if (changedFiles) {
 | |
|     if (clearExit)
 | |
|       console.log(`${YELLOW_COLOR}Some files were updated.${RESET_COLOR}`);
 | |
|     clearExit = false;
 | |
|   }
 | |
|   console.log(`${errors.length} failures, ${warnings.length} warnings.`);
 | |
|   const runningTime = Date.now() - startTime;
 | |
|   console.log(`DocLint Finished in ${runningTime / 1000} seconds`);
 | |
|   process.exit(clearExit ? 0 : 1);
 | |
| }
 | |
| 
 | |
| async function getBrowserVersions() {
 | |
|   const [chromium, firefox] = await Promise.all([
 | |
|     getChromeVersion(),
 | |
|     getFirefoxVersion(),
 | |
|   ])
 | |
|   return {
 | |
|     chromium,
 | |
|     firefox,
 | |
|   };
 | |
| }
 | |
| 
 | |
| async function getChromeVersion() {
 | |
|   if (os.platform() === 'win32' || os.platform() === 'cygwin') {
 | |
|     const browser = await playwright.chromium.launch();
 | |
|     const page = await browser.newPage();
 | |
|     const userAgent = await page.evaluate('navigator.userAgent');
 | |
|     const [type] = userAgent.split(' ').filter(str => str.includes('Chrome'));
 | |
|     await browser.close();
 | |
|     return type.split('/')[1];
 | |
|   }
 | |
|   const version = spawnSync(playwright.chromium.executablePath(), ['--version'], undefined).stdout.toString();
 | |
|   return version.trim().split(' ').pop();
 | |
| }
 | |
| 
 | |
| async function getFirefoxVersion() {
 | |
|   const isWin = os.platform() === 'win32' || os.platform() === 'cygwin';
 | |
|   const out = spawnSync(playwright.firefox.executablePath(), [isWin ? '/version' : '--version'], undefined);
 | |
|   const version = out.stdout.toString();
 | |
|   return version.trim().split(' ').pop();
 | |
| }
 |