1
0
Fork 0
mirror of https://code.forgejo.org/actions/checkout.git synced 2024-11-27 22:49:17 +01:00
This commit is contained in:
eric sciple 2019-12-09 19:15:39 -05:00
parent d415b27760
commit 306dc1c898
4 changed files with 47 additions and 14 deletions

25
dist/index.js vendored
View file

@ -4439,6 +4439,9 @@ const fshelper = __importStar(__webpack_require__(618));
const io = __importStar(__webpack_require__(1)); const io = __importStar(__webpack_require__(1));
const path = __importStar(__webpack_require__(622)); const path = __importStar(__webpack_require__(622));
const git_version_1 = __webpack_require__(559); const git_version_1 = __webpack_require__(559);
// Auth header not supported before 2.9
// Wire protocol v2 not supported before 2.18
exports.MinimumGitVersion = new git_version_1.GitVersion('2.18');
function CreateCommandManager(workingDirectory, lfs) { function CreateCommandManager(workingDirectory, lfs) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
return yield GitCommandManager.createCommandManager(workingDirectory, lfs); return yield GitCommandManager.createCommandManager(workingDirectory, lfs);
@ -4719,12 +4722,8 @@ class GitCommandManager {
throw new Error('Unable to determine git version'); throw new Error('Unable to determine git version');
} }
// Minimum git version // Minimum git version
// Note: if (!gitVersion.checkMinimum(exports.MinimumGitVersion)) {
// - Auth header not supported before 2.9 throw new Error(`Minimum required git version is ${exports.MinimumGitVersion}. Your git ('${this.gitPath}') is ${gitVersion}`);
// - Wire protocol v2 not supported before 2.18
const minimumGitVersion = new git_version_1.GitVersion('2.18');
if (!gitVersion.checkMinimum(minimumGitVersion)) {
throw new Error(`Minimum required git version is ${minimumGitVersion}. Your git ('${this.gitPath}') is ${gitVersion}`);
} }
if (this.lfs) { if (this.lfs) {
// Git-lfs version // Git-lfs version
@ -4844,6 +4843,8 @@ function getSource(settings) {
yield prepareExistingDirectory(git, settings.repositoryPath, repositoryUrl, settings.clean); yield prepareExistingDirectory(git, settings.repositoryPath, repositoryUrl, settings.clean);
} }
if (!git || `${1}` == '1') { if (!git || `${1}` == '1') {
core.info(`Git version ${gitCommandManager.MinimumGitVersion} was not found in the PATH.`);
core.info(`Instead downloading the repository files using the GitHub REST API.`);
yield githubApiHelper.downloadRepository(settings.accessToken, settings.repositoryOwner, settings.repositoryName, settings.ref, settings.repositoryPath); yield githubApiHelper.downloadRepository(settings.accessToken, settings.repositoryOwner, settings.repositoryName, settings.ref, settings.repositoryPath);
} }
else { else {
@ -8087,7 +8088,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result; return result;
}; };
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
const assert = __importStar(__webpack_require__(357));
const exec = __importStar(__webpack_require__(986));
const fs = __importStar(__webpack_require__(747));
const github = __importStar(__webpack_require__(469)); const github = __importStar(__webpack_require__(469));
const path = __importStar(__webpack_require__(622));
const IS_WINDOWS = process.platform === 'win32'; const IS_WINDOWS = process.platform === 'win32';
function downloadRepository(accessToken, owner, repo, ref, repositoryPath) { function downloadRepository(accessToken, owner, repo, ref, repositoryPath) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
@ -8098,13 +8103,19 @@ function downloadRepository(accessToken, owner, repo, ref, repositoryPath) {
repo: repo, repo: repo,
ref: ref ref: ref
}; };
// todo: retry
const response = yield octokit.repos.getArchiveLink(params); const response = yield octokit.repos.getArchiveLink(params);
if (response.status != 200) { if (response.status != 200) {
throw new Error(`GitHub API call failed with response status '${response.status}': ${response.data}`); throw new Error(`Unexpected response from GitHub API. Status: '${response.status}'; Data: '${response.data}'`);
} }
console.log(`status=${response.status}`); console.log(`status=${response.status}`);
console.log(`headers=${JSON.stringify(response.headers)}`); console.log(`headers=${JSON.stringify(response.headers)}`);
console.log(`data=${JSON.stringify(typeof response.data)}`); console.log(`data=${JSON.stringify(typeof response.data)}`);
const runnerTemp = process.env['RUNNER_TEMP'];
assert.ok(runnerTemp, 'RUNNER_TEMP not defined');
const archiveFile = path.join(runnerTemp, 'checkout.tar.gz');
yield fs.promises.writeFile(archiveFile, response.data);
yield exec.exec(`tar -xzf "${archiveFile}"`, [], { cwd: repositoryPath });
}); });
} }
exports.downloadRepository = downloadRepository; exports.downloadRepository = downloadRepository;

