Skip to content

Commit

Permalink
use exec listeners
Browse files Browse the repository at this point in the history
  • Loading branch information
baptiste0928 committed Mar 7, 2024
1 parent 3f4cc42 commit a574bfe
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions src/resolve/git.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import stream from 'node:stream'
import * as exec from '@actions/exec'
import * as core from '@actions/core'

Expand Down Expand Up @@ -48,21 +47,13 @@ export async function resolveGitCommit (git: GitSource): Promise<ResolvedVersion
}

async function fetchGitRemote (repository: string): Promise<GitRemoteCommits> {
const outStream = new stream.PassThrough()
await exec.exec('git', ['ls-remote', repository], { outStream })

const outChunks: Uint8Array[] = []
for await (const chunk of outStream) {
outChunks.push(Buffer.from(chunk))
}

const output = Buffer.concat(outChunks).toString('utf-8')
const commits: GitRemoteCommits = { head: '', tags: {}, branches: {} }
for (const line of output.split('\n')) {

const parseLine = (line: string): void => {
const [commit, ref] = line.split('\t')

if (commit === '' || ref === '' || ref === undefined) {
continue
return
}

if (ref === 'HEAD') {
Expand All @@ -82,6 +73,8 @@ async function fetchGitRemote (repository: string): Promise<GitRemoteCommits> {
}
}

await exec.exec('git', ['ls-remote', repository], { listeners: { stdline: parseLine }, silent: true })

if (commits.head === '') {
core.setFailed(`Failed to fetch HEAD commit for ${repository}`)
process.exit(1)
Expand Down

0 comments on commit a574bfe

Please sign in to comment.