mirror of
https://github.com/dorny/paths-filter.git
synced 2026-06-27 16:07:41 +00:00
Compare commits
5 Commits
56002fecf0
...
7efdf018c8
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7efdf018c8 | ||
|
|
f3ceefdc7e | ||
|
|
61f87a10cd | ||
|
|
4c5aaae1a5 | ||
|
|
7b47280cac |
@ -50,6 +50,10 @@ inputs:
|
||||
required: false
|
||||
default: 'some'
|
||||
outputs:
|
||||
all_changed:
|
||||
description: Boolean value indicating if all of the filters contained at least one changed file
|
||||
any_changed:
|
||||
description: Boolean value indicating if any of the filters contained at least one changed file
|
||||
changes:
|
||||
description: JSON array with names of all filters matching any of changed files
|
||||
runs:
|
||||
|
||||
14
dist/index.js
vendored
14
dist/index.js
vendored
@ -363,8 +363,8 @@ exports.listAllFilesAsAdded = listAllFilesAsAdded;
|
||||
async function getCurrentRef() {
|
||||
core.startGroup(`Get current git ref`);
|
||||
try {
|
||||
const branch = (await (0, exec_1.getExecOutput)('git', ['branch', '--show-current'])).stdout.trim();
|
||||
if (branch) {
|
||||
const branch = (await (0, exec_1.getExecOutput)('git', ['rev-parse', '--abbrev-ref', 'HEAD'])).stdout.trim();
|
||||
if (branch && branch !== 'HEAD') {
|
||||
return branch;
|
||||
}
|
||||
const describe = await (0, exec_1.getExecOutput)('git', ['describe', '--tags', '--exact-match'], { ignoreReturnCode: true });
|
||||
@ -640,7 +640,7 @@ async function getChangedFiles(token, base, ref, initialFetchDepth) {
|
||||
// At the same time we don't want to fetch any code from forked repository
|
||||
throw new Error(`'token' input parameter is required if action is triggered by 'pull_request_target' event`);
|
||||
}
|
||||
core.info('Github token is not available - changes will be detected using git diff');
|
||||
core.info('GitHub token is not available - changes will be detected using git diff');
|
||||
const baseSha = (_a = github.context.payload.pull_request) === null || _a === void 0 ? void 0 : _a.base.sha;
|
||||
const defaultBranch = (_b = github.context.payload.repository) === null || _b === void 0 ? void 0 : _b.default_branch;
|
||||
const currentRef = await git.getCurrentRef();
|
||||
@ -710,7 +710,7 @@ async function getChangedFilesFromGit(base, head, initialFetchDepth) {
|
||||
}
|
||||
// Uses github REST api to get list of files changed in PR
|
||||
async function getChangedFilesFromApi(token, pullRequest) {
|
||||
core.startGroup(`Fetching list of changed files for PR#${pullRequest.number} from Github API`);
|
||||
core.startGroup(`Fetching list of changed files for PR#${pullRequest.number} from GitHub API`);
|
||||
try {
|
||||
const client = github.getOctokit(token);
|
||||
const per_page = 100;
|
||||
@ -761,11 +761,14 @@ async function getChangedFilesFromApi(token, pullRequest) {
|
||||
function exportResults(results, format) {
|
||||
core.info('Results:');
|
||||
const changes = [];
|
||||
let anyChanged = false;
|
||||
let allChanged = true;
|
||||
for (const [key, files] of Object.entries(results)) {
|
||||
const value = files.length > 0;
|
||||
core.startGroup(`Filter ${key} = ${value}`);
|
||||
if (files.length > 0) {
|
||||
changes.push(key);
|
||||
anyChanged = true;
|
||||
core.info('Matching files:');
|
||||
for (const file of files) {
|
||||
core.info(`${file.filename} [${file.status}]`);
|
||||
@ -773,6 +776,7 @@ function exportResults(results, format) {
|
||||
}
|
||||
else {
|
||||
core.info('Matching files: none');
|
||||
allChanged = false;
|
||||
}
|
||||
core.setOutput(key, value);
|
||||
core.setOutput(`${key}_count`, files.length);
|
||||
@ -780,6 +784,8 @@ function exportResults(results, format) {
|
||||
const filesValue = serializeExport(files, format);
|
||||
core.setOutput(`${key}_files`, filesValue);
|
||||
}
|
||||
core.setOutput('all_changed', allChanged);
|
||||
core.setOutput('any_changed', anyChanged);
|
||||
core.endGroup();
|
||||
}
|
||||
if (results['changes'] === undefined) {
|
||||
|
||||
@ -166,8 +166,8 @@ export async function listAllFilesAsAdded(): Promise<File[]> {
|
||||
export async function getCurrentRef(): Promise<string> {
|
||||
core.startGroup(`Get current git ref`)
|
||||
try {
|
||||
const branch = (await getExecOutput('git', ['branch', '--show-current'])).stdout.trim()
|
||||
if (branch) {
|
||||
const branch = (await getExecOutput('git', ['rev-parse', '--abbrev-ref', 'HEAD'])).stdout.trim()
|
||||
if (branch && branch !== 'HEAD') {
|
||||
return branch
|
||||
}
|
||||
|
||||
|
||||
10
src/main.ts
10
src/main.ts
@ -107,7 +107,7 @@ async function getChangedFiles(token: string, base: string, ref: string, initial
|
||||
// At the same time we don't want to fetch any code from forked repository
|
||||
throw new Error(`'token' input parameter is required if action is triggered by 'pull_request_target' event`)
|
||||
}
|
||||
core.info('Github token is not available - changes will be detected using git diff')
|
||||
core.info('GitHub token is not available - changes will be detected using git diff')
|
||||
const baseSha = github.context.payload.pull_request?.base.sha
|
||||
const defaultBranch = github.context.payload.repository?.default_branch
|
||||
const currentRef = await git.getCurrentRef()
|
||||
@ -194,7 +194,7 @@ async function getChangedFilesFromGit(base: string, head: string, initialFetchDe
|
||||
|
||||
// Uses github REST api to get list of files changed in PR
|
||||
async function getChangedFilesFromApi(token: string, pullRequest: PullRequest): Promise<File[]> {
|
||||
core.startGroup(`Fetching list of changed files for PR#${pullRequest.number} from Github API`)
|
||||
core.startGroup(`Fetching list of changed files for PR#${pullRequest.number} from GitHub API`)
|
||||
try {
|
||||
const client = github.getOctokit(token)
|
||||
const per_page = 100
|
||||
@ -249,17 +249,21 @@ async function getChangedFilesFromApi(token: string, pullRequest: PullRequest):
|
||||
function exportResults(results: FilterResults, format: ExportFormat): void {
|
||||
core.info('Results:')
|
||||
const changes = []
|
||||
let anyChanged = false
|
||||
let allChanged = true
|
||||
for (const [key, files] of Object.entries(results)) {
|
||||
const value = files.length > 0
|
||||
core.startGroup(`Filter ${key} = ${value}`)
|
||||
if (files.length > 0) {
|
||||
changes.push(key)
|
||||
anyChanged = true
|
||||
core.info('Matching files:')
|
||||
for (const file of files) {
|
||||
core.info(`${file.filename} [${file.status}]`)
|
||||
}
|
||||
} else {
|
||||
core.info('Matching files: none')
|
||||
allChanged = false
|
||||
}
|
||||
|
||||
core.setOutput(key, value)
|
||||
@ -268,6 +272,8 @@ function exportResults(results: FilterResults, format: ExportFormat): void {
|
||||
const filesValue = serializeExport(files, format)
|
||||
core.setOutput(`${key}_files`, filesValue)
|
||||
}
|
||||
core.setOutput('all_changed', allChanged)
|
||||
core.setOutput('any_changed', anyChanged)
|
||||
core.endGroup()
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user