Skip to content

Commit 5b97809

Browse files
chore: wip
1 parent 9d28fec commit 5b97809

File tree

2 files changed

+94
-48
lines changed

2 files changed

+94
-48
lines changed

src/utils/github-actions-parser.ts

Lines changed: 52 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -221,21 +221,28 @@ export async function fetchLatestActionVersion(actionName: string): Promise<stri
221221
})
222222

223223
if (releasesResponse.ok) {
224-
const releases = await releasesResponse.json() as Array<{ tag_name?: string, published_at?: string }>
225-
console.log(`📋 Found ${releases.length} releases`)
226-
227-
// Filter out pre-releases and sort by published date
228-
const stableReleases = releases
229-
.filter(release => release.tag_name && !release.tag_name.includes('-'))
230-
.sort((a, b) => {
231-
const dateA = a.published_at ? new Date(a.published_at).getTime() : 0
232-
const dateB = b.published_at ? new Date(b.published_at).getTime() : 0
233-
return dateB - dateA // Sort descending (newest first)
234-
})
224+
const releases = await releasesResponse.json()
235225

236-
if (stableReleases.length > 0) {
237-
console.log(`✅ Found latest stable release: ${stableReleases[0].tag_name}`)
238-
return stableReleases[0].tag_name || null
226+
// Ensure we have an array
227+
if (!Array.isArray(releases)) {
228+
console.log(`⚠️ Unexpected releases response format (expected array)`)
229+
}
230+
else {
231+
console.log(`📋 Found ${releases.length} releases`)
232+
233+
// Filter out pre-releases and sort by published date
234+
const stableReleases = releases
235+
.filter((release: any) => release.tag_name && !release.tag_name.includes('-'))
236+
.sort((a: any, b: any) => {
237+
const dateA = a.published_at ? new Date(a.published_at).getTime() : 0
238+
const dateB = b.published_at ? new Date(b.published_at).getTime() : 0
239+
return dateB - dateA // Sort descending (newest first)
240+
})
241+
242+
if (stableReleases.length > 0) {
243+
console.log(`✅ Found latest stable release: ${stableReleases[0].tag_name}`)
244+
return stableReleases[0].tag_name || null
245+
}
239246
}
240247
}
241248
else {
@@ -249,35 +256,42 @@ export async function fetchLatestActionVersion(actionName: string): Promise<stri
249256
})
250257

