| | |
| | import fs from 'fs/promises' |
| | import { promisify } from 'util' |
| | import { exec as execOrig } from 'child_process' |
| |
|
| | const exec = promisify(execOrig) |
| |
|
| | |
| | |
| | |
| | |
| | export async function getGitInfo() { |
| | let eventData = {} |
| |
|
| | try { |
| | eventData = |
| | JSON.parse( |
| | await fs.readFile(process.env.GITHUB_EVENT_PATH || '', 'utf8') |
| | )['pull_request'] || {} |
| | } catch (_) {} |
| |
|
| | const branchName = |
| | eventData?.head?.ref || |
| | process.env.GITHUB_REF_NAME || |
| | (await exec('git rev-parse --abbrev-ref HEAD')).stdout.trim() |
| |
|
| | const remoteUrl = |
| | eventData?.head?.repo?.full_name || |
| | process.env.GITHUB_REPOSITORY || |
| | (await exec('git remote get-url origin')).stdout.trim() |
| |
|
| | const commitSha = |
| | eventData?.head?.sha || |
| | process.env.GITHUB_SHA || |
| | (await exec('git rev-parse HEAD')).stdout.trim() |
| |
|
| | const isCanary = |
| | branchName === 'canary' && remoteUrl.includes('vercel/next.js') |
| |
|
| | return { branchName, remoteUrl, commitSha, isCanary } |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | export async function getDiffRevision() { |
| | if ( |
| | process.env.GITHUB_ACTIONS === 'true' && |
| | process.env.GITHUB_EVENT_NAME === 'pull_request' |
| | ) { |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | return 'HEAD~1' |
| | } else { |
| | try { |
| | await exec('git remote set-branches --add origin canary') |
| | await exec('git fetch origin canary --depth=20') |
| | } catch (err) { |
| | const remoteInfo = await exec('git remote -v') |
| | console.error(remoteInfo.stdout) |
| | console.error(remoteInfo.stderr) |
| | console.error(`Failed to fetch origin/canary`, err) |
| | } |
| | |
| | |
| | |
| | |
| | |
| | |
| | return 'origin/canary' |
| | } |
| | } |
| |
|