1+ import { execSync } from 'node:child_process' ;
12import { Octokit } from 'octokit' ;
23import { createInterface } from 'node:readline' ;
34
@@ -62,52 +63,43 @@ async function main() {
6263 process . exit ( 1 ) ;
6364 }
6465
65- const octokit = new Octokit ( { auth : token } ) ;
66- const owner = 'mcowger' ;
67- const repo = 'plexus' ;
68-
69- // 1. Get current version tags via GitHub API
70- let currentTag : CalVerTag | null = null ;
71- try {
72- const { data : tags } = await octokit . request ( 'GET /repos/{owner}/{repo}/tags' , {
73- owner,
74- repo,
75- per_page : 100 ,
76- } ) ;
66+ // 1. Get local tags using git
67+ const tagOutput = execSync ( 'git tag' , { encoding : 'utf-8' } ) ;
68+ const allTags = tagOutput
69+ . split ( '\n' )
70+ . map ( ( t ) => t . trim ( ) )
71+ . filter ( Boolean ) ;
72+
73+ const calverTags = allTags . map ( ( t ) => parseCalVer ( t ) ) . filter ( ( t ) : t is CalVerTag => t !== null ) ;
74+
75+ // Sort: newest date first, then highest counter
76+ calverTags . sort ( ( a , b ) => {
77+ const dateA = a . year * 10000 + a . month * 100 + a . day ;
78+ const dateB = b . year * 10000 + b . month * 100 + b . day ;
79+ if ( dateB !== dateA ) return dateB - dateA ;
80+ return b . counter - a . counter ;
81+ } ) ;
7782
78- const calverTags = tags
79- . map ( ( t ) => parseCalVer ( t . name ) )
80- . filter ( ( t ) : t is CalVerTag => t !== null ) ;
81-
82- if ( calverTags . length > 0 ) {
83- // Sort: newest date first, then highest counter
84- calverTags . sort ( ( a , b ) => {
85- const dateA = a . year * 10000 + a . month * 100 + a . day ;
86- const dateB = b . year * 10000 + b . month * 100 + b . day ;
87- if ( dateB !== dateA ) return dateB - dateA ;
88- return b . counter - a . counter ;
89- } ) ;
90- currentTag = calverTags [ 0 ] ! ;
91- }
92- } catch ( e ) {
93- console . log ( 'Could not fetch tags, starting fresh...\n' ) ;
94- }
83+ const currentTag = calverTags . length > 0 ? calverTags [ 0 ] ! : null ;
9584
9685 // Calculate next version
9786 const now = new Date ( ) ;
9887 const todayStr = `${ now . getFullYear ( ) } .${ String ( now . getMonth ( ) + 1 ) . padStart ( 2 , '0' ) } .${ String ( now . getDate ( ) ) . padStart ( 2 , '0' ) } ` ;
9988
10089 let nextVersion : string ;
10190
102- if ( currentTag ) {
103- const currentDateStr = `${ currentTag . year } .${ String ( currentTag . month ) . padStart ( 2 , '0' ) } .${ String ( currentTag . day ) . padStart ( 2 , '0' ) } ` ;
104- if ( currentDateStr === todayStr ) {
105- // Same day, increment counter
106- nextVersion = `${ todayStr } .${ currentTag . counter + 1 } ` ;
107- } else {
108- // New day, start at .1
109- nextVersion = `${ todayStr } .1` ;
110- }
91+ // Find all tags for today and get the highest counter
92+ const todayCalVerTags = calverTags . filter (
93+ ( t ) => t . year === now . getFullYear ( ) && t . month === now . getMonth ( ) + 1 && t . day === now . getDate ( )
94+ ) ;
95+
96+ if ( todayCalVerTags . length > 0 ) {
97+ // Same day, increment from highest counter
98+ const highestCounter = Math . max ( ...todayCalVerTags . map ( ( t ) => t . counter ) ) ;
99+ nextVersion = `${ todayStr } .${ highestCounter + 1 } ` ;
100+ } else if ( currentTag ) {
101+ // New day, start at .1
102+ nextVersion = `${ todayStr } .1` ;
111103 } else {
112104 // No tags yet
113105 nextVersion = `${ todayStr } .1` ;
@@ -123,6 +115,10 @@ async function main() {
123115 rl . close ( ) ;
124116
125117 // 3. GitHub API - create tag on main
118+ const octokit = new Octokit ( { auth : token } ) ;
119+ const owner = 'mcowger' ;
120+ const repo = 'plexus' ;
121+
126122 console . log ( '\n📦 Creating tag on remote main...' ) ;
127123 try {
128124 // Get the latest commit SHA on main
0 commit comments