|
| 1 | +#!/usr/bin/env node |
| 2 | + |
| 3 | +const fs = require("fs"); |
| 4 | +const path = require("path"); |
| 5 | + |
| 6 | +/** |
| 7 | + * Verifies that all expected binary assets are present in the GitHub release |
| 8 | + * for the version specified in package.json |
| 9 | + */ |
| 10 | +async function verifyReleaseAssets() { |
| 11 | + try { |
| 12 | + // Read version from package.json |
| 13 | + const packagePath = path.join(__dirname, "..", "package.json"); |
| 14 | + const packageJson = JSON.parse(fs.readFileSync(packagePath, "utf8")); |
| 15 | + const version = packageJson.version; |
| 16 | + |
| 17 | + console.log(`🔍 Verifying release assets for version ${version}...`); |
| 18 | + |
| 19 | + // GitHub API configuration |
| 20 | + const owner = "dyad-sh"; |
| 21 | + const repo = "dyad"; |
| 22 | + const token = process.env.GITHUB_TOKEN; |
| 23 | + |
| 24 | + if (!token) { |
| 25 | + throw new Error("GITHUB_TOKEN environment variable is required"); |
| 26 | + } |
| 27 | + |
| 28 | + // Fetch all releases (including drafts) |
| 29 | + const tagName = `v${version}`; |
| 30 | + |
| 31 | + console.log(`📡 Fetching all releases to find: ${tagName}`); |
| 32 | + |
| 33 | + const allReleasesUrl = `https://api.github.com/repos/${owner}/${repo}/releases`; |
| 34 | + const response = await fetch(allReleasesUrl, { |
| 35 | + headers: { |
| 36 | + Authorization: `token ${token}`, |
| 37 | + Accept: "application/vnd.github.v3+json", |
| 38 | + "User-Agent": "dyad-release-verifier", |
| 39 | + }, |
| 40 | + }); |
| 41 | + |
| 42 | + if (!response.ok) { |
| 43 | + throw new Error( |
| 44 | + `GitHub API error: ${response.status} ${response.statusText}`, |
| 45 | + ); |
| 46 | + } |
| 47 | + |
| 48 | + const allReleases = await response.json(); |
| 49 | + const release = allReleases.find((r) => r.tag_name === tagName); |
| 50 | + |
| 51 | + if (!release) { |
| 52 | + throw new Error( |
| 53 | + `Release ${tagName} not found in published releases or drafts. Make sure the release exists.`, |
| 54 | + ); |
| 55 | + } |
| 56 | + |
| 57 | + const assets = release.assets || []; |
| 58 | + |
| 59 | + console.log(`📦 Found ${assets.length} assets in release ${tagName}`); |
| 60 | + console.log(`📄 Release status: ${release.draft ? "DRAFT" : "PUBLISHED"}`); |
| 61 | + |
| 62 | + // Define expected assets |
| 63 | + const expectedAssets = [ |
| 64 | + `dyad-${version}-1.x86_64.rpm`, |
| 65 | + `dyad-${version}-full.nupkg`, |
| 66 | + `dyad-${version}.Setup.exe`, |
| 67 | + `dyad-darwin-arm64-${version}.zip`, |
| 68 | + `dyad-darwin-x64-${version}.zip`, |
| 69 | + `dyad_${version}_amd64.deb`, |
| 70 | + "RELEASES", |
| 71 | + ]; |
| 72 | + |
| 73 | + console.log("📋 Expected assets:"); |
| 74 | + expectedAssets.forEach((asset) => console.log(` - ${asset}`)); |
| 75 | + console.log(""); |
| 76 | + |
| 77 | + // Get actual asset names |
| 78 | + const actualAssets = assets.map((asset) => asset.name); |
| 79 | + |
| 80 | + console.log("📋 Actual assets:"); |
| 81 | + actualAssets.forEach((asset) => console.log(` - ${asset}`)); |
| 82 | + console.log(""); |
| 83 | + |
| 84 | + // Check for missing assets |
| 85 | + const missingAssets = expectedAssets.filter( |
| 86 | + (expected) => !actualAssets.includes(expected), |
| 87 | + ); |
| 88 | + |
| 89 | + if (missingAssets.length > 0) { |
| 90 | + console.error("❌ VERIFICATION FAILED!"); |
| 91 | + console.error("📭 Missing assets:"); |
| 92 | + missingAssets.forEach((asset) => console.error(` - ${asset}`)); |
| 93 | + console.error(""); |
| 94 | + console.error( |
| 95 | + "Please ensure all platforms have completed their builds and uploads.", |
| 96 | + ); |
| 97 | + process.exit(1); |
| 98 | + } |
| 99 | + |
| 100 | + // Check for unexpected assets (optional warning) |
| 101 | + const unexpectedAssets = actualAssets.filter( |
| 102 | + (actual) => !expectedAssets.includes(actual), |
| 103 | + ); |
| 104 | + |
| 105 | + if (unexpectedAssets.length > 0) { |
| 106 | + console.warn("⚠️ Unexpected assets found:"); |
| 107 | + unexpectedAssets.forEach((asset) => console.warn(` - ${asset}`)); |
| 108 | + console.warn(""); |
| 109 | + } |
| 110 | + |
| 111 | + console.log("✅ VERIFICATION PASSED!"); |
| 112 | + console.log( |
| 113 | + `🎉 All ${expectedAssets.length} expected assets are present in release ${tagName}`, |
| 114 | + ); |
| 115 | + console.log(""); |
| 116 | + console.log("📊 Release Summary:"); |
| 117 | + console.log(` Release: ${release.name || tagName}`); |
| 118 | + console.log(` Tag: ${release.tag_name}`); |
| 119 | + console.log(` Published: ${release.published_at}`); |
| 120 | + console.log(` URL: ${release.html_url}`); |
| 121 | + } catch (error) { |
| 122 | + console.error("❌ Error verifying release assets:", error.message); |
| 123 | + process.exit(1); |
| 124 | + } |
| 125 | +} |
| 126 | + |
| 127 | +// Run the verification |
| 128 | +verifyReleaseAssets(); |
0 commit comments