View file

@ -5,6 +5,10 @@ import * as io from '@actions/io'
import * as path from 'path' import * as path from 'path'
import {GitVersion} from './git-version' import {GitVersion} from './git-version'
// Auth header not supported before 2.9
// Wire protocol v2 not supported before 2.18
export const MinimumGitVersion = new GitVersion('2.18')
export interface IGitCommandManager { export interface IGitCommandManager {
branchDelete(remote: boolean, branch: string): Promise<void> branchDelete(remote: boolean, branch: string): Promise<void>
branchExists(remote: boolean, pattern: string): Promise<boolean> branchExists(remote: boolean, pattern: string): Promise<boolean>
@ -338,13 +342,9 @@ class GitCommandManager {
} }
// Minimum git version // Minimum git version
// Note: if (!gitVersion.checkMinimum(MinimumGitVersion)) {
// - Auth header not supported before 2.9
// - Wire protocol v2 not supported before 2.18
const minimumGitVersion = new GitVersion('2.18')
if (!gitVersion.checkMinimum(minimumGitVersion)) {
throw new Error( throw new Error(
`Minimum required git version is ${minimumGitVersion}. Your git ('${this.gitPath}') is ${gitVersion}` `Minimum required git version is ${MinimumGitVersion}. Your git ('${this.gitPath}') is ${gitVersion}`
) )
} }

View file

@ -79,6 +79,12 @@ export async function getSource(settings: ISourceSettings): Promise<void> {
} }
if (!git || `${1}` == '1') { if (!git || `${1}` == '1') {
core.info(
`Git version ${gitCommandManager.MinimumGitVersion} was not found in the PATH.`
)
core.info(
`Instead downloading the repository files using the GitHub REST API.`
)
await githubApiHelper.downloadRepository( await githubApiHelper.downloadRepository(
settings.accessToken, settings.accessToken,
settings.repositoryOwner, settings.repositoryOwner,

View file

@ -1,5 +1,13 @@
import * as assert from 'assert'
import * as core from '@actions/core'
import * as exec from '@actions/exec'
import * as fs from 'fs'
import * as github from '@actions/github' import * as github from '@actions/github'
import * as io from '@actions/io'
import * as path from 'path'
import {ReposGetArchiveLinkParams} from '@octokit/rest' import {ReposGetArchiveLinkParams} from '@octokit/rest'
import {defaultCoreCipherList} from 'constants'
import {ExecOptions} from '@actions/exec/lib/interfaces'
const IS_WINDOWS = process.platform === 'win32' const IS_WINDOWS = process.platform === 'win32'
@ -17,13 +25,21 @@ export async function downloadRepository(
repo: repo, repo: repo,
ref: ref ref: ref
} }
// todo: retry
const response = await octokit.repos.getArchiveLink(params) const response = await octokit.repos.getArchiveLink(params)
if (response.status != 200) { if (response.status != 200) {
throw new Error( throw new Error(
`GitHub API call failed with response status '${response.status}': ${response.data}` `Unexpected response from GitHub API. Status: '${response.status}'; Data: '${response.data}'`
) )
} }
console.log(`status=${response.status}`) console.log(`status=${response.status}`)
console.log(`headers=${JSON.stringify(response.headers)}`) console.log(`headers=${JSON.stringify(response.headers)}`)
console.log(`data=${JSON.stringify(typeof response.data)}`) console.log(`data=${JSON.stringify(typeof response.data)}`)
const runnerTemp = process.env['RUNNER_TEMP'] as string
assert.ok(runnerTemp, 'RUNNER_TEMP not defined')
const archiveFile = path.join(runnerTemp, 'checkout.tar.gz')
await fs.promises.writeFile(archiveFile, response.data)
await exec.exec(`tar -xzf "${archiveFile}"`, [], {
cwd: repositoryPath
} as ExecOptions)
} }