mirror of
https://github.com/tj-actions/changed-files
synced 2025-02-28 23:30:55 +00:00
chore: switch to use the github context (#1386)
Co-authored-by: GitHub Action <action@github.com>
This commit is contained in:
parent
e3ea6b7948
commit
ec0b6d0e4c
7 changed files with 114 additions and 189 deletions
128
dist/index.js
generated
vendored
128
dist/index.js
generated
vendored
|
@ -52,9 +52,9 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|||
exports.getChangedFilesFromGithubAPI = exports.getAllChangeTypeFiles = exports.getChangeTypeFiles = exports.getAllDiffFiles = exports.ChangeTypeEnum = exports.getRenamedFiles = void 0;
|
||||
const core = __importStar(__nccwpck_require__(2186));
|
||||
const github = __importStar(__nccwpck_require__(5438));
|
||||
const flatten_1 = __importDefault(__nccwpck_require__(2394));
|
||||
const path = __importStar(__nccwpck_require__(1017));
|
||||
const utils_1 = __nccwpck_require__(918);
|
||||
const flatten_1 = __importDefault(__nccwpck_require__(2394));
|
||||
const getRenamedFiles = ({ inputs, workingDirectory, hasSubmodule, diffResult, submodulePaths }) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
const renamedFiles = yield (0, utils_1.gitRenamedFiles)({
|
||||
cwd: workingDirectory,
|
||||
|
@ -213,8 +213,9 @@ const getAllChangeTypeFiles = ({ inputs, changedFiles }) => __awaiter(void 0, vo
|
|||
};
|
||||
});
|
||||
exports.getAllChangeTypeFiles = getAllChangeTypeFiles;
|
||||
const getChangedFilesFromGithubAPI = ({ inputs, env }) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
const getChangedFilesFromGithubAPI = ({ inputs }) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
var _a, e_1, _b, _c;
|
||||
var _d;
|
||||
const octokit = github.getOctokit(inputs.token, {
|
||||
baseUrl: inputs.apiUrl
|
||||
});
|
||||
|
@ -232,7 +233,7 @@ const getChangedFilesFromGithubAPI = ({ inputs, env }) => __awaiter(void 0, void
|
|||
const options = octokit.rest.pulls.listFiles.endpoint.merge({
|
||||
owner: github.context.repo.owner,
|
||||
repo: github.context.repo.repo,
|
||||
pull_number: env.GITHUB_EVENT_PULL_REQUEST_NUMBER,
|
||||
pull_number: (_d = github.context.payload.pull_request) === null || _d === void 0 ? void 0 : _d.number,
|
||||
per_page: 100
|
||||
});
|
||||
const paginatedResponse = yield octokit.paginate(options);
|
||||
|
@ -247,9 +248,9 @@ const getChangedFilesFromGithubAPI = ({ inputs, env }) => __awaiter(void 0, void
|
|||
unchanged: ChangeTypeEnum.Unmerged
|
||||
};
|
||||
try {
|
||||
for (var _d = true, paginatedResponse_1 = __asyncValues(paginatedResponse), paginatedResponse_1_1; paginatedResponse_1_1 = yield paginatedResponse_1.next(), _a = paginatedResponse_1_1.done, !_a; _d = true) {
|
||||
for (var _e = true, paginatedResponse_1 = __asyncValues(paginatedResponse), paginatedResponse_1_1; paginatedResponse_1_1 = yield paginatedResponse_1.next(), _a = paginatedResponse_1_1.done, !_a; _e = true) {
|
||||
_c = paginatedResponse_1_1.value;
|
||||
_d = false;
|
||||
_e = false;
|
||||
const item = _c;
|
||||
const changeType = statusMap[item.status] || ChangeTypeEnum.Unknown;
|
||||
if (changeType === ChangeTypeEnum.Renamed) {
|
||||
|
@ -269,7 +270,7 @@ const getChangedFilesFromGithubAPI = ({ inputs, env }) => __awaiter(void 0, void
|
|||
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
||||
finally {
|
||||
try {
|
||||
if (!_d && !_a && (_b = paginatedResponse_1.return)) yield _b.call(paginatedResponse_1);
|
||||
if (!_e && !_a && (_b = paginatedResponse_1.return)) yield _b.call(paginatedResponse_1);
|
||||
}
|
||||
finally { if (e_1) throw e_1.error; }
|
||||
}
|
||||
|
@ -344,7 +345,7 @@ const setChangedFilesOutput = ({ allDiffFiles, inputs, workingDirectory, diffRes
|
|||
changedFiles: allFilteredDiffFiles,
|
||||
changeTypes: [changedFiles_1.ChangeTypeEnum.Added]
|
||||
});
|
||||
core.debug(`Added files: ${addedFiles}`);
|
||||
core.debug(`Added files: ${JSON.stringify(addedFiles)}`);
|
||||
yield (0, utils_1.setOutput)({
|
||||
key: getOutputKey('added_files', outputPrefix),
|
||||
value: addedFiles.paths,
|
||||
|
@ -360,7 +361,7 @@ const setChangedFilesOutput = ({ allDiffFiles, inputs, workingDirectory, diffRes
|
|||
changedFiles: allFilteredDiffFiles,
|
||||
changeTypes: [changedFiles_1.ChangeTypeEnum.Copied]
|
||||
});
|
||||
core.debug(`Copied files: ${copiedFiles}`);
|
||||
core.debug(`Copied files: ${JSON.stringify(copiedFiles)}`);
|
||||
yield (0, utils_1.setOutput)({
|
||||
key: getOutputKey('copied_files', outputPrefix),
|
||||
value: copiedFiles.paths,
|
||||
|
@ -376,7 +377,7 @@ const setChangedFilesOutput = ({ allDiffFiles, inputs, workingDirectory, diffRes
|
|||
changedFiles: allFilteredDiffFiles,
|
||||
changeTypes: [changedFiles_1.ChangeTypeEnum.Modified]
|
||||
});
|
||||
core.debug(`Modified files: ${modifiedFiles}`);
|
||||
core.debug(`Modified files: ${JSON.stringify(modifiedFiles)}`);
|
||||
yield (0, utils_1.setOutput)({
|
||||
key: getOutputKey('modified_files', outputPrefix),
|
||||
value: modifiedFiles.paths,
|
||||
|
@ -392,7 +393,7 @@ const setChangedFilesOutput = ({ allDiffFiles, inputs, workingDirectory, diffRes
|
|||
changedFiles: allFilteredDiffFiles,
|
||||
changeTypes: [changedFiles_1.ChangeTypeEnum.Renamed]
|
||||
});
|
||||
core.debug(`Renamed files: ${renamedFiles}`);
|
||||
core.debug(`Renamed files: ${JSON.stringify(renamedFiles)}`);
|
||||
yield (0, utils_1.setOutput)({
|
||||
key: getOutputKey('renamed_files', outputPrefix),
|
||||
value: renamedFiles.paths,
|
||||
|
@ -408,7 +409,7 @@ const setChangedFilesOutput = ({ allDiffFiles, inputs, workingDirectory, diffRes
|
|||
changedFiles: allFilteredDiffFiles,
|
||||
changeTypes: [changedFiles_1.ChangeTypeEnum.TypeChanged]
|
||||
});
|
||||
core.debug(`Type changed files: ${typeChangedFiles}`);
|
||||
core.debug(`Type changed files: ${JSON.stringify(typeChangedFiles)}`);
|
||||
yield (0, utils_1.setOutput)({
|
||||
key: getOutputKey('type_changed_files', outputPrefix),
|
||||
value: typeChangedFiles.paths,
|
||||
|
@ -424,7 +425,7 @@ const setChangedFilesOutput = ({ allDiffFiles, inputs, workingDirectory, diffRes
|
|||
changedFiles: allFilteredDiffFiles,
|
||||
changeTypes: [changedFiles_1.ChangeTypeEnum.Unmerged]
|
||||
});
|
||||
core.debug(`Unmerged files: ${unmergedFiles}`);
|
||||
core.debug(`Unmerged files: ${JSON.stringify(unmergedFiles)}`);
|
||||
yield (0, utils_1.setOutput)({
|
||||
key: getOutputKey('unmerged_files', outputPrefix),
|
||||
value: unmergedFiles.paths,
|
||||
|
@ -440,7 +441,7 @@ const setChangedFilesOutput = ({ allDiffFiles, inputs, workingDirectory, diffRes
|
|||
changedFiles: allFilteredDiffFiles,
|
||||
changeTypes: [changedFiles_1.ChangeTypeEnum.Unknown]
|
||||
});
|
||||
core.debug(`Unknown files: ${unknownFiles}`);
|
||||
core.debug(`Unknown files: ${JSON.stringify(unknownFiles)}`);
|
||||
yield (0, utils_1.setOutput)({
|
||||
key: getOutputKey('unknown_files', outputPrefix),
|
||||
value: unknownFiles.paths,
|
||||
|
@ -455,7 +456,7 @@ const setChangedFilesOutput = ({ allDiffFiles, inputs, workingDirectory, diffRes
|
|||
inputs,
|
||||
changedFiles: allFilteredDiffFiles
|
||||
});
|
||||
core.debug(`All changed and modified files: ${allChangedAndModifiedFiles}`);
|
||||
core.debug(`All changed and modified files: ${JSON.stringify(allChangedAndModifiedFiles)}`);
|
||||
yield (0, utils_1.setOutput)({
|
||||
key: getOutputKey('all_changed_and_modified_files', outputPrefix),
|
||||
value: allChangedAndModifiedFiles.paths,
|
||||
|
@ -476,7 +477,7 @@ const setChangedFilesOutput = ({ allDiffFiles, inputs, workingDirectory, diffRes
|
|||
changedFiles_1.ChangeTypeEnum.Renamed
|
||||
]
|
||||
});
|
||||
core.debug(`All changed files: ${allChangedFiles}`);
|
||||
core.debug(`All changed files: ${JSON.stringify(allChangedFiles)}`);
|
||||
yield (0, utils_1.setOutput)({
|
||||
key: getOutputKey('all_changed_files', outputPrefix),
|
||||
value: allChangedFiles.paths,
|
||||
|
@ -502,7 +503,7 @@ const setChangedFilesOutput = ({ allDiffFiles, inputs, workingDirectory, diffRes
|
|||
changedFiles_1.ChangeTypeEnum.Renamed
|
||||
]
|
||||
});
|
||||
core.debug(`All other changed files: ${allOtherChangedFiles}`);
|
||||
core.debug(`All other changed files: ${JSON.stringify(allOtherChangedFiles)}`);
|
||||
const otherChangedFiles = allOtherChangedFiles.paths
|
||||
.split(inputs.separator)
|
||||
.filter((filePath) => !allChangedFiles.paths.split(inputs.separator).includes(filePath));
|
||||
|
@ -535,7 +536,7 @@ const setChangedFilesOutput = ({ allDiffFiles, inputs, workingDirectory, diffRes
|
|||
changedFiles_1.ChangeTypeEnum.Deleted
|
||||
]
|
||||
});
|
||||
core.debug(`All modified files: ${allModifiedFiles}`);
|
||||
core.debug(`All modified files: ${JSON.stringify(allModifiedFiles)}`);
|
||||
yield (0, utils_1.setOutput)({
|
||||
key: getOutputKey('all_modified_files', outputPrefix),
|
||||
value: allModifiedFiles.paths,
|
||||
|
@ -588,7 +589,7 @@ const setChangedFilesOutput = ({ allDiffFiles, inputs, workingDirectory, diffRes
|
|||
changedFiles: allFilteredDiffFiles,
|
||||
changeTypes: [changedFiles_1.ChangeTypeEnum.Deleted]
|
||||
});
|
||||
core.debug(`Deleted files: ${deletedFiles}`);
|
||||
core.debug(`Deleted files: ${JSON.stringify(deletedFiles)}`);
|
||||
yield (0, utils_1.setOutput)({
|
||||
key: getOutputKey('deleted_files', outputPrefix),
|
||||
value: deletedFiles.paths,
|
||||
|
@ -676,8 +677,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.getSHAForPullRequestEvent = exports.getSHAForPushEvent = void 0;
|
||||
const core = __importStar(__nccwpck_require__(2186));
|
||||
const github = __importStar(__nccwpck_require__(5438));
|
||||
const utils_1 = __nccwpck_require__(918);
|
||||
const getCurrentSHA = ({ env, inputs, workingDirectory }) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
const getCurrentSHA = ({ inputs, workingDirectory }) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
var _a, _b, _c, _d, _e, _f;
|
||||
let currentSha = inputs.sha;
|
||||
core.debug('Getting current SHA...');
|
||||
if (inputs.until) {
|
||||
|
@ -703,13 +706,13 @@ const getCurrentSHA = ({ env, inputs, workingDirectory }) => __awaiter(void 0, v
|
|||
}
|
||||
else {
|
||||
if (!currentSha) {
|
||||
if (env.GITHUB_EVENT_PULL_REQUEST_HEAD_SHA &&
|
||||
if (((_b = (_a = github.context.payload.pull_request) === null || _a === void 0 ? void 0 : _a.head) === null || _b === void 0 ? void 0 : _b.sha) &&
|
||||
(yield (0, utils_1.verifyCommitSha)({
|
||||
sha: env.GITHUB_EVENT_PULL_REQUEST_HEAD_SHA,
|
||||
sha: (_d = (_c = github.context.payload.pull_request) === null || _c === void 0 ? void 0 : _c.head) === null || _d === void 0 ? void 0 : _d.sha,
|
||||
cwd: workingDirectory,
|
||||
showAsErrorMessage: false
|
||||
})) === 0) {
|
||||
currentSha = env.GITHUB_EVENT_PULL_REQUEST_HEAD_SHA;
|
||||
currentSha = (_f = (_e = github.context.payload.pull_request) === null || _e === void 0 ? void 0 : _e.head) === null || _f === void 0 ? void 0 : _f.sha;
|
||||
}
|
||||
else {
|
||||
currentSha = yield (0, utils_1.getHeadSha)({ cwd: workingDirectory });
|
||||
|
@ -721,14 +724,15 @@ const getCurrentSHA = ({ env, inputs, workingDirectory }) => __awaiter(void 0, v
|
|||
return currentSha;
|
||||
});
|
||||
const getSHAForPushEvent = (inputs, env, workingDirectory, isShallow, hasSubmodule, gitFetchExtraArgs, isTag) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
var _g;
|
||||
let targetBranch = env.GITHUB_REF_NAME;
|
||||
const currentBranch = targetBranch;
|
||||
let initialCommit = false;
|
||||
if (isShallow && !inputs.skipInitialFetch) {
|
||||
core.info('Repository is shallow, fetching more history...');
|
||||
if (isTag) {
|
||||
const sourceBranch = env.GITHUB_EVENT_BASE_REF.replace('refs/heads/', '') ||
|
||||
env.GITHUB_EVENT_RELEASE_TARGET_COMMITISH;
|
||||
const sourceBranch = github.context.payload.base_ref.replace('refs/heads/', '') ||
|
||||
((_g = github.context.payload.release) === null || _g === void 0 ? void 0 : _g.target_commitish);
|
||||
yield (0, utils_1.gitFetch)({
|
||||
cwd: workingDirectory,
|
||||
args: [
|
||||
|
@ -766,7 +770,7 @@ const getSHAForPushEvent = (inputs, env, workingDirectory, isShallow, hasSubmodu
|
|||
});
|
||||
}
|
||||
}
|
||||
const currentSha = yield getCurrentSHA({ env, inputs, workingDirectory });
|
||||
const currentSha = yield getCurrentSHA({ inputs, workingDirectory });
|
||||
let previousSha = inputs.baseSha;
|
||||
const diff = '..';
|
||||
if (previousSha && currentSha && currentBranch && targetBranch) {
|
||||
|
@ -812,8 +816,9 @@ const getSHAForPushEvent = (inputs, env, workingDirectory, isShallow, hasSubmodu
|
|||
}
|
||||
else {
|
||||
core.debug('Getting previous SHA for last remote commit...');
|
||||
if (env.GITHUB_EVENT_FORCED === 'false' || !env.GITHUB_EVENT_FORCED) {
|
||||
previousSha = env.GITHUB_EVENT_BEFORE;
|
||||
if (github.context.payload.forced === 'false' ||
|
||||
!github.context.payload.forced) {
|
||||
previousSha = github.context.payload.before;
|
||||
}
|
||||
if (!previousSha ||
|
||||
previousSha === '0000000000000000000000000000000000000000') {
|
||||
|
@ -863,8 +868,9 @@ const getSHAForPushEvent = (inputs, env, workingDirectory, isShallow, hasSubmodu
|
|||
});
|
||||
exports.getSHAForPushEvent = getSHAForPushEvent;
|
||||
const getSHAForPullRequestEvent = (inputs, env, workingDirectory, isShallow, hasSubmodule, gitFetchExtraArgs) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
let targetBranch = env.GITHUB_EVENT_PULL_REQUEST_BASE_REF;
|
||||
const currentBranch = env.GITHUB_EVENT_PULL_REQUEST_HEAD_REF;
|
||||
var _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
|
||||
let targetBranch = (_j = (_h = github.context.payload.pull_request) === null || _h === void 0 ? void 0 : _h.base) === null || _j === void 0 ? void 0 : _j.ref;
|
||||
const currentBranch = (_l = (_k = github.context.payload.pull_request) === null || _k === void 0 ? void 0 : _k.head) === null || _l === void 0 ? void 0 : _l.ref;
|
||||
if (inputs.sinceLastRemoteCommit) {
|
||||
targetBranch = currentBranch;
|
||||
}
|
||||
|
@ -877,7 +883,7 @@ const getSHAForPullRequestEvent = (inputs, env, workingDirectory, isShallow, has
|
|||
'-u',
|
||||
'--progress',
|
||||
'origin',
|
||||
`pull/${env.GITHUB_EVENT_PULL_REQUEST_NUMBER}/head:${currentBranch}`
|
||||
`pull/${(_m = github.context.payload.pull_request) === null || _m === void 0 ? void 0 : _m.number}/head:${currentBranch}`
|
||||
]
|
||||
});
|
||||
if (prFetchExitCode !== 0) {
|
||||
|
@ -923,7 +929,7 @@ const getSHAForPullRequestEvent = (inputs, env, workingDirectory, isShallow, has
|
|||
}
|
||||
core.info('Completed fetching more history.');
|
||||
}
|
||||
const currentSha = yield getCurrentSHA({ env, inputs, workingDirectory });
|
||||
const currentSha = yield getCurrentSHA({ inputs, workingDirectory });
|
||||
let previousSha = inputs.baseSha;
|
||||
let diff = '...';
|
||||
if (previousSha && currentSha && currentBranch && targetBranch) {
|
||||
|
@ -942,13 +948,13 @@ const getSHAForPullRequestEvent = (inputs, env, workingDirectory, isShallow, has
|
|||
diff
|
||||
};
|
||||
}
|
||||
if (!env.GITHUB_EVENT_PULL_REQUEST_BASE_REF ||
|
||||
env.GITHUB_EVENT_HEAD_REPO_FORK === 'true') {
|
||||
if (!((_p = (_o = github.context.payload.pull_request) === null || _o === void 0 ? void 0 : _o.base) === null || _p === void 0 ? void 0 : _p.ref) ||
|
||||
((_r = (_q = github.context.payload.head) === null || _q === void 0 ? void 0 : _q.repo) === null || _r === void 0 ? void 0 : _r.fork) === 'true') {
|
||||
diff = '..';
|
||||
}
|
||||
if (!previousSha) {
|
||||
if (inputs.sinceLastRemoteCommit) {
|
||||
previousSha = env.GITHUB_EVENT_BEFORE;
|
||||
previousSha = github.context.payload.before;
|
||||
if (!previousSha ||
|
||||
(previousSha &&
|
||||
(yield (0, utils_1.verifyCommitSha)({ sha: previousSha, cwd: workingDirectory })) !==
|
||||
|
@ -959,7 +965,7 @@ const getSHAForPullRequestEvent = (inputs, env, workingDirectory, isShallow, has
|
|||
});
|
||||
if (!previousSha) {
|
||||
core.warning('Unable to locate the previous commit in the local history. Falling back to the pull request base sha.');
|
||||
previousSha = env.GITHUB_EVENT_PULL_REQUEST_BASE_SHA;
|
||||
previousSha = (_t = (_s = github.context.payload.pull_request) === null || _s === void 0 ? void 0 : _s.base) === null || _t === void 0 ? void 0 : _t.sha;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -969,7 +975,7 @@ const getSHAForPullRequestEvent = (inputs, env, workingDirectory, isShallow, has
|
|||
branch: targetBranch
|
||||
});
|
||||
if (!previousSha) {
|
||||
previousSha = env.GITHUB_EVENT_PULL_REQUEST_BASE_SHA;
|
||||
previousSha = (_v = (_u = github.context.payload.pull_request) === null || _u === void 0 ? void 0 : _u.base) === null || _v === void 0 ? void 0 : _v.sha;
|
||||
}
|
||||
if (isShallow) {
|
||||
if (!(yield (0, utils_1.canDiffCommits)({
|
||||
|
@ -1006,7 +1012,7 @@ const getSHAForPullRequestEvent = (inputs, env, workingDirectory, isShallow, has
|
|||
}
|
||||
}
|
||||
if (!previousSha || previousSha === currentSha) {
|
||||
previousSha = env.GITHUB_EVENT_PULL_REQUEST_BASE_SHA;
|
||||
previousSha = (_x = (_w = github.context.payload.pull_request) === null || _w === void 0 ? void 0 : _w.base) === null || _x === void 0 ? void 0 : _x.sha;
|
||||
}
|
||||
}
|
||||
if (!(yield (0, utils_1.canDiffCommits)({
|
||||
|
@ -1039,7 +1045,7 @@ const getSHAForPullRequestEvent = (inputs, env, workingDirectory, isShallow, has
|
|||
// uses: actions/checkout@v3
|
||||
// with:
|
||||
// repository: ${{ github.event.pull_request.head.repo.full_name }}
|
||||
if (env.GITHUB_EVENT_NAME === 'pull_request_target') {
|
||||
if (github.context.eventName === 'pull_request_target') {
|
||||
core.warning('If this pull request is from a forked repository, please set the checkout action `repository` input to the same repository as the pull request.');
|
||||
core.warning('This can be done by setting actions/checkout `repository` to ${{ github.event.pull_request.head.repo.full_name }}');
|
||||
}
|
||||
|
@ -1100,35 +1106,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|||
};
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.getEnv = void 0;
|
||||
const fs_1 = __nccwpck_require__(7147);
|
||||
const core = __importStar(__nccwpck_require__(2186));
|
||||
const getEnv = () => __awaiter(void 0, void 0, void 0, function* () {
|
||||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
||||
const eventPath = process.env.GITHUB_EVENT_PATH;
|
||||
let eventJson = {};
|
||||
if (eventPath) {
|
||||
eventJson = JSON.parse(yield fs_1.promises.readFile(eventPath, { encoding: 'utf8' }));
|
||||
}
|
||||
core.debug(`Env: ${JSON.stringify(process.env, null, 2)}`);
|
||||
core.debug(`Event: ${JSON.stringify(eventJson, null, 2)}`);
|
||||
core.debug(`Process Env: ${JSON.stringify(process.env, null, 2)}`);
|
||||
return {
|
||||
GITHUB_EVENT_PULL_REQUEST_HEAD_REF: ((_b = (_a = eventJson.pull_request) === null || _a === void 0 ? void 0 : _a.head) === null || _b === void 0 ? void 0 : _b.ref) || '',
|
||||
GITHUB_EVENT_PULL_REQUEST_BASE_REF: ((_d = (_c = eventJson.pull_request) === null || _c === void 0 ? void 0 : _c.base) === null || _d === void 0 ? void 0 : _d.ref) || '',
|
||||
GITHUB_EVENT_BEFORE: eventJson.before || '',
|
||||
GITHUB_EVENT_BASE_REF: eventJson.base_ref || '',
|
||||
GITHUB_EVENT_RELEASE_TARGET_COMMITISH: ((_e = eventJson.release) === null || _e === void 0 ? void 0 : _e.target_commitish) || '',
|
||||
GITHUB_EVENT_HEAD_REPO_FORK: ((_g = (_f = eventJson.head) === null || _f === void 0 ? void 0 : _f.repo) === null || _g === void 0 ? void 0 : _g.fork) || '',
|
||||
GITHUB_EVENT_PULL_REQUEST_NUMBER: ((_h = eventJson.pull_request) === null || _h === void 0 ? void 0 : _h.number) || '',
|
||||
GITHUB_EVENT_PULL_REQUEST_BASE_SHA: ((_k = (_j = eventJson.pull_request) === null || _j === void 0 ? void 0 : _j.base) === null || _k === void 0 ? void 0 : _k.sha) || '',
|
||||
GITHUB_EVENT_PULL_REQUEST_HEAD_SHA: ((_m = (_l = eventJson.pull_request) === null || _l === void 0 ? void 0 : _l.head) === null || _m === void 0 ? void 0 : _m.sha) || '',
|
||||
GITHUB_EVENT_FORCED: eventJson.forced || '',
|
||||
GITHUB_EVENT_ACTION: eventJson.action || '',
|
||||
GITHUB_REF_NAME: process.env.GITHUB_REF_NAME || '',
|
||||
GITHUB_REF: process.env.GITHUB_REF || '',
|
||||
GITHUB_WORKSPACE: process.env.GITHUB_WORKSPACE || '',
|
||||
GITHUB_EVENT_NAME: process.env.GITHUB_EVENT_NAME || '',
|
||||
GITHUB_REPOSITORY_OWNER: process.env.GITHUB_REPOSITORY_OWNER || '',
|
||||
GITHUB_REPOSITORY: process.env.GITHUB_REPOSITORY || ''
|
||||
GITHUB_WORKSPACE: process.env.GITHUB_WORKSPACE || ''
|
||||
};
|
||||
});
|
||||
exports.getEnv = getEnv;
|
||||
|
@ -1347,6 +1331,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.run = void 0;
|
||||
const core = __importStar(__nccwpck_require__(2186));
|
||||
const github = __importStar(__nccwpck_require__(5438));
|
||||
const path_1 = __importDefault(__nccwpck_require__(1017));
|
||||
const changedFiles_1 = __nccwpck_require__(7358);
|
||||
const changedFilesOutput_1 = __nccwpck_require__(8930);
|
||||
|
@ -1355,7 +1340,7 @@ const env_1 = __nccwpck_require__(9763);
|
|||
const inputs_1 = __nccwpck_require__(6180);
|
||||
const utils_1 = __nccwpck_require__(918);
|
||||
const getChangedFilesFromLocalGit = ({ inputs, env, workingDirectory, filePatterns, yamlFilePatterns }) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
var _a;
|
||||
var _a, _b, _c;
|
||||
yield (0, utils_1.verifyMinimumGitVersion)();
|
||||
let quotePathValue = 'on';
|
||||
if (!inputs.quotePath) {
|
||||
|
@ -1384,12 +1369,12 @@ const getChangedFilesFromLocalGit = ({ inputs, env, workingDirectory, filePatter
|
|||
gitFetchExtraArgs = ['--prune', '--no-recurse-submodules'];
|
||||
}
|
||||
let diffResult;
|
||||
if (!env.GITHUB_EVENT_PULL_REQUEST_BASE_REF) {
|
||||
core.info(`Running on a ${env.GITHUB_EVENT_NAME || 'push'} event...`);
|
||||
if (!((_c = (_b = github.context.payload.pull_request) === null || _b === void 0 ? void 0 : _b.base) === null || _c === void 0 ? void 0 : _c.ref)) {
|
||||
core.info(`Running on a ${github.context.eventName || 'push'} event...`);
|
||||
diffResult = yield (0, commitSha_1.getSHAForPushEvent)(inputs, env, workingDirectory, isShallow, hasSubmodule, gitFetchExtraArgs, isTag);
|
||||
}
|
||||
else {
|
||||
core.info(`Running on a ${env.GITHUB_EVENT_NAME || 'pull_request'} (${env.GITHUB_EVENT_ACTION}) event...`);
|
||||
core.info(`Running on a ${github.context.eventName || 'pull_request'} (${github.context.payload.action}) event...`);
|
||||
diffResult = yield (0, commitSha_1.getSHAForPullRequestEvent)(inputs, env, workingDirectory, isShallow, hasSubmodule, gitFetchExtraArgs);
|
||||
}
|
||||
if (diffResult.initialCommit) {
|
||||
|
@ -1470,10 +1455,9 @@ const getChangedFilesFromLocalGit = ({ inputs, env, workingDirectory, filePatter
|
|||
core.endGroup();
|
||||
}
|
||||
});
|
||||
const getChangedFilesFromRESTAPI = ({ inputs, env, workingDirectory, filePatterns, yamlFilePatterns }) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
const getChangedFilesFromRESTAPI = ({ inputs, workingDirectory, filePatterns, yamlFilePatterns }) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
const allDiffFiles = yield (0, changedFiles_1.getChangedFilesFromGithubAPI)({
|
||||
inputs,
|
||||
env
|
||||
inputs
|
||||
});
|
||||
core.debug(`All diff files: ${JSON.stringify(allDiffFiles)}`);
|
||||
core.info('All Done!');
|
||||
|
@ -1514,12 +1498,15 @@ const getChangedFilesFromRESTAPI = ({ inputs, env, workingDirectory, filePattern
|
|||
}
|
||||
});
|
||||
function run() {
|
||||
var _a;
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
core.startGroup('changed-files');
|
||||
const env = yield (0, env_1.getEnv)();
|
||||
core.debug(`Env: ${JSON.stringify(env, null, 2)}`);
|
||||
const inputs = (0, inputs_1.getInputs)();
|
||||
core.debug(`Inputs: ${JSON.stringify(inputs, null, 2)}`);
|
||||
const githubContext = github.context;
|
||||
core.debug(`Github Context: ${JSON.stringify(githubContext, null, 2)}`);
|
||||
const workingDirectory = path_1.default.resolve(env.GITHUB_WORKSPACE || process.cwd(), inputs.path);
|
||||
core.debug(`Working directory: ${workingDirectory}`);
|
||||
const hasGitDirectory = yield (0, utils_1.hasLocalGitDirectory)({ workingDirectory });
|
||||
|
@ -1535,7 +1522,7 @@ function run() {
|
|||
});
|
||||
core.debug(`Yaml file patterns: ${JSON.stringify(yamlFilePatterns)}`);
|
||||
if (inputs.token &&
|
||||
env.GITHUB_EVENT_PULL_REQUEST_NUMBER &&
|
||||
((_a = github.context.payload.pull_request) === null || _a === void 0 ? void 0 : _a.number) &&
|
||||
!hasGitDirectory) {
|
||||
core.info("Using GitHub's REST API to get changed files");
|
||||
const unsupportedInputs = [
|
||||
|
@ -1555,7 +1542,6 @@ function run() {
|
|||
}
|
||||
yield getChangedFilesFromRESTAPI({
|
||||
inputs,
|
||||
env,
|
||||
workingDirectory,
|
||||
filePatterns,
|
||||
yamlFilePatterns
|
||||
|
|
2
dist/index.js.map
generated
vendored
2
dist/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
|
@ -1,19 +1,18 @@
|
|||
import * as core from '@actions/core'
|
||||
import * as github from '@actions/github'
|
||||
import type {RestEndpointMethodTypes} from '@octokit/rest'
|
||||
import flatten from 'lodash/flatten'
|
||||
import * as path from 'path'
|
||||
|
||||
import {DiffResult} from './commitSha'
|
||||
import {Env} from './env'
|
||||
import {Inputs} from './inputs'
|
||||
import {
|
||||
getAllChangedFiles,
|
||||
getDirnameMaxDepth,
|
||||
gitRenamedFiles,
|
||||
gitSubmoduleDiffSHA,
|
||||
jsonOutput,
|
||||
getAllChangedFiles
|
||||
jsonOutput
|
||||
} from './utils'
|
||||
import flatten from 'lodash/flatten'
|
||||
|
||||
export const getRenamedFiles = async ({
|
||||
inputs,
|
||||
|
@ -252,11 +251,9 @@ export const getAllChangeTypeFiles = async ({
|
|||
}
|
||||
|
||||
export const getChangedFilesFromGithubAPI = async ({
|
||||
inputs,
|
||||
env
|
||||
inputs
|
||||
}: {
|
||||
inputs: Inputs
|
||||
env: Env
|
||||
}): Promise<ChangedFiles> => {
|
||||
const octokit = github.getOctokit(inputs.token, {
|
||||
baseUrl: inputs.apiUrl
|
||||
|
@ -277,7 +274,7 @@ export const getChangedFilesFromGithubAPI = async ({
|
|||
const options = octokit.rest.pulls.listFiles.endpoint.merge({
|
||||
owner: github.context.repo.owner,
|
||||
repo: github.context.repo.repo,
|
||||
pull_number: env.GITHUB_EVENT_PULL_REQUEST_NUMBER,
|
||||
pull_number: github.context.payload.pull_request?.number,
|
||||
per_page: 100
|
||||
})
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ export const setChangedFilesOutput = async ({
|
|||
changedFiles: allFilteredDiffFiles,
|
||||
changeTypes: [ChangeTypeEnum.Added]
|
||||
})
|
||||
core.debug(`Added files: ${addedFiles}`)
|
||||
core.debug(`Added files: ${JSON.stringify(addedFiles)}`)
|
||||
await setOutput({
|
||||
key: getOutputKey('added_files', outputPrefix),
|
||||
value: addedFiles.paths,
|
||||
|
@ -65,7 +65,7 @@ export const setChangedFilesOutput = async ({
|
|||
changedFiles: allFilteredDiffFiles,
|
||||
changeTypes: [ChangeTypeEnum.Copied]
|
||||
})
|
||||
core.debug(`Copied files: ${copiedFiles}`)
|
||||
core.debug(`Copied files: ${JSON.stringify(copiedFiles)}`)
|
||||
await setOutput({
|
||||
key: getOutputKey('copied_files', outputPrefix),
|
||||
value: copiedFiles.paths,
|
||||
|
@ -83,7 +83,7 @@ export const setChangedFilesOutput = async ({
|
|||
changedFiles: allFilteredDiffFiles,
|
||||
changeTypes: [ChangeTypeEnum.Modified]
|
||||
})
|
||||
core.debug(`Modified files: ${modifiedFiles}`)
|
||||
core.debug(`Modified files: ${JSON.stringify(modifiedFiles)}`)
|
||||
await setOutput({
|
||||
key: getOutputKey('modified_files', outputPrefix),
|
||||
value: modifiedFiles.paths,
|
||||
|
@ -101,7 +101,7 @@ export const setChangedFilesOutput = async ({
|
|||
changedFiles: allFilteredDiffFiles,
|
||||
changeTypes: [ChangeTypeEnum.Renamed]
|
||||
})
|
||||
core.debug(`Renamed files: ${renamedFiles}`)
|
||||
core.debug(`Renamed files: ${JSON.stringify(renamedFiles)}`)
|
||||
await setOutput({
|
||||
key: getOutputKey('renamed_files', outputPrefix),
|
||||
value: renamedFiles.paths,
|
||||
|
@ -119,7 +119,7 @@ export const setChangedFilesOutput = async ({
|
|||
changedFiles: allFilteredDiffFiles,
|
||||
changeTypes: [ChangeTypeEnum.TypeChanged]
|
||||
})
|
||||
core.debug(`Type changed files: ${typeChangedFiles}`)
|
||||
core.debug(`Type changed files: ${JSON.stringify(typeChangedFiles)}`)
|
||||
await setOutput({
|
||||
key: getOutputKey('type_changed_files', outputPrefix),
|
||||
value: typeChangedFiles.paths,
|
||||
|
@ -137,7 +137,7 @@ export const setChangedFilesOutput = async ({
|
|||
changedFiles: allFilteredDiffFiles,
|
||||
changeTypes: [ChangeTypeEnum.Unmerged]
|
||||
})
|
||||
core.debug(`Unmerged files: ${unmergedFiles}`)
|
||||
core.debug(`Unmerged files: ${JSON.stringify(unmergedFiles)}`)
|
||||
await setOutput({
|
||||
key: getOutputKey('unmerged_files', outputPrefix),
|
||||
value: unmergedFiles.paths,
|
||||
|
@ -155,7 +155,7 @@ export const setChangedFilesOutput = async ({
|
|||
changedFiles: allFilteredDiffFiles,
|
||||
changeTypes: [ChangeTypeEnum.Unknown]
|
||||
})
|
||||
core.debug(`Unknown files: ${unknownFiles}`)
|
||||
core.debug(`Unknown files: ${JSON.stringify(unknownFiles)}`)
|
||||
await setOutput({
|
||||
key: getOutputKey('unknown_files', outputPrefix),
|
||||
value: unknownFiles.paths,
|
||||
|
@ -172,7 +172,11 @@ export const setChangedFilesOutput = async ({
|
|||
inputs,
|
||||
changedFiles: allFilteredDiffFiles
|
||||
})
|
||||
core.debug(`All changed and modified files: ${allChangedAndModifiedFiles}`)
|
||||
core.debug(
|
||||
`All changed and modified files: ${JSON.stringify(
|
||||
allChangedAndModifiedFiles
|
||||
)}`
|
||||
)
|
||||
await setOutput({
|
||||
key: getOutputKey('all_changed_and_modified_files', outputPrefix),
|
||||
value: allChangedAndModifiedFiles.paths,
|
||||
|
@ -195,7 +199,7 @@ export const setChangedFilesOutput = async ({
|
|||
ChangeTypeEnum.Renamed
|
||||
]
|
||||
})
|
||||
core.debug(`All changed files: ${allChangedFiles}`)
|
||||
core.debug(`All changed files: ${JSON.stringify(allChangedFiles)}`)
|
||||
await setOutput({
|
||||
key: getOutputKey('all_changed_files', outputPrefix),
|
||||
value: allChangedFiles.paths,
|
||||
|
@ -224,7 +228,7 @@ export const setChangedFilesOutput = async ({
|
|||
ChangeTypeEnum.Renamed
|
||||
]
|
||||
})
|
||||
core.debug(`All other changed files: ${allOtherChangedFiles}`)
|
||||
core.debug(`All other changed files: ${JSON.stringify(allOtherChangedFiles)}`)
|
||||
|
||||
const otherChangedFiles = allOtherChangedFiles.paths
|
||||
.split(inputs.separator)
|
||||
|
@ -267,7 +271,7 @@ export const setChangedFilesOutput = async ({
|
|||
ChangeTypeEnum.Deleted
|
||||
]
|
||||
})
|
||||
core.debug(`All modified files: ${allModifiedFiles}`)
|
||||
core.debug(`All modified files: ${JSON.stringify(allModifiedFiles)}`)
|
||||
await setOutput({
|
||||
key: getOutputKey('all_modified_files', outputPrefix),
|
||||
value: allModifiedFiles.paths,
|
||||
|
@ -333,7 +337,7 @@ export const setChangedFilesOutput = async ({
|
|||
changedFiles: allFilteredDiffFiles,
|
||||
changeTypes: [ChangeTypeEnum.Deleted]
|
||||
})
|
||||
core.debug(`Deleted files: ${deletedFiles}`)
|
||||
core.debug(`Deleted files: ${JSON.stringify(deletedFiles)}`)
|
||||
await setOutput({
|
||||
key: getOutputKey('deleted_files', outputPrefix),
|
||||
value: deletedFiles.paths,
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import * as core from '@actions/core'
|
||||
import * as github from '@actions/github'
|
||||
|
||||
import {Env} from './env'
|
||||
import {Inputs} from './inputs'
|
||||
|
@ -15,11 +16,9 @@ import {
|
|||
} from './utils'
|
||||
|
||||
const getCurrentSHA = async ({
|
||||
env,
|
||||
inputs,
|
||||
workingDirectory
|
||||
}: {
|
||||
env: Env
|
||||
inputs: Inputs
|
||||
workingDirectory: string
|
||||
}): Promise<string> => {
|
||||
|
@ -50,14 +49,14 @@ const getCurrentSHA = async ({
|
|||
} else {
|
||||
if (!currentSha) {
|
||||
if (
|
||||
env.GITHUB_EVENT_PULL_REQUEST_HEAD_SHA &&
|
||||
github.context.payload.pull_request?.head?.sha &&
|
||||
(await verifyCommitSha({
|
||||
sha: env.GITHUB_EVENT_PULL_REQUEST_HEAD_SHA,
|
||||
sha: github.context.payload.pull_request?.head?.sha,
|
||||
cwd: workingDirectory,
|
||||
showAsErrorMessage: false
|
||||
})) === 0
|
||||
) {
|
||||
currentSha = env.GITHUB_EVENT_PULL_REQUEST_HEAD_SHA
|
||||
currentSha = github.context.payload.pull_request?.head?.sha
|
||||
} else {
|
||||
currentSha = await getHeadSha({cwd: workingDirectory})
|
||||
}
|
||||
|
@ -97,8 +96,8 @@ export const getSHAForPushEvent = async (
|
|||
|
||||
if (isTag) {
|
||||
const sourceBranch =
|
||||
env.GITHUB_EVENT_BASE_REF.replace('refs/heads/', '') ||
|
||||
env.GITHUB_EVENT_RELEASE_TARGET_COMMITISH
|
||||
github.context.payload.base_ref.replace('refs/heads/', '') ||
|
||||
github.context.payload.release?.target_commitish
|
||||
await gitFetch({
|
||||
cwd: workingDirectory,
|
||||
args: [
|
||||
|
@ -137,7 +136,7 @@ export const getSHAForPushEvent = async (
|
|||
}
|
||||
}
|
||||
|
||||
const currentSha = await getCurrentSHA({env, inputs, workingDirectory})
|
||||
const currentSha = await getCurrentSHA({inputs, workingDirectory})
|
||||
let previousSha = inputs.baseSha
|
||||
const diff = '..'
|
||||
|
||||
|
@ -191,8 +190,11 @@ export const getSHAForPushEvent = async (
|
|||
targetBranch = tag
|
||||
} else {
|
||||
core.debug('Getting previous SHA for last remote commit...')
|
||||
if (env.GITHUB_EVENT_FORCED === 'false' || !env.GITHUB_EVENT_FORCED) {
|
||||
previousSha = env.GITHUB_EVENT_BEFORE
|
||||
if (
|
||||
github.context.payload.forced === 'false' ||
|
||||
!github.context.payload.forced
|
||||
) {
|
||||
previousSha = github.context.payload.before
|
||||
}
|
||||
|
||||
if (
|
||||
|
@ -265,8 +267,8 @@ export const getSHAForPullRequestEvent = async (
|
|||
hasSubmodule: boolean,
|
||||
gitFetchExtraArgs: string[]
|
||||
): Promise<DiffResult> => {
|
||||
let targetBranch = env.GITHUB_EVENT_PULL_REQUEST_BASE_REF
|
||||
const currentBranch = env.GITHUB_EVENT_PULL_REQUEST_HEAD_REF
|
||||
let targetBranch = github.context.payload.pull_request?.base?.ref
|
||||
const currentBranch = github.context.payload.pull_request?.head?.ref
|
||||
if (inputs.sinceLastRemoteCommit) {
|
||||
targetBranch = currentBranch
|
||||
}
|
||||
|
@ -281,7 +283,7 @@ export const getSHAForPullRequestEvent = async (
|
|||
'-u',
|
||||
'--progress',
|
||||
'origin',
|
||||
`pull/${env.GITHUB_EVENT_PULL_REQUEST_NUMBER}/head:${currentBranch}`
|
||||
`pull/${github.context.payload.pull_request?.number}/head:${currentBranch}`
|
||||
]
|
||||
})
|
||||
|
||||
|
@ -334,7 +336,7 @@ export const getSHAForPullRequestEvent = async (
|
|||
core.info('Completed fetching more history.')
|
||||
}
|
||||
|
||||
const currentSha = await getCurrentSHA({env, inputs, workingDirectory})
|
||||
const currentSha = await getCurrentSHA({inputs, workingDirectory})
|
||||
let previousSha = inputs.baseSha
|
||||
let diff = '...'
|
||||
|
||||
|
@ -362,15 +364,15 @@ export const getSHAForPullRequestEvent = async (
|
|||
}
|
||||
|
||||
if (
|
||||
!env.GITHUB_EVENT_PULL_REQUEST_BASE_REF ||
|
||||
env.GITHUB_EVENT_HEAD_REPO_FORK === 'true'
|
||||
!github.context.payload.pull_request?.base?.ref ||
|
||||
github.context.payload.head?.repo?.fork === 'true'
|
||||
) {
|
||||
diff = '..'
|
||||
}
|
||||
|
||||
if (!previousSha) {
|
||||
if (inputs.sinceLastRemoteCommit) {
|
||||
previousSha = env.GITHUB_EVENT_BEFORE
|
||||
previousSha = github.context.payload.before
|
||||
|
||||
if (
|
||||
!previousSha ||
|
||||
|
@ -389,7 +391,7 @@ export const getSHAForPullRequestEvent = async (
|
|||
core.warning(
|
||||
'Unable to locate the previous commit in the local history. Falling back to the pull request base sha.'
|
||||
)
|
||||
previousSha = env.GITHUB_EVENT_PULL_REQUEST_BASE_SHA
|
||||
previousSha = github.context.payload.pull_request?.base?.sha
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -399,7 +401,7 @@ export const getSHAForPullRequestEvent = async (
|
|||
})
|
||||
|
||||
if (!previousSha) {
|
||||
previousSha = env.GITHUB_EVENT_PULL_REQUEST_BASE_SHA
|
||||
previousSha = github.context.payload.pull_request?.base?.sha
|
||||
}
|
||||
|
||||
if (isShallow) {
|
||||
|
@ -449,7 +451,7 @@ export const getSHAForPullRequestEvent = async (
|
|||
}
|
||||
|
||||
if (!previousSha || previousSha === currentSha) {
|
||||
previousSha = env.GITHUB_EVENT_PULL_REQUEST_BASE_SHA
|
||||
previousSha = github.context.payload.pull_request?.base?.sha
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -494,7 +496,7 @@ export const getSHAForPullRequestEvent = async (
|
|||
// uses: actions/checkout@v3
|
||||
// with:
|
||||
// repository: ${{ github.event.pull_request.head.repo.full_name }}
|
||||
if (env.GITHUB_EVENT_NAME === 'pull_request_target') {
|
||||
if (github.context.eventName === 'pull_request_target') {
|
||||
core.warning(
|
||||
'If this pull request is from a forked repository, please set the checkout action `repository` input to the same repository as the pull request.'
|
||||
)
|
||||
|
|
68
src/env.ts
68
src/env.ts
|
@ -1,80 +1,16 @@
|
|||
import {promises as fs} from 'fs'
|
||||
import * as core from '@actions/core'
|
||||
|
||||
export type Env = {
|
||||
GITHUB_REF_NAME: string
|
||||
GITHUB_REF: string
|
||||
GITHUB_WORKSPACE: string
|
||||
GITHUB_EVENT_ACTION: string
|
||||
GITHUB_EVENT_NAME: string
|
||||
GITHUB_EVENT_FORCED: string
|
||||
GITHUB_EVENT_BEFORE: string
|
||||
GITHUB_EVENT_BASE_REF: string
|
||||
GITHUB_EVENT_RELEASE_TARGET_COMMITISH: string
|
||||
GITHUB_EVENT_HEAD_REPO_FORK: string
|
||||
GITHUB_EVENT_PULL_REQUEST_NUMBER: string
|
||||
GITHUB_EVENT_PULL_REQUEST_BASE_SHA: string
|
||||
GITHUB_EVENT_PULL_REQUEST_HEAD_SHA: string
|
||||
GITHUB_EVENT_PULL_REQUEST_HEAD_REF: string
|
||||
GITHUB_EVENT_PULL_REQUEST_BASE_REF: string
|
||||
GITHUB_REPOSITORY_OWNER: string
|
||||
GITHUB_REPOSITORY: string
|
||||
}
|
||||
|
||||
type GithubEvent = {
|
||||
action?: string
|
||||
forced?: string
|
||||
pull_request?: {
|
||||
head: {
|
||||
ref: string
|
||||
sha: string
|
||||
}
|
||||
base: {
|
||||
ref: string
|
||||
sha: string
|
||||
}
|
||||
number: string
|
||||
}
|
||||
release?: {
|
||||
target_commitish: string
|
||||
}
|
||||
before?: string
|
||||
base_ref?: string
|
||||
head?: {
|
||||
repo?: {
|
||||
fork: string
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const getEnv = async (): Promise<Env> => {
|
||||
const eventPath = process.env.GITHUB_EVENT_PATH
|
||||
let eventJson: GithubEvent = {}
|
||||
|
||||
if (eventPath) {
|
||||
eventJson = JSON.parse(await fs.readFile(eventPath, {encoding: 'utf8'}))
|
||||
}
|
||||
core.debug(`Env: ${JSON.stringify(process.env, null, 2)}`)
|
||||
core.debug(`Event: ${JSON.stringify(eventJson, null, 2)}`)
|
||||
core.debug(`Process Env: ${JSON.stringify(process.env, null, 2)}`)
|
||||
|
||||
return {
|
||||
GITHUB_EVENT_PULL_REQUEST_HEAD_REF: eventJson.pull_request?.head?.ref || '',
|
||||
GITHUB_EVENT_PULL_REQUEST_BASE_REF: eventJson.pull_request?.base?.ref || '',
|
||||
GITHUB_EVENT_BEFORE: eventJson.before || '',
|
||||
GITHUB_EVENT_BASE_REF: eventJson.base_ref || '',
|
||||
GITHUB_EVENT_RELEASE_TARGET_COMMITISH:
|
||||
eventJson.release?.target_commitish || '',
|
||||
GITHUB_EVENT_HEAD_REPO_FORK: eventJson.head?.repo?.fork || '',
|
||||
GITHUB_EVENT_PULL_REQUEST_NUMBER: eventJson.pull_request?.number || '',
|
||||
GITHUB_EVENT_PULL_REQUEST_BASE_SHA: eventJson.pull_request?.base?.sha || '',
|
||||
GITHUB_EVENT_PULL_REQUEST_HEAD_SHA: eventJson.pull_request?.head?.sha || '',
|
||||
GITHUB_EVENT_FORCED: eventJson.forced || '',
|
||||
GITHUB_EVENT_ACTION: eventJson.action || '',
|
||||
GITHUB_REF_NAME: process.env.GITHUB_REF_NAME || '',
|
||||
GITHUB_REF: process.env.GITHUB_REF || '',
|
||||
GITHUB_WORKSPACE: process.env.GITHUB_WORKSPACE || '',
|
||||
GITHUB_EVENT_NAME: process.env.GITHUB_EVENT_NAME || '',
|
||||
GITHUB_REPOSITORY_OWNER: process.env.GITHUB_REPOSITORY_OWNER || '',
|
||||
GITHUB_REPOSITORY: process.env.GITHUB_REPOSITORY || ''
|
||||
GITHUB_WORKSPACE: process.env.GITHUB_WORKSPACE || ''
|
||||
}
|
||||
}
|
||||
|
|
20
src/main.ts
20
src/main.ts
|
@ -1,4 +1,5 @@
|
|||
import * as core from '@actions/core'
|
||||
import * as github from '@actions/github'
|
||||
import path from 'path'
|
||||
import {
|
||||
getAllDiffFiles,
|
||||
|
@ -76,8 +77,8 @@ const getChangedFilesFromLocalGit = async ({
|
|||
|
||||
let diffResult: DiffResult
|
||||
|
||||
if (!env.GITHUB_EVENT_PULL_REQUEST_BASE_REF) {
|
||||
core.info(`Running on a ${env.GITHUB_EVENT_NAME || 'push'} event...`)
|
||||
if (!github.context.payload.pull_request?.base?.ref) {
|
||||
core.info(`Running on a ${github.context.eventName || 'push'} event...`)
|
||||
diffResult = await getSHAForPushEvent(
|
||||
inputs,
|
||||
env,
|
||||
|
@ -89,8 +90,8 @@ const getChangedFilesFromLocalGit = async ({
|
|||
)
|
||||
} else {
|
||||
core.info(
|
||||
`Running on a ${env.GITHUB_EVENT_NAME || 'pull_request'} (${
|
||||
env.GITHUB_EVENT_ACTION
|
||||
`Running on a ${github.context.eventName || 'pull_request'} (${
|
||||
github.context.payload.action
|
||||
}) event...`
|
||||
)
|
||||
diffResult = await getSHAForPullRequestEvent(
|
||||
|
@ -192,20 +193,17 @@ const getChangedFilesFromLocalGit = async ({
|
|||
|
||||
const getChangedFilesFromRESTAPI = async ({
|
||||
inputs,
|
||||
env,
|
||||
workingDirectory,
|
||||
filePatterns,
|
||||
yamlFilePatterns
|
||||
}: {
|
||||
inputs: Inputs
|
||||
env: Env
|
||||
workingDirectory: string
|
||||
filePatterns: string[]
|
||||
yamlFilePatterns: Record<string, string[]>
|
||||
}): Promise<void> => {
|
||||
const allDiffFiles = await getChangedFilesFromGithubAPI({
|
||||
inputs,
|
||||
env
|
||||
inputs
|
||||
})
|
||||
core.debug(`All diff files: ${JSON.stringify(allDiffFiles)}`)
|
||||
core.info('All Done!')
|
||||
|
@ -258,6 +256,9 @@ export async function run(): Promise<void> {
|
|||
const inputs = getInputs()
|
||||
core.debug(`Inputs: ${JSON.stringify(inputs, null, 2)}`)
|
||||
|
||||
const githubContext = github.context
|
||||
core.debug(`Github Context: ${JSON.stringify(githubContext, null, 2)}`)
|
||||
|
||||
const workingDirectory = path.resolve(
|
||||
env.GITHUB_WORKSPACE || process.cwd(),
|
||||
inputs.path
|
||||
|
@ -281,7 +282,7 @@ export async function run(): Promise<void> {
|
|||
|
||||
if (
|
||||
inputs.token &&
|
||||
env.GITHUB_EVENT_PULL_REQUEST_NUMBER &&
|
||||
github.context.payload.pull_request?.number &&
|
||||
!hasGitDirectory
|
||||
) {
|
||||
core.info("Using GitHub's REST API to get changed files")
|
||||
|
@ -305,7 +306,6 @@ export async function run(): Promise<void> {
|
|||
}
|
||||
await getChangedFilesFromRESTAPI({
|
||||
inputs,
|
||||
env,
|
||||
workingDirectory,
|
||||
filePatterns,
|
||||
yamlFilePatterns
|
||||
|
|
Loading…
Add table
Reference in a new issue