|
| 1 | +// Example script to test the pollForAirgapReleaseStatus function |
| 2 | +// Usage: node poll-for-airgap-build.js <appId> <channelId> <releaseSequence> <expectedStatus> |
| 3 | + |
| 4 | +import { VendorPortalApi } from "../dist/configuration"; |
| 5 | +import { pollForAirgapReleaseStatus } from "../dist/releases"; |
| 6 | +import * as readline from 'readline'; |
| 7 | + |
| 8 | +// Function to get input from the user |
| 9 | +async function getUserInput(prompt: string): Promise<string> { |
| 10 | + const rl = readline.createInterface({ |
| 11 | + input: process.stdin, |
| 12 | + output: process.stdout |
| 13 | + }); |
| 14 | + |
| 15 | + return new Promise((resolve) => { |
| 16 | + rl.question(prompt, (answer) => { |
| 17 | + rl.close(); |
| 18 | + resolve(answer); |
| 19 | + }); |
| 20 | + }); |
| 21 | +} |
| 22 | + |
| 23 | +async function main() { |
| 24 | + try { |
| 25 | + // Initialize the API client |
| 26 | + const api = new VendorPortalApi(); |
| 27 | + |
| 28 | + // Get API token from environment variable |
| 29 | + api.apiToken = process.env.REPLICATED_API_TOKEN || ""; |
| 30 | + |
| 31 | + if (!api.apiToken) { |
| 32 | + throw new Error("REPLICATED_API_TOKEN environment variable is not set"); |
| 33 | + } |
| 34 | + |
| 35 | + // Get parameters from command line arguments or prompt for them |
| 36 | + let appId = process.argv[2]; |
| 37 | + let channelId = process.argv[3]; |
| 38 | + let releaseSequence = process.argv[4] ? parseInt(process.argv[4]) : undefined; |
| 39 | + let expectedStatus = process.argv[5]; |
| 40 | + |
| 41 | + // If any parameters are missing, prompt for them |
| 42 | + if (!appId) { |
| 43 | + appId = await getUserInput("Enter Application ID: "); |
| 44 | + } |
| 45 | + |
| 46 | + if (!channelId) { |
| 47 | + channelId = await getUserInput("Enter Channel ID: "); |
| 48 | + } |
| 49 | + |
| 50 | + if (!releaseSequence) { |
| 51 | + const sequenceStr = await getUserInput("Enter Release Sequence: "); |
| 52 | + releaseSequence = parseInt(sequenceStr); |
| 53 | + } |
| 54 | + |
| 55 | + if (!expectedStatus) { |
| 56 | + expectedStatus = await getUserInput("Enter Expected Status (e.g., 'built', 'warn', 'metadata'): "); |
| 57 | + } |
| 58 | + |
| 59 | + // Validate inputs |
| 60 | + if (isNaN(releaseSequence)) { |
| 61 | + throw new Error("Release Sequence must be a number"); |
| 62 | + } |
| 63 | + |
| 64 | + console.log(`\nPolling for airgap release status with the following parameters:`); |
| 65 | + console.log(`- Application ID: ${appId}`); |
| 66 | + console.log(`- Channel ID: ${channelId}`); |
| 67 | + console.log(`- Release Sequence: ${releaseSequence}`); |
| 68 | + console.log(`- Expected Status: ${expectedStatus}`); |
| 69 | + console.log(`\nThis will poll until the release reaches the expected status or times out.`); |
| 70 | + |
| 71 | + console.log("\nStarting to poll for airgap release status..."); |
| 72 | + |
| 73 | + const status = await pollForAirgapReleaseStatus( |
| 74 | + api, |
| 75 | + appId, |
| 76 | + channelId, |
| 77 | + releaseSequence, |
| 78 | + expectedStatus, |
| 79 | + 60, // 1 minute timeout |
| 80 | + 1000 // 1 second polling interval |
| 81 | + ); |
| 82 | + |
| 83 | + console.log(`\nSuccess! Release ${releaseSequence} has reached status: ${status}`); |
| 84 | + } catch (error) { |
| 85 | + console.error(`\nError: ${error.message}`); |
| 86 | + process.exit(1); |
| 87 | + } |
| 88 | +} |
| 89 | + |
| 90 | +// Run the main function |
| 91 | +main(); |
0 commit comments