|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright 2022 Google LLC |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +const https = require('https'); |
| 19 | + |
| 20 | +const MAX_ATTEMPTS = 10; |
| 21 | +const MINUTE = 60 * 1000; |
| 22 | +const RETRY_DELAY_MINUTES = 15; |
| 23 | + |
| 24 | +async function pollReleaseNotes() { |
| 25 | + if (!process.env.VERSION) { |
| 26 | + console.log(`Couldn't find version.`); |
| 27 | + return; |
| 28 | + } |
| 29 | + |
| 30 | + const version = process.env.VERSION; |
| 31 | + |
| 32 | + const options = { |
| 33 | + method: 'GET' |
| 34 | + }; |
| 35 | + |
| 36 | + const getData = () => |
| 37 | + new Promise((resolve, reject) => { |
| 38 | + const req = https.request( |
| 39 | + `https://firebase.google.com/support/release-notes/js`, |
| 40 | + options, |
| 41 | + res => { |
| 42 | + let content = ''; |
| 43 | + res.on('data', d => (content += d)); |
| 44 | + res.on('end', () => resolve(content)); |
| 45 | + } |
| 46 | + ); |
| 47 | + |
| 48 | + req.on('error', error => reject(error)); |
| 49 | + req.end(); |
| 50 | + }); |
| 51 | + let siteContent = ''; |
| 52 | + for (let i = 0; i < MAX_ATTEMPTS; i++) { |
| 53 | + siteContent = await getData(); |
| 54 | + const matches = siteContent.match(/<a name="\d+\.\d+.\d+">/g); |
| 55 | + if (matches[0] === version) { |
| 56 | + return; |
| 57 | + } |
| 58 | + if (matches.includes(`<a name="${version}">`) && !process.env.FORCE) { |
| 59 | + console.warn( |
| 60 | + `${version} was found but is not the latest version. ` + |
| 61 | + `Set the force option to true to publish anyway.` |
| 62 | + ); |
| 63 | + process.exit(1); |
| 64 | + } |
| 65 | + console.log(`Didn't find ${version} on release notes page.`); |
| 66 | + if (i < MAX_ATTEMPTS - 1) { |
| 67 | + console.log(`Trying again in ${RETRY_DELAY_MINUTES} minutes.`); |
| 68 | + await new Promise(resolve => |
| 69 | + setTimeout(resolve, RETRY_DELAY_MINUTES * MINUTE) |
| 70 | + ); |
| 71 | + } |
| 72 | + } |
| 73 | + console.log(`Was not able to find ${version}. Ending process.`); |
| 74 | + process.exit(1); |
| 75 | +} |
| 76 | + |
| 77 | +pollReleaseNotes(); |
0 commit comments