|
12 | 12 | * |
13 | 13 | * Tag format: deploy-${environment}-${version}-${shortSha} |
14 | 14 | * - environment: from `network.environment` (e.g. mainnet, testnet) |
15 | | - * - version: from deploymentInfo["deploy:protocol"].version |
| 15 | + * - version: highest semver found across all contracts[*].version in the env file |
16 | 16 | * - shortSha: first 7 chars of the deployment gitCommit |
17 | 17 | * |
18 | 18 | * The tag points directly to the deployment commit SHA referenced in the env file, |
@@ -73,24 +73,28 @@ function extractTagInfo(filePath) { |
73 | 73 | return []; |
74 | 74 | } |
75 | 75 |
|
| 76 | + // Determine the version from the highest version found across all contracts |
| 77 | + const version = findHighestContractVersion(chain.contracts); |
| 78 | + |
76 | 79 | const results = []; |
77 | 80 |
|
78 | | - // Look for deploy:protocol.version |
| 81 | + // Look for deploy:protocol gitCommit |
79 | 82 | const protocolDeploy = deploymentInfo["deploy:protocol"]; |
80 | 83 | if (protocolDeploy?.gitCommit) { |
81 | 84 | results.push({ |
82 | 85 | environment, |
83 | | - version: protocolDeploy.version || null, |
| 86 | + version, |
84 | 87 | gitCommit: protocolDeploy.gitCommit, |
85 | 88 | }); |
86 | 89 | } |
87 | 90 |
|
88 | | - // Fallback: check any deploymentInfo entry for gitCommit |
89 | | - for (const value of Object.values(deploymentInfo)) { |
| 91 | + // Fallback: check any other deploymentInfo entry for gitCommit |
| 92 | + for (const [key, value] of Object.entries(deploymentInfo)) { |
| 93 | + if (key === "deploy:protocol") continue; |
90 | 94 | if (value?.gitCommit) { |
91 | 95 | results.push({ |
92 | 96 | environment, |
93 | | - version: value.version || null, |
| 97 | + version, |
94 | 98 | gitCommit: value.gitCommit, |
95 | 99 | }); |
96 | 100 | } |
@@ -119,6 +123,56 @@ function generateTimestamp() { |
119 | 123 | return `${year}${month}${day}-${hours}${minutes}${seconds}`; |
120 | 124 | } |
121 | 125 |
|
| 126 | +/** |
| 127 | + * Parses a version string into its numeric components. |
| 128 | + * Supports formats: "v3.1.0", "v3.1", "v3", "3.1.0", "3.1", "3" (optional 'v' prefix) |
| 129 | + * @param {string} versionStr - Version string to parse |
| 130 | + * @returns {{ major: number, minor: number, patch: number, original: string } | null} |
| 131 | + */ |
| 132 | +function parseVersion(versionStr) { |
| 133 | + if (!versionStr || typeof versionStr !== "string") return null; |
| 134 | + const cleaned = versionStr.replace(/^v/i, ""); |
| 135 | + const parts = cleaned.split(".").map((p) => parseInt(p, 10)); |
| 136 | + if (parts.length === 0 || parts.some(isNaN)) return null; |
| 137 | + return { |
| 138 | + major: parts[0] || 0, |
| 139 | + minor: parts[1] || 0, |
| 140 | + patch: parts[2] || 0, |
| 141 | + original: versionStr, |
| 142 | + }; |
| 143 | +} |
| 144 | + |
| 145 | +/** |
| 146 | + * Compares two parsed versions. Returns positive if a > b, negative if a < b, 0 if equal. |
| 147 | + * @param {{ major: number, minor: number, patch: number }} a |
| 148 | + * @param {{ major: number, minor: number, patch: number }} b |
| 149 | + * @returns {number} |
| 150 | + */ |
| 151 | +function compareVersions(a, b) { |
| 152 | + if (a.major !== b.major) return a.major - b.major; |
| 153 | + if (a.minor !== b.minor) return a.minor - b.minor; |
| 154 | + return a.patch - b.patch; |
| 155 | +} |
| 156 | + |
| 157 | +/** |
| 158 | + * Finds the highest version across all contracts in the env file. |
| 159 | + * @param {Object} contracts - The contracts object from the env JSON |
| 160 | + * @returns {string|null} The highest version string found, or null if none |
| 161 | + */ |
| 162 | +function findHighestContractVersion(contracts) { |
| 163 | + if (!contracts || typeof contracts !== "object") return null; |
| 164 | + let highest = null; |
| 165 | + for (const contract of Object.values(contracts)) { |
| 166 | + if (!contract?.version) continue; |
| 167 | + const parsed = parseVersion(contract.version); |
| 168 | + if (!parsed) continue; |
| 169 | + if (!highest || compareVersions(parsed, highest) > 0) { |
| 170 | + highest = parsed; |
| 171 | + } |
| 172 | + } |
| 173 | + return highest?.original || null; |
| 174 | +} |
| 175 | + |
122 | 176 | /** |
123 | 177 | * Sanitizes a version string for use in a git tag name |
124 | 178 | * @param {string} version - Version string (e.g., "v3.1", "test-v3.0.1") |
|
0 commit comments