mirror of
https://github.com/dorny/paths-filter.git
synced 2025-06-08 00:59:04 +00:00
Improve change detection for feature branches (#16)
* Detect changes against configured base branch * Update README and action.yml * Add job.outputs example * Update CHANGELOG
This commit is contained in:
parent
7d201829e2
commit
83deb9f037
8 changed files with 202 additions and 35 deletions
30
src/git.ts
30
src/git.ts
|
@ -1,15 +1,18 @@
|
|||
import {exec} from '@actions/exec'
|
||||
|
||||
export async function fetchCommit(sha: string): Promise<void> {
|
||||
const exitCode = await exec('git', ['fetch', '--depth=1', 'origin', sha])
|
||||
export const NULL_SHA = '0000000000000000000000000000000000000000'
|
||||
export const FETCH_HEAD = 'FETCH_HEAD'
|
||||
|
||||
export async function fetchCommit(ref: string): Promise<void> {
|
||||
const exitCode = await exec('git', ['fetch', '--depth=1', '--no-tags', 'origin', ref])
|
||||
if (exitCode !== 0) {
|
||||
throw new Error(`Fetching commit ${sha} failed`)
|
||||
throw new Error(`Fetching ${ref} failed`)
|
||||
}
|
||||
}
|
||||
|
||||
export async function getChangedFiles(sha: string): Promise<string[]> {
|
||||
export async function getChangedFiles(ref: string): Promise<string[]> {
|
||||
let output = ''
|
||||
const exitCode = await exec('git', ['diff-index', '--name-only', sha], {
|
||||
const exitCode = await exec('git', ['diff-index', '--name-only', ref], {
|
||||
listeners: {
|
||||
stdout: (data: Buffer) => (output += data.toString())
|
||||
}
|
||||
|
@ -24,3 +27,20 @@ export async function getChangedFiles(sha: string): Promise<string[]> {
|
|||
.map(s => s.trim())
|
||||
.filter(s => s.length > 0)
|
||||
}
|
||||
|
||||
export function isTagRef(ref: string): boolean {
|
||||
return ref.startsWith('refs/tags/')
|
||||
}
|
||||
|
||||
export function trimRefs(ref: string): string {
|
||||
return trimStart(ref, 'refs/')
|
||||
}
|
||||
|
||||
export function trimRefsHeads(ref: string): string {
|
||||
const trimRef = trimStart(ref, 'refs/')
|
||||
return trimStart(trimRef, 'heads/')
|
||||
}
|
||||
|
||||
function trimStart(ref: string, start: string): string {
|
||||
return ref.startsWith(start) ? ref.substr(start.length) : ref
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue