* Generates the AMP version number. * * Version numbers are determined using the following algorithm: * - Count the number ( ) of cherry-picked commits on this branch, including * commits not on the main branch . If this branch only contains new commits * that are not cherry-picked, then
(ref = 'HEAD')
| 64 | * @return {string} AMP version number (always 13 digits long) |
| 65 | */ |
| 66 | function getVersion(ref = 'HEAD') { |
| 67 | if (argv.version_override) { |
| 68 | const version = String(argv.version_override); |
| 69 | if (!/^\d{13}$/.test(version)) { |
| 70 | throw new Error('--version_override only accepts a 13-digit version'); |
| 71 | } |
| 72 | return version; |
| 73 | } |
| 74 | |
| 75 | const numberOfCherryPicks = gitCherryMain(ref).length; |
| 76 | if (numberOfCherryPicks > 999) { |
| 77 | throw new Error( |
| 78 | `This branch has ${numberOfCherryPicks} cherry-picks, which is more ` + |
| 79 | 'than 999, the maximum allowed number of cherry-picks! Please make ' + |
| 80 | 'sure your local main branch is up to date.' |
| 81 | ); |
| 82 | } |
| 83 | |
| 84 | const lastCommitFormattedTime = gitCommitFormattedTime( |
| 85 | `${ref}~${numberOfCherryPicks}` |
| 86 | ).slice(0, -2); |
| 87 | |
| 88 | const numberOfCherryPicksStr = String(numberOfCherryPicks).padStart(3, '0'); |
| 89 | return `${lastCommitFormattedTime}${numberOfCherryPicksStr}`; |
| 90 | } |
| 91 | |
| 92 | // Used to e.g. references the ads binary from the runtime to get version lock. |
| 93 | const VERSION = getVersion(); |
no test coverage detected