Skip to content

Commit ddc3192

Browse files
authored
Set e2e test workflow to poll npm to check the version is available (#8684)
1 parent 32bf021 commit ddc3192

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

.github/workflows/e2e-test.yml

+6
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ jobs:
5050
TEST_ACCOUNT: ${{ secrets.TEST_ACCOUNT }}
5151
run: |
5252
echo "export const config = $PROJECT_CONFIG; export const testAccount = $TEST_ACCOUNT" > firebase-config.js
53+
- name: Poll npm until version to test is available for install
54+
run: |
55+
echo "Polling npm for firebase@${{ github.event.client_payload.versionOrTag }}"
56+
node ../scripts/release/poll-npm-publish.js
57+
env:
58+
VERSION: ${{ github.event.client_payload.versionOrTag }}
5359
- name: Yarn install
5460
run: |
5561
echo "Installing firebase@${{ github.event.client_payload.versionOrTag }}"

scripts/release/poll-npm-publish.js

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/**
2+
* @license
3+
* Copyright 2025 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 { exec } = require('child_process');
19+
20+
const MAX_ATTEMPTS = 15;
21+
const RETRY_DELAY_SECONDS = 60;
22+
23+
async function pollNpmPublish() {
24+
const version = process.env.VERSION;
25+
26+
if (!version) {
27+
console.log(`Couldn't find env var VERSION.`);
28+
return;
29+
}
30+
31+
const getNpmPublishedVersion = () =>
32+
new Promise((resolve, reject) => {
33+
exec(`npm view firebase@${version} version`, (error, stdout) => {
34+
if (error) {
35+
reject(error);
36+
}
37+
const version = stdout.trim();
38+
if (!version.match(/^\d+\.\d+\.\d+$/)) {
39+
reject(
40+
new Error(
41+
`npm view did not return a valid semver version. Received: ${version}`
42+
)
43+
);
44+
}
45+
resolve(version);
46+
});
47+
});
48+
for (let i = 0; i < MAX_ATTEMPTS; i++) {
49+
const latestPublishedVersion = await getNpmPublishedVersion();
50+
if (latestPublishedVersion === process.env.VERSION) {
51+
console.log(`Found firebase@${version} in the npm registry.`);
52+
return;
53+
}
54+
console.log(`Didn't find firebase@${version} in the npm registry.`);
55+
if (i < MAX_ATTEMPTS - 1) {
56+
console.log(`Trying again in ${RETRY_DELAY_SECONDS} seconds.`);
57+
await new Promise(resolve =>
58+
setTimeout(resolve, RETRY_DELAY_SECONDS * 1000)
59+
);
60+
}
61+
}
62+
console.log(
63+
`Was not able to find firebase@${version} on npm. Ending process.`
64+
);
65+
process.exit(1);
66+
}
67+
68+
pollNpmPublish();

0 commit comments

Comments
 (0)