summaryrefslogtreecommitdiffstats
path: root/remote/test/puppeteer/packages/browsers/tools/updateVersions.mjs
blob: 9fb704baf5c4a4ce619a6c8c83526347788b73a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/**
 * @license
 * Copyright 2023 Google Inc.
 * SPDX-License-Identifier: Apache-2.0
 */

import fs from 'node:fs/promises';

import actions from '@actions/core';

import {testFirefoxBuildId} from '../test/build/versions.js';

const filePath = './test/src/versions.ts';

const getVersion = async () => {
  // https://stackoverflow.com/a/1732454/96656
  const response = await fetch(
    'https://archive.mozilla.org/pub/firefox/nightly/latest-mozilla-central/'
  );
  const html = await response.text();
  const re = /firefox-(.*)\.en-US\.langpack\.xpi">/;
  const match = re.exec(html)[1];
  return match;
};

const patch = (input, version) => {
  const output = input.replace(/testFirefoxBuildId = '([^']+)';/, match => {
    return `testFirefoxBuildId = '${version}';`;
  });
  return output;
};

const version = await getVersion();

if (testFirefoxBuildId !== version) {
  actions.setOutput(
    'commit',
    `chore: update Firefox testing pin to ${version}`
  );
  const contents = await fs.readFile(filePath, 'utf8');
  const patched = patch(contents, version);
  fs.writeFile(filePath, patched);
}