251258
if (tagsResponse.ok) {
252-
const tags = await tagsResponse.json() as Array<{ name?: string }>
253-
console.log(`📋 Found ${tags.length} tags`)
254-
255-
// Filter out pre-releases and find the latest stable tag
256-
const stableTags = tags
257-
.filter(tag => tag.name && !tag.name.includes('-'))
258-
.map(tag => tag.name!)
259-
.sort((a, b) => {
260-
// Simple version comparison for tags
261-
// Remove 'v' prefix if present for proper number parsing
262-
const aClean = a.replace(/^v/, '')
263-
const bClean = b.replace(/^v/, '')
264-
265-
const aParts = aClean.split('.').map(Number)
266-
const bParts = bClean.split('.').map(Number)
267-
268-
for (let i = 0; i < Math.max(aParts.length, bParts.length); i++) {
269-
const aPart = aParts[i] || 0
270-
const bPart = bParts[i] || 0
271-
if (aPart !== bPart) {
272-
return bPart - aPart // Sort descending
259+
const tags = await tagsResponse.json()
260+
261+
// Ensure we have an array
262+
if (!Array.isArray(tags)) {
263+
console.log(`⚠️ Unexpected tags response format (expected array)`)
264+
}
265+
else {
266+
console.log(`📋 Found ${tags.length} tags`)
267+
268+
// Filter out pre-releases and find the latest stable tag
269+
const stableTags = tags
270+
.filter((tag: any) => tag.name && !tag.name.includes('-'))
271+
.map((tag: any) => tag.name!)
272+
.sort((a: string, b: string) => {
273+
// Simple version comparison for tags
274+
// Remove 'v' prefix if present for proper number parsing
275+
const aClean = a.replace(/^v/, '')
276+
const bClean = b.replace(/^v/, '')
277+
278+
const aParts = aClean.split('.').map(Number)
279+
const bParts = bClean.split('.').map(Number)
280+
281+
for (let i = 0; i < Math.max(aParts.length, bParts.length); i++) {
282+
const aPart = aParts[i] || 0
283+
const bPart = bParts[i] || 0
284+
if (aPart !== bPart) {
285+
return bPart - aPart // Sort descending
273286
}
274287
}
275288
return 0
276289
})
277290

278-
if (stableTags.length > 0) {
279-
console.log(`✅ Found latest stable tag: ${stableTags[0]}`)
280-
return stableTags[0]
291+
if (stableTags.length > 0) {
292+
console.log(`✅ Found latest stable tag: ${stableTags[0]}`)
293+
return stableTags[0]
294+
}
281295
}
282296
}
283297
else {

src/utils/zig-parser.ts

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,52 @@ export async function parseZigManifest(filePath: string, content: string): Promi
2323

2424
// Parse dependencies from the .dependencies block
2525
// Format: .dependencies = .{ .package_name = .{ .url = "...", .hash = "..." }, }
26-
const dependenciesMatch = content.match(/\.dependencies\s*=\s*\.?\{([^}]*)\}/)
26+
// We need to handle nested braces, so we'll use a more sophisticated approach
27+
const dependenciesStartMatch = content.match(/\.dependencies\s*=\s*\.?\{/)
2728

28-
if (dependenciesMatch) {
29-
const dependenciesBlock = dependenciesMatch[1]
29+
if (dependenciesStartMatch) {
30+
const startIndex = dependenciesStartMatch.index! + dependenciesStartMatch[0].length
3031

31-
// Match each dependency entry: .package_name = .{ .url = "...", ... }
32-
const depRegex = /\.(\w+)\s*=\s*\.?\{([^}]*)\}/g
33-
let match = depRegex.exec(dependenciesBlock)
32+
// Find the matching closing brace by counting brace depth
33+
let braceDepth = 1
34+
let endIndex = startIndex
3435

35-
while (match !== null) {
36+
while (endIndex < content.length && braceDepth > 0) {
37+
if (content[endIndex] === '{') {
38+
braceDepth++
39+
}
40+
else if (content[endIndex] === '}') {
41+
braceDepth--
42+
}
43+
endIndex++
44+
}
45+
46+
const dependenciesBlock = content.slice(startIndex, endIndex - 1)
47+
48+
// Match each dependency entry: .package_name = .{ ... }
49+
// We'll find each one individually by looking for the pattern and extracting the content
50+
const depPattern = /\.(\w+)\s*=\s*\.?\{/g
51+
let match
52+
53+
while ((match = depPattern.exec(dependenciesBlock)) !== null) {
3654
const packageName = match[1]
37-
const depContent = match[2]
55+
const depStartIndex = match.index + match[0].length
56+
57+
// Find the closing brace for this dependency
58+
let depBraceDepth = 1
59+
let depEndIndex = depStartIndex
60+
61+
while (depEndIndex < dependenciesBlock.length && depBraceDepth > 0) {
62+
if (dependenciesBlock[depEndIndex] === '{') {
63+
depBraceDepth++
64+
}
65+
else if (dependenciesBlock[depEndIndex] === '}') {
66+
depBraceDepth--
67+
}
68+
depEndIndex++
69+
}
70+
71+
const depContent = dependenciesBlock.slice(depStartIndex, depEndIndex - 1)
3872

3973
// Extract URL to get version information
4074
const urlMatch = depContent.match(/\.url\s*=\s*"([^"]+)"/)
@@ -59,8 +93,6 @@ export async function parseZigManifest(filePath: string, content: string): Promi
5993
metadata,
6094
})
6195
}
62-
63-
match = depRegex.exec(dependenciesBlock)
6496
}
6597
}
6698

0 commit comments

Comments
 (0)