Skip to content

Commit 7ff84ac

Browse files
committed
fix(buddy): link the current release workflow
1 parent 5fcf732 commit 7ff84ac

2 files changed

Lines changed: 41 additions & 3 deletions

File tree

storage/framework/core/buddy/src/commands/release.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import type { CLI, ReleaseOptions } from '@stacksjs/types'
2+
import { execFileSync } from 'node:child_process'
23
import process from 'node:process'
34
import { runAction } from '@stacksjs/actions'
4-
import { intro, italic, log, onUnknownSubcommand, outro } from "@stacksjs/cli"
5+
import { intro, italic, log, onUnknownSubcommand, outro } from '@stacksjs/cli'
56
import { Action } from '@stacksjs/enums'
67
import { ExitCode } from '@stacksjs/types'
78

@@ -39,8 +40,26 @@ export function release(buddy: CLI): void {
3940
useSeconds: true,
4041
})
4142

42-
log.info(`Follow along: ${italic('https://github.com/stacksjs/stacks/actions')}`)
43+
log.info(`Follow along: ${italic(resolveGitHubActionsUrl(readOriginRemote()))}`)
4344
})
4445

45-
onUnknownSubcommand(buddy, "release")
46+
onUnknownSubcommand(buddy, 'release')
47+
}
48+
49+
export function resolveGitHubActionsUrl(
50+
remoteUrl?: string,
51+
repository = process.env.GITHUB_REPOSITORY,
52+
serverUrl = process.env.GITHUB_SERVER_URL ?? 'https://github.com',
53+
): string {
54+
const repo = repository?.trim() || remoteUrl?.trim().match(/github\.com[/:]([^/\s]+\/[^/\s]+?)(?:\.git)?$/)?.[1]
55+
return repo ? `${serverUrl.replace(/\/$/, '')}/${repo}/actions` : 'https://github.com/stacksjs/stacks/actions'
56+
}
57+
58+
function readOriginRemote(): string | undefined {
59+
try {
60+
return execFileSync('git', ['config', '--get', 'remote.origin.url'], { encoding: 'utf8' }).trim()
61+
}
62+
catch {
63+
return undefined
64+
}
4665
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { describe, expect, it } from 'bun:test'
2+
import { resolveGitHubActionsUrl } from '../src/commands/release'
3+
4+
describe('release workflow URL', () => {
5+
it('uses the current HTTPS GitHub remote', () => {
6+
expect(resolveGitHubActionsUrl('https://github.com/chrisbbreuer/very-good-adblock.git', '', 'https://github.com'))
7+
.toBe('https://github.com/chrisbbreuer/very-good-adblock/actions')
8+
})
9+
10+
it('uses the current SSH GitHub remote', () => {
11+
expect(resolveGitHubActionsUrl('git@github.com:stacksjs/stacks.git', '', 'https://github.com'))
12+
.toBe('https://github.com/stacksjs/stacks/actions')
13+
})
14+
15+
it('prefers GitHub Actions repository metadata', () => {
16+
expect(resolveGitHubActionsUrl(undefined, 'owner/repo', 'https://github.example.com'))
17+
.toBe('https://github.example.com/owner/repo/actions')
18+
})
19+
})

0 commit comments

Comments
 (0)