Compare commits

...

9 Commits

Author SHA1 Message Date
Tonye Jack
9ecc6e7fe2 fix: bug with retrieving the base sha when since last commit is enabled (#1213)
Co-authored-by: GitHub Action <action@github.com>
2023-06-01 11:18:54 -06:00
tj-actions[bot]
72cf8893fc Upgraded to v36.0.13 (#1212)
Co-authored-by: jackton1 <jackton1@users.noreply.github.com>
Co-authored-by: Tonye Jack <jtonye@ymail.com>
2023-06-01 11:02:57 -06:00
tj-actions[bot]
28d6f2964c Upgraded to v36.0.12 (#1210)
Co-authored-by: jackton1 <jackton1@users.noreply.github.com>
Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
2023-06-01 16:53:31 +00:00
Tonye Jack
8c9ee56d01 fix: error fetching history (#1211)
Co-authored-by: GitHub Action <action@github.com>
2023-06-01 10:34:16 -06:00
Tonye Jack
5978e5a2df fix: bug retrieving diff when persist credentials is false (#1209)
Co-authored-by: GitHub Action <action@github.com>
2023-06-01 10:03:09 -06:00
tj-actions[bot]
ab45871481 Upgraded to v36.0.11 (#1208)
Co-authored-by: jackton1 <jackton1@users.noreply.github.com>
2023-05-31 21:44:30 +00:00
Tonye Jack
17c3e9e98f chore: update test to include pull request head sha checkout (#1205) 2023-05-31 21:26:08 +00:00
renovate[bot]
c9dcbc3147 chore(deps): update dependency @types/jest to v29.5.2 (#1207)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-05-31 17:13:16 +00:00
tj-actions[bot]
aa54931d1d Upgraded to v36.0.10 (#1202)
Co-authored-by: jackton1 <jackton1@users.noreply.github.com>
2023-05-30 21:50:01 +00:00
8 changed files with 6039 additions and 5944 deletions

View File

@@ -316,6 +316,66 @@ jobs:
shell:
bash
test-pull-request-head-ref:
name: Test changed-files with pull request head ref
runs-on: ubuntu-latest
needs: build
if: github.event_name != 'push'
steps:
- name: Checkout to branch
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Download build assets
uses: actions/download-artifact@v3
with:
name: build-assets
- name: Run changed-files
id: changed-files
uses: ./
- name: Show output
run: |
echo '${{ toJSON(steps.changed-files.outputs) }}'
shell:
bash
test-pull-request-without-persist-credentials:
name: Test changed-files with pull request without persist credentials
runs-on: ubuntu-latest
needs: build
if: github.event_name != 'push'
strategy:
fail-fast: false
max-parallel: 4
matrix:
fetch-depth: [1, 2, 0]
steps:
- name: Checkout to branch
uses: actions/checkout@v3
with:
fetch-depth: ${{ matrix.fetch-depth }}
persist-credentials: false
- name: Download build assets
uses: actions/download-artifact@v3
with:
name: build-assets
- name: Run changed-files
id: changed-files
uses: ./
- name: Show output
run: |
echo '${{ toJSON(steps.changed-files.outputs) }}'
shell:
bash
test-non-existent-base-sha:
name: Test changed-files non existent base sha
runs-on: ubuntu-latest

11831
HISTORY.md

File diff suppressed because it is too large Load Diff

36
dist/index.js generated vendored
View File

@@ -356,7 +356,7 @@ const getSHAForPullRequestEvent = (inputs, env, workingDirectory, isShallow, has
}
if (isShallow) {
core.info('Repository is shallow, fetching more history...');
const prFetchExitCode = yield (0, utils_1.gitFetch)({
let prFetchExitCode = yield (0, utils_1.gitFetch)({
cwd: workingDirectory,
args: [
...gitExtraArgs,
@@ -367,7 +367,7 @@ const getSHAForPullRequestEvent = (inputs, env, workingDirectory, isShallow, has
]
});
if (prFetchExitCode !== 0) {
yield (0, utils_1.gitFetch)({
prFetchExitCode = yield (0, utils_1.gitFetch)({
cwd: workingDirectory,
args: [
...gitExtraArgs,
@@ -379,6 +379,9 @@ const getSHAForPullRequestEvent = (inputs, env, workingDirectory, isShallow, has
]
});
}
if (prFetchExitCode !== 0) {
throw new Error('Failed to fetch pull request branch. Please ensure "persist-credentials" is set to "true" when checking out the repository. See: https://github.com/actions/checkout#usage');
}
if (!inputs.sinceLastRemoteCommit) {
core.debug('Fetching target branch...');
yield (0, utils_1.gitFetch)({
@@ -433,23 +436,16 @@ const getSHAForPullRequestEvent = (inputs, env, workingDirectory, isShallow, has
if (inputs.sinceLastRemoteCommit) {
previousSha = env.GITHUB_EVENT_BEFORE;
if (!previousSha) {
previousSha = yield (0, utils_1.gitLsRemote)({
cwd: workingDirectory,
args: [currentBranch]
});
previousSha = yield (0, utils_1.getParentSha)({ cwd: workingDirectory });
}
if ((yield (0, utils_1.verifyCommitSha)({
sha: previousSha,
cwd: workingDirectory,
showAsErrorMessage: false
})) !== 0) {
if (!previousSha) {
previousSha = env.GITHUB_EVENT_PULL_REQUEST_BASE_SHA;
}
}
else {
previousSha = yield (0, utils_1.gitLsRemote)({
previousSha = yield (0, utils_1.getRemoteBranchHeadSha)({
cwd: workingDirectory,
args: [targetBranch]
branch: targetBranch
});
if (!previousSha) {
previousSha = env.GITHUB_EVENT_PULL_REQUEST_BASE_SHA;
@@ -1169,7 +1165,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.setOutput = exports.getFilePatterns = exports.jsonOutput = exports.getDirnameMaxDepth = exports.canDiffCommits = exports.getPreviousGitTag = exports.verifyCommitSha = exports.getParentSha = exports.gitLsRemote = exports.getHeadSha = exports.gitLog = exports.gitDiff = exports.gitRenamedFiles = exports.gitSubmoduleDiffSHA = exports.getSubmodulePath = exports.gitFetchSubmodules = exports.gitFetch = exports.submoduleExists = exports.isRepoShallow = exports.updateGitGlobalConfig = exports.verifyMinimumGitVersion = void 0;
exports.setOutput = exports.getFilePatterns = exports.jsonOutput = exports.getDirnameMaxDepth = exports.canDiffCommits = exports.getPreviousGitTag = exports.verifyCommitSha = exports.getParentSha = exports.getRemoteBranchHeadSha = exports.getHeadSha = exports.gitLog = exports.gitDiff = exports.gitRenamedFiles = exports.gitSubmoduleDiffSHA = exports.getSubmodulePath = exports.gitFetchSubmodules = exports.gitFetch = exports.submoduleExists = exports.isRepoShallow = exports.updateGitGlobalConfig = exports.verifyMinimumGitVersion = void 0;
/*global AsyncIterableIterator*/
const core = __importStar(__nccwpck_require__(2186));
const exec = __importStar(__nccwpck_require__(1514));
@@ -1520,18 +1516,14 @@ const getHeadSha = ({ cwd }) => __awaiter(void 0, void 0, void 0, function* () {
return stdout.trim();
});
exports.getHeadSha = getHeadSha;
const gitLsRemote = ({ cwd, args }) => __awaiter(void 0, void 0, void 0, function* () {
const { stdout } = yield exec.getExecOutput('git', ['ls-remote', 'origin', ...args], {
const getRemoteBranchHeadSha = ({ cwd, branch }) => __awaiter(void 0, void 0, void 0, function* () {
const { stdout } = yield exec.getExecOutput('git', ['rev-parse', `origin/${branch}`], {
cwd,
silent: process.env.RUNNER_DEBUG !== '1'
});
const output = stdout.trim().split('\t');
if (output.length === 0) {
throw new Error('No output returned from git ls-remote');
}
return output[0];
return stdout.trim();
});
exports.gitLsRemote = gitLsRemote;
exports.getRemoteBranchHeadSha = getRemoteBranchHeadSha;
const getParentSha = ({ cwd }) => __awaiter(void 0, void 0, void 0, function* () {
const { stdout, exitCode } = yield exec.getExecOutput('git', ['rev-list', '-n', '1', 'HEAD^'], {
cwd,

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View File

@@ -37,7 +37,7 @@
"micromatch": "^4.0.5"
},
"devDependencies": {
"@types/jest": "29.5.1",
"@types/jest": "29.5.2",
"@types/micromatch": "^4.0.2",
"@types/node": "20.2.1",
"@types/uuid": "9.0.1",

View File

@@ -7,10 +7,10 @@ import {
getHeadSha,
getParentSha,
getPreviousGitTag,
getRemoteBranchHeadSha,
gitFetch,
gitFetchSubmodules,
gitLog,
gitLsRemote,
verifyCommitSha
} from './utils'
@@ -261,7 +261,7 @@ export const getSHAForPullRequestEvent = async (
if (isShallow) {
core.info('Repository is shallow, fetching more history...')
const prFetchExitCode = await gitFetch({
let prFetchExitCode = await gitFetch({
cwd: workingDirectory,
args: [
...gitExtraArgs,
@@ -273,7 +273,7 @@ export const getSHAForPullRequestEvent = async (
})
if (prFetchExitCode !== 0) {
await gitFetch({
prFetchExitCode = await gitFetch({
cwd: workingDirectory,
args: [
...gitExtraArgs,
@@ -286,6 +286,12 @@ export const getSHAForPullRequestEvent = async (
})
}
if (prFetchExitCode !== 0) {
throw new Error(
'Failed to fetch pull request branch. Please ensure "persist-credentials" is set to "true" when checking out the repository. See: https://github.com/actions/checkout#usage'
)
}
if (!inputs.sinceLastRemoteCommit) {
core.debug('Fetching target branch...')
await gitFetch({
@@ -354,25 +360,16 @@ export const getSHAForPullRequestEvent = async (
previousSha = env.GITHUB_EVENT_BEFORE
if (!previousSha) {
previousSha = await gitLsRemote({
cwd: workingDirectory,
args: [currentBranch]
})
previousSha = await getParentSha({cwd: workingDirectory})
}
if (
(await verifyCommitSha({
sha: previousSha,
cwd: workingDirectory,
showAsErrorMessage: false
})) !== 0
) {
if (!previousSha) {
previousSha = env.GITHUB_EVENT_PULL_REQUEST_BASE_SHA
}
} else {
previousSha = await gitLsRemote({
previousSha = await getRemoteBranchHeadSha({
cwd: workingDirectory,
args: [targetBranch]
branch: targetBranch
})
if (!previousSha) {

View File

@@ -501,28 +501,23 @@ export const getHeadSha = async ({cwd}: {cwd: string}): Promise<string> => {
return stdout.trim()
}
export const gitLsRemote = async ({
export const getRemoteBranchHeadSha = async ({
cwd,
args
branch
}: {
cwd: string
args: string[]
branch: string
}): Promise<string> => {
const {stdout} = await exec.getExecOutput(
'git',
['ls-remote', 'origin', ...args],
['rev-parse', `origin/${branch}`],
{
cwd,
silent: process.env.RUNNER_DEBUG !== '1'
}
)
const output = stdout.trim().split('\t')
if (output.length === 0) {
throw new Error('No output returned from git ls-remote')
}
return output[0]
return stdout.trim()
}
export const getParentSha = async ({cwd}: {cwd: string}): Promise<string> => {

View File

@@ -738,10 +738,10 @@
dependencies:
"@types/istanbul-lib-report" "*"
"@types/jest@29.5.1":
version "29.5.1"
resolved "https://registry.yarnpkg.com/@types/jest/-/jest-29.5.1.tgz#83c818aa9a87da27d6da85d3378e5a34d2f31a47"
integrity sha512-tEuVcHrpaixS36w7hpsfLBLpjtMRJUE09/MHXn923LOVojDwyC14cWcfc0rDs0VEfUyYmt/+iX1kxxp+gZMcaQ==
"@types/jest@29.5.2":
version "29.5.2"
resolved "https://registry.yarnpkg.com/@types/jest/-/jest-29.5.2.tgz#86b4afc86e3a8f3005b297ed8a72494f89e6395b"
integrity sha512-mSoZVJF5YzGVCk+FsDxzDuH7s+SCkzrgKZzf0Z0T2WudhBUPoF6ktoTPC4R0ZoCPCV5xUvuU6ias5NvxcBcMMg==
dependencies:
expect "^29.0.0"
pretty-format "^29.0.0"