diff --git a/__test__/git-auth-helper.test.ts b/__test__/git-auth-helper.test.ts index 026be7c..1d5c3d5 100644 --- a/__test__/git-auth-helper.test.ts +++ b/__test__/git-auth-helper.test.ts @@ -725,7 +725,6 @@ async function setup(testName: string): Promise { setEnvironmentVariable: jest.fn((name: string, value: string) => { git.env[name] = value }), - setRemoteUrl: jest.fn(), submoduleForeach: jest.fn(async () => { return '' }), @@ -749,7 +748,7 @@ async function setup(testName: string): Promise { } ), tryDisableAutomaticGarbageCollection: jest.fn(), - tryGetRemoteUrl: jest.fn(), + tryGetFetchUrl: jest.fn(), tryReset: jest.fn() } @@ -758,7 +757,6 @@ async function setup(testName: string): Promise { clean: true, commit: '', fetchDepth: 1, - isWorkflowRepository: true, lfs: false, submodules: false, nestedSubmodules: false, diff --git a/__test__/git-directory-helper.test.ts b/__test__/git-directory-helper.test.ts index 22f3767..c39a2a5 100644 --- a/__test__/git-directory-helper.test.ts +++ b/__test__/git-directory-helper.test.ts @@ -7,8 +7,7 @@ import {IGitCommandManager} from '../lib/git-command-manager' const testWorkspace = path.join(__dirname, '_temp', 'git-directory-helper') let repositoryPath: string -let httpsUrl: string -let sshUrl: string +let repositoryUrl: string let clean: boolean let git: IGitCommandManager @@ -41,8 +40,7 @@ describe('git-directory-helper tests', () => { await gitDirectoryHelper.prepareExistingDirectory( git, repositoryPath, - httpsUrl, - [httpsUrl, sshUrl], + repositoryUrl, clean ) @@ -64,8 +62,7 @@ describe('git-directory-helper tests', () => { await gitDirectoryHelper.prepareExistingDirectory( git, repositoryPath, - httpsUrl, - [httpsUrl, sshUrl], + repositoryUrl, clean ) @@ -90,8 +87,7 @@ describe('git-directory-helper tests', () => { await gitDirectoryHelper.prepareExistingDirectory( git, repositoryPath, - httpsUrl, - [httpsUrl, sshUrl], + repositoryUrl, clean ) @@ -112,8 +108,7 @@ describe('git-directory-helper tests', () => { await gitDirectoryHelper.prepareExistingDirectory( git, repositoryPath, - httpsUrl, - [httpsUrl, sshUrl], + repositoryUrl, clean ) @@ -141,8 +136,7 @@ describe('git-directory-helper tests', () => { await gitDirectoryHelper.prepareExistingDirectory( git, repositoryPath, - httpsUrl, - [httpsUrl, sshUrl], + repositoryUrl, clean ) @@ -161,15 +155,14 @@ describe('git-directory-helper tests', () => { await setup(removesContentsWhenDifferentRepositoryUrl) clean = false await fs.promises.writeFile(path.join(repositoryPath, 'my-file'), '') - const differentRemoteUrl = + const differentRepositoryUrl = 'https://github.com/my-different-org/my-different-repo' // Act await gitDirectoryHelper.prepareExistingDirectory( git, repositoryPath, - differentRemoteUrl, - [differentRemoteUrl], + differentRepositoryUrl, clean ) @@ -193,8 +186,7 @@ describe('git-directory-helper tests', () => { await gitDirectoryHelper.prepareExistingDirectory( git, repositoryPath, - httpsUrl, - [httpsUrl, sshUrl], + repositoryUrl, clean ) @@ -219,8 +211,7 @@ describe('git-directory-helper tests', () => { await gitDirectoryHelper.prepareExistingDirectory( git, repositoryPath, - httpsUrl, - [httpsUrl, sshUrl], + repositoryUrl, clean ) @@ -244,8 +235,7 @@ describe('git-directory-helper tests', () => { await gitDirectoryHelper.prepareExistingDirectory( undefined, repositoryPath, - httpsUrl, - [httpsUrl, sshUrl], + repositoryUrl, clean ) @@ -269,8 +259,7 @@ describe('git-directory-helper tests', () => { await gitDirectoryHelper.prepareExistingDirectory( git, repositoryPath, - httpsUrl, - [httpsUrl, sshUrl], + repositoryUrl, clean ) @@ -300,8 +289,7 @@ describe('git-directory-helper tests', () => { await gitDirectoryHelper.prepareExistingDirectory( git, repositoryPath, - httpsUrl, - [httpsUrl, sshUrl], + repositoryUrl, clean ) @@ -331,8 +319,7 @@ describe('git-directory-helper tests', () => { await gitDirectoryHelper.prepareExistingDirectory( git, repositoryPath, - httpsUrl, - [httpsUrl, sshUrl], + repositoryUrl, clean ) @@ -342,30 +329,6 @@ describe('git-directory-helper tests', () => { expect(git.branchDelete).toHaveBeenCalledWith(true, 'remote-branch-1') expect(git.branchDelete).toHaveBeenCalledWith(true, 'remote-branch-2') }) - - const updatesRemoteUrl = 'updates remote URL' - it(updatesRemoteUrl, async () => { - // Arrange - await setup(updatesRemoteUrl) - await fs.promises.writeFile(path.join(repositoryPath, 'my-file'), '') - - // Act - await gitDirectoryHelper.prepareExistingDirectory( - git, - repositoryPath, - sshUrl, - [sshUrl, httpsUrl], - clean - ) - - // Assert - const files = await fs.promises.readdir(repositoryPath) - expect(files.sort()).toEqual(['.git', 'my-file']) - expect(git.isDetached).toHaveBeenCalled() - expect(git.branchList).toHaveBeenCalled() - expect(core.warning).not.toHaveBeenCalled() - expect(git.setRemoteUrl).toHaveBeenCalledWith(sshUrl) - }) }) async function setup(testName: string): Promise { @@ -375,9 +338,8 @@ async function setup(testName: string): Promise { repositoryPath = path.join(testWorkspace, testName) await fs.promises.mkdir(path.join(repositoryPath, '.git'), {recursive: true}) - // Remote URLs - httpsUrl = 'https://github.com/my-org/my-repo' - sshUrl = 'git@github.com:my-org/my-repo' + // Repository URL + repositoryUrl = 'https://github.com/my-org/my-repo' // Clean clean = true @@ -403,7 +365,6 @@ async function setup(testName: string): Promise { remoteAdd: jest.fn(), removeEnvironmentVariable: jest.fn(), setEnvironmentVariable: jest.fn(), - setRemoteUrl: jest.fn(), submoduleForeach: jest.fn(), submoduleSync: jest.fn(), submoduleUpdate: jest.fn(), @@ -413,10 +374,10 @@ async function setup(testName: string): Promise { }), tryConfigUnset: jest.fn(), tryDisableAutomaticGarbageCollection: jest.fn(), - tryGetRemoteUrl: jest.fn(async () => { + tryGetFetchUrl: jest.fn(async () => { // Sanity check - this function shouldn't be called when the .git directory doesn't exist await fs.promises.stat(path.join(repositoryPath, '.git')) - return httpsUrl + return repositoryUrl }), tryReset: jest.fn(async () => { return true diff --git a/dist/index.js b/dist/index.js index 77b3691..3992650 100644 --- a/dist/index.js +++ b/dist/index.js @@ -5225,7 +5225,7 @@ class GitAuthHelper { } removeGlobalAuth() { return __awaiter(this, void 0, void 0, function* () { - core.debug(`Unsetting HOME override`); + core.info(`Unsetting HOME override`); this.git.removeEnvironmentVariable('HOME'); yield io.rmRF(this.temporaryHomePath); }); @@ -5581,11 +5581,6 @@ class GitCommandManager { setEnvironmentVariable(name, value) { this.gitEnv[name] = value; } - setRemoteUrl(value) { - return __awaiter(this, void 0, void 0, function* () { - yield this.config('git.remote.url', value); - }); - } submoduleForeach(command, recursive) { return __awaiter(this, void 0, void 0, function* () { const args = ['submodule', 'foreach']; @@ -5648,7 +5643,7 @@ class GitCommandManager { return output.exitCode === 0; }); } - tryGetRemoteUrl() { + tryGetFetchUrl() { return __awaiter(this, void 0, void 0, function* () { const output = yield this.execGit(['config', '--local', '--get', 'remote.origin.url'], true); if (output.exitCode !== 0) { @@ -5805,12 +5800,11 @@ const stateHelper = __importStar(__webpack_require__(153)); const hostname = 'github.com'; function getSource(settings) { return __awaiter(this, void 0, void 0, function* () { + // Repository URL core.info(`Syncing repository: ${settings.repositoryOwner}/${settings.repositoryName}`); - // Remote URL - const httpsUrl = `https://${hostname}/${encodeURIComponent(settings.repositoryOwner)}/${encodeURIComponent(settings.repositoryName)}`; - const sshUrl = `git@${hostname}:${encodeURIComponent(settings.repositoryOwner)}/${encodeURIComponent(settings.repositoryName)}.git`; - // Always fetch the workflow repository using the token, not the SSH key - const initialRemoteUrl = !settings.sshKey || settings.isWorkflowRepository ? httpsUrl : sshUrl; + const repositoryUrl = settings.sshKey + ? `git@${hostname}:${encodeURIComponent(settings.repositoryOwner)}/${encodeURIComponent(settings.repositoryName)}.git` + : `https://${hostname}/${encodeURIComponent(settings.repositoryOwner)}/${encodeURIComponent(settings.repositoryName)}`; // Remove conflicting file path if (fsHelper.fileExistsSync(settings.repositoryPath)) { yield io.rmRF(settings.repositoryPath); @@ -5822,12 +5816,10 @@ function getSource(settings) { yield io.mkdirP(settings.repositoryPath); } // Git command manager - core.startGroup('Getting Git version info'); const git = yield getGitCommandManager(settings); - core.endGroup(); // Prepare existing directory, otherwise recreate if (isExisting) { - yield gitDirectoryHelper.prepareExistingDirectory(git, settings.repositoryPath, initialRemoteUrl, [httpsUrl, sshUrl], settings.clean); + yield gitDirectoryHelper.prepareExistingDirectory(git, settings.repositoryPath, repositoryUrl, settings.clean); } if (!git) { // Downloading using REST API @@ -5846,72 +5838,46 @@ function getSource(settings) { stateHelper.setRepositoryPath(settings.repositoryPath); // Initialize the repository if (!fsHelper.directoryExistsSync(path.join(settings.repositoryPath, '.git'))) { - core.startGroup('Initializing the repository'); yield git.init(); - yield git.remoteAdd('origin', initialRemoteUrl); - core.endGroup(); + yield git.remoteAdd('origin', repositoryUrl); } // Disable automatic garbage collection - core.startGroup('Disabling automatic garbage collection'); if (!(yield git.tryDisableAutomaticGarbageCollection())) { core.warning(`Unable to turn off git automatic garbage collection. The git fetch operation may trigger garbage collection and cause a delay.`); } - core.endGroup(); const authHelper = gitAuthHelper.createAuthHelper(git, settings); try { // Configure auth - core.startGroup('Setting up auth'); yield authHelper.configureAuth(); - core.endGroup(); // LFS install if (settings.lfs) { yield git.lfsInstall(); } // Fetch - core.startGroup('Fetching the repository'); const refSpec = refHelper.getRefSpec(settings.ref, settings.commit); yield git.fetch(settings.fetchDepth, refSpec); - core.endGroup(); // Checkout info - core.startGroup('Determining the checkout info'); const checkoutInfo = yield refHelper.getCheckoutInfo(git, settings.ref, settings.commit); - core.endGroup(); // LFS fetch // Explicit lfs-fetch to avoid slow checkout (fetches one lfs object at a time). // Explicit lfs fetch will fetch lfs objects in parallel. if (settings.lfs) { - core.startGroup('Fetching LFS objects'); yield git.lfsFetch(checkoutInfo.startPoint || checkoutInfo.ref); - core.endGroup(); - } - // Fix URL when using SSH - if (settings.sshKey && initialRemoteUrl !== sshUrl) { - core.startGroup('Updating the remote URL'); - yield git.setRemoteUrl(sshUrl); - core.endGroup(); } // Checkout - core.startGroup('Checking out the ref'); yield git.checkout(checkoutInfo.ref, checkoutInfo.startPoint); - core.endGroup(); // Submodules if (settings.submodules) { try { // Temporarily override global config - core.startGroup('Setting up auth for fetching submodules'); yield authHelper.configureGlobalAuth(); - core.endGroup(); // Checkout submodules - core.startGroup('Fetching submodules'); yield git.submoduleSync(settings.nestedSubmodules); yield git.submoduleUpdate(settings.fetchDepth, settings.nestedSubmodules); yield git.submoduleForeach('git config --local gc.auto 0', settings.nestedSubmodules); - core.endGroup(); // Persist credentials if (settings.persistCredentials) { - core.startGroup('Persisting credentials for submodules'); yield authHelper.configureSubmoduleAuth(); - core.endGroup(); } } finally { @@ -5925,9 +5891,7 @@ function getSource(settings) { finally { // Remove auth if (!settings.persistCredentials) { - core.startGroup('Removing auth'); yield authHelper.removeAuth(); - core.endGroup(); } } }); @@ -7227,29 +7191,21 @@ var __importStar = (this && this.__importStar) || function (mod) { return result; }; Object.defineProperty(exports, "__esModule", { value: true }); -const assert = __importStar(__webpack_require__(357)); const core = __importStar(__webpack_require__(470)); const fs = __importStar(__webpack_require__(747)); const fsHelper = __importStar(__webpack_require__(618)); const io = __importStar(__webpack_require__(1)); const path = __importStar(__webpack_require__(622)); -function prepareExistingDirectory(git, repositoryPath, preferredRemoteUrl, allowedRemoteUrls, clean) { +function prepareExistingDirectory(git, repositoryPath, repositoryUrl, clean) { return __awaiter(this, void 0, void 0, function* () { - assert.ok(repositoryPath, 'Expected repositoryPath to be defined'); - assert.ok(preferredRemoteUrl, 'Expected preferredRemoteUrl to be defined'); - assert.ok(allowedRemoteUrls, 'Expected allowedRemoteUrls to be defined'); - assert.ok(allowedRemoteUrls.length, 'Expected allowedRemoteUrls to have at least one value'); - // Indicates whether to delete the directory contents let remove = false; - // The remote URL - let remoteUrl; // Check whether using git or REST API if (!git) { remove = true; } // Fetch URL does not match else if (!fsHelper.directoryExistsSync(path.join(repositoryPath, '.git')) || - allowedRemoteUrls.indexOf((remoteUrl = yield git.tryGetRemoteUrl())) < 0) { + repositoryUrl !== (yield git.tryGetFetchUrl())) { remove = true; } else { @@ -7267,7 +7223,6 @@ function prepareExistingDirectory(git, repositoryPath, preferredRemoteUrl, allow } } try { - core.startGroup('Removing previously created refs, to avoid conflicts'); // Checkout detached HEAD if (!(yield git.isDetached())) { yield git.checkoutDetach(); @@ -7282,10 +7237,8 @@ function prepareExistingDirectory(git, repositoryPath, preferredRemoteUrl, allow for (const branch of branches) { yield git.branchDelete(true, branch); } - core.endGroup(); // Clean if (clean) { - core.startGroup('Cleaning the repository'); if (!(yield git.tryClean())) { core.debug(`The clean command failed. This might be caused by: 1) path too long, 2) permission issue, or 3) file in use. For futher investigation, manually run 'git clean -ffdx' on the directory '${repositoryPath}'.`); remove = true; @@ -7293,17 +7246,10 @@ function prepareExistingDirectory(git, repositoryPath, preferredRemoteUrl, allow else if (!(yield git.tryReset())) { remove = true; } - core.endGroup(); if (remove) { core.warning(`Unable to clean or reset the repository. The repository will be recreated instead.`); } } - // Update to the preferred remote URL - if (remoteUrl !== preferredRemoteUrl) { - core.startGroup('Updating the remote URL'); - yield git.setRemoteUrl(preferredRemoteUrl); - core.endGroup(); - } } catch (error) { core.warning(`Unable to prepare the existing repository. The repository will be recreated instead.`); @@ -14043,7 +13989,6 @@ const core = __importStar(__webpack_require__(470)); const fsHelper = __importStar(__webpack_require__(618)); const github = __importStar(__webpack_require__(469)); const path = __importStar(__webpack_require__(622)); -const hostname = 'github.com'; function getInputs() { const result = {}; // GitHub workspace @@ -14073,13 +14018,12 @@ function getInputs() { throw new Error(`Repository path '${result.repositoryPath}' is not under '${githubWorkspacePath}'`); } // Workflow repository? - result.isWorkflowRepository = - qualifiedRepository.toUpperCase() === - `${github.context.repo.owner}/${github.context.repo.repo}`.toUpperCase(); + const isWorkflowRepository = qualifiedRepository.toUpperCase() === + `${github.context.repo.owner}/${github.context.repo.repo}`.toUpperCase(); // Source branch, source version result.ref = core.getInput('ref'); if (!result.ref) { - if (result.isWorkflowRepository) { + if (isWorkflowRepository) { result.ref = github.context.ref; result.commit = github.context.sha; // Some events have an unqualifed ref. For example when a PR is merged (pull_request closed event), diff --git a/src/git-auth-helper.ts b/src/git-auth-helper.ts index c4be3ab..06e8912 100644 --- a/src/git-auth-helper.ts +++ b/src/git-auth-helper.ts @@ -167,7 +167,7 @@ class GitAuthHelper { } async removeGlobalAuth(): Promise { - core.debug(`Unsetting HOME override`) + core.info(`Unsetting HOME override`) this.git.removeEnvironmentVariable('HOME') await io.rmRF(this.temporaryHomePath) } diff --git a/src/git-command-manager.ts b/src/git-command-manager.ts index a874e35..4cbfe4a 100644 --- a/src/git-command-manager.ts +++ b/src/git-command-manager.ts @@ -33,7 +33,6 @@ export interface IGitCommandManager { remoteAdd(remoteName: string, remoteUrl: string): Promise removeEnvironmentVariable(name: string): void setEnvironmentVariable(name: string, value: string): void - setRemoteUrl(url: string): Promise submoduleForeach(command: string, recursive: boolean): Promise submoduleSync(recursive: boolean): Promise submoduleUpdate(fetchDepth: number, recursive: boolean): Promise @@ -41,7 +40,7 @@ export interface IGitCommandManager { tryClean(): Promise tryConfigUnset(configKey: string, globalConfig?: boolean): Promise tryDisableAutomaticGarbageCollection(): Promise - tryGetRemoteUrl(): Promise + tryGetFetchUrl(): Promise tryReset(): Promise } @@ -242,10 +241,6 @@ class GitCommandManager { this.gitEnv[name] = value } - async setRemoteUrl(value: string): Promise { - await this.config('git.remote.url', value) - } - async submoduleForeach(command: string, recursive: boolean): Promise { const args = ['submodule', 'foreach'] if (recursive) { @@ -314,7 +309,7 @@ class GitCommandManager { return output.exitCode === 0 } - async tryGetRemoteUrl(): Promise { + async tryGetFetchUrl(): Promise { const output = await this.execGit( ['config', '--local', '--get', 'remote.origin.url'], true diff --git a/src/git-directory-helper.ts b/src/git-directory-helper.ts index c56a2fa..bfaa4a9 100644 --- a/src/git-directory-helper.ts +++ b/src/git-directory-helper.ts @@ -1,33 +1,18 @@ -import * as assert from 'assert' import * as core from '@actions/core' import * as fs from 'fs' import * as fsHelper from './fs-helper' import * as io from '@actions/io' import * as path from 'path' import {IGitCommandManager} from './git-command-manager' -import {IGitSourceSettings} from './git-source-settings' export async function prepareExistingDirectory( git: IGitCommandManager | undefined, repositoryPath: string, - preferredRemoteUrl: string, - allowedRemoteUrls: string[], + repositoryUrl: string, clean: boolean ): Promise { - assert.ok(repositoryPath, 'Expected repositoryPath to be defined') - assert.ok(preferredRemoteUrl, 'Expected preferredRemoteUrl to be defined') - assert.ok(allowedRemoteUrls, 'Expected allowedRemoteUrls to be defined') - assert.ok( - allowedRemoteUrls.length, - 'Expected allowedRemoteUrls to have at least one value' - ) - - // Indicates whether to delete the directory contents let remove = false - // The remote URL - let remoteUrl: string - // Check whether using git or REST API if (!git) { remove = true @@ -35,7 +20,7 @@ export async function prepareExistingDirectory( // Fetch URL does not match else if ( !fsHelper.directoryExistsSync(path.join(repositoryPath, '.git')) || - allowedRemoteUrls.indexOf((remoteUrl = await git.tryGetRemoteUrl())) < 0 + repositoryUrl !== (await git.tryGetFetchUrl()) ) { remove = true } else { @@ -53,7 +38,6 @@ export async function prepareExistingDirectory( } try { - core.startGroup('Removing previously created refs, to avoid conflicts') // Checkout detached HEAD if (!(await git.isDetached())) { await git.checkoutDetach() @@ -70,11 +54,9 @@ export async function prepareExistingDirectory( for (const branch of branches) { await git.branchDelete(true, branch) } - core.endGroup() // Clean if (clean) { - core.startGroup('Cleaning the repository') if (!(await git.tryClean())) { core.debug( `The clean command failed. This might be caused by: 1) path too long, 2) permission issue, or 3) file in use. For futher investigation, manually run 'git clean -ffdx' on the directory '${repositoryPath}'.` @@ -83,7 +65,6 @@ export async function prepareExistingDirectory( } else if (!(await git.tryReset())) { remove = true } - core.endGroup() if (remove) { core.warning( @@ -91,13 +72,6 @@ export async function prepareExistingDirectory( ) } } - - // Update to the preferred remote URL - if (remoteUrl !== preferredRemoteUrl) { - core.startGroup('Updating the remote URL') - await git.setRemoteUrl(preferredRemoteUrl) - core.endGroup() - } } catch (error) { core.warning( `Unable to prepare the existing repository. The repository will be recreated instead.` diff --git a/src/git-source-provider.ts b/src/git-source-provider.ts index 6bd4a4f..4bce702 100644 --- a/src/git-source-provider.ts +++ b/src/git-source-provider.ts @@ -14,21 +14,17 @@ import {IGitSourceSettings} from './git-source-settings' const hostname = 'github.com' export async function getSource(settings: IGitSourceSettings): Promise { + // Repository URL core.info( `Syncing repository: ${settings.repositoryOwner}/${settings.repositoryName}` ) - - // Remote URL - const httpsUrl = `https://${hostname}/${encodeURIComponent( - settings.repositoryOwner - )}/${encodeURIComponent(settings.repositoryName)}` - const sshUrl = `git@${hostname}:${encodeURIComponent( - settings.repositoryOwner - )}/${encodeURIComponent(settings.repositoryName)}.git` - - // Always fetch the workflow repository using the token, not the SSH key - const initialRemoteUrl = - !settings.sshKey || settings.isWorkflowRepository ? httpsUrl : sshUrl + const repositoryUrl = settings.sshKey + ? `git@${hostname}:${encodeURIComponent( + settings.repositoryOwner + )}/${encodeURIComponent(settings.repositoryName)}.git` + : `https://${hostname}/${encodeURIComponent( + settings.repositoryOwner + )}/${encodeURIComponent(settings.repositoryName)}` // Remove conflicting file path if (fsHelper.fileExistsSync(settings.repositoryPath)) { @@ -43,17 +39,14 @@ export async function getSource(settings: IGitSourceSettings): Promise { } // Git command manager - core.startGroup('Getting Git version info') const git = await getGitCommandManager(settings) - core.endGroup() // Prepare existing directory, otherwise recreate if (isExisting) { await gitDirectoryHelper.prepareExistingDirectory( git, settings.repositoryPath, - initialRemoteUrl, - [httpsUrl, sshUrl], + repositoryUrl, settings.clean ) } @@ -92,27 +85,21 @@ export async function getSource(settings: IGitSourceSettings): Promise { if ( !fsHelper.directoryExistsSync(path.join(settings.repositoryPath, '.git')) ) { - core.startGroup('Initializing the repository') await git.init() - await git.remoteAdd('origin', initialRemoteUrl) - core.endGroup() + await git.remoteAdd('origin', repositoryUrl) } // Disable automatic garbage collection - core.startGroup('Disabling automatic garbage collection') if (!(await git.tryDisableAutomaticGarbageCollection())) { core.warning( `Unable to turn off git automatic garbage collection. The git fetch operation may trigger garbage collection and cause a delay.` ) } - core.endGroup() const authHelper = gitAuthHelper.createAuthHelper(git, settings) try { // Configure auth - core.startGroup('Setting up auth') await authHelper.configureAuth() - core.endGroup() // LFS install if (settings.lfs) { @@ -120,51 +107,33 @@ export async function getSource(settings: IGitSourceSettings): Promise { } // Fetch - core.startGroup('Fetching the repository') const refSpec = refHelper.getRefSpec(settings.ref, settings.commit) await git.fetch(settings.fetchDepth, refSpec) - core.endGroup() // Checkout info - core.startGroup('Determining the checkout info') const checkoutInfo = await refHelper.getCheckoutInfo( git, settings.ref, settings.commit ) - core.endGroup() // LFS fetch // Explicit lfs-fetch to avoid slow checkout (fetches one lfs object at a time). // Explicit lfs fetch will fetch lfs objects in parallel. if (settings.lfs) { - core.startGroup('Fetching LFS objects') await git.lfsFetch(checkoutInfo.startPoint || checkoutInfo.ref) - core.endGroup() - } - - // Fix URL when using SSH - if (settings.sshKey && initialRemoteUrl !== sshUrl) { - core.startGroup('Updating the remote URL') - await git.setRemoteUrl(sshUrl) - core.endGroup() } // Checkout - core.startGroup('Checking out the ref') await git.checkout(checkoutInfo.ref, checkoutInfo.startPoint) - core.endGroup() // Submodules if (settings.submodules) { try { // Temporarily override global config - core.startGroup('Setting up auth for fetching submodules') await authHelper.configureGlobalAuth() - core.endGroup() // Checkout submodules - core.startGroup('Fetching submodules') await git.submoduleSync(settings.nestedSubmodules) await git.submoduleUpdate( settings.fetchDepth, @@ -174,13 +143,10 @@ export async function getSource(settings: IGitSourceSettings): Promise { 'git config --local gc.auto 0', settings.nestedSubmodules ) - core.endGroup() // Persist credentials if (settings.persistCredentials) { - core.startGroup('Persisting credentials for submodules') await authHelper.configureSubmoduleAuth() - core.endGroup() } } finally { // Remove temporary global config override @@ -193,9 +159,7 @@ export async function getSource(settings: IGitSourceSettings): Promise { } finally { // Remove auth if (!settings.persistCredentials) { - core.startGroup('Removing auth') await authHelper.removeAuth() - core.endGroup() } } } diff --git a/src/git-source-settings.ts b/src/git-source-settings.ts index 25af0c8..04d548c 100644 --- a/src/git-source-settings.ts +++ b/src/git-source-settings.ts @@ -1,81 +1,17 @@ export interface IGitSourceSettings { - /** - * The location on disk where the repository will be placed - */ repositoryPath: string - - /** - * The repository owner - */ repositoryOwner: string - - /** - * The repository name - */ repositoryName: string - - /** - * Indicates whether the repository is main workflow repository - */ - isWorkflowRepository: boolean - - /** - * The ref to fetch - */ ref: string - - /** - * The commit to checkout - */ commit: string - - /** - * Indicates whether to clean the repository - */ clean: boolean - - /** - * The depth when fetching - */ fetchDepth: number - - /** - * Indicates whether to fetch LFS objects - */ lfs: boolean - - /** - * Indicates whether to checkout submodules - */ submodules: boolean - - /** - * Indicates whether to recursively checkout submodules - */ nestedSubmodules: boolean - - /** - * The auth token to use when fetching the repository - */ authToken: string - - /** - * The SSH key to configure - */ sshKey: string - - /** - * Additional SSH known hosts - */ sshKnownHosts: string - - /** - * Indicates whether the server must be a known host - */ sshStrict: boolean - - /** - * Indicates whether to persist the credentials on disk to enable scripting authenticated git commands - */ persistCredentials: boolean } diff --git a/src/input-helper.ts b/src/input-helper.ts index 6e35986..11a1ab6 100644 --- a/src/input-helper.ts +++ b/src/input-helper.ts @@ -4,8 +4,6 @@ import * as github from '@actions/github' import * as path from 'path' import {IGitSourceSettings} from './git-source-settings' -const hostname = 'github.com' - export function getInputs(): IGitSourceSettings { const result = ({} as unknown) as IGitSourceSettings @@ -53,14 +51,14 @@ export function getInputs(): IGitSourceSettings { } // Workflow repository? - result.isWorkflowRepository = + const isWorkflowRepository = qualifiedRepository.toUpperCase() === `${github.context.repo.owner}/${github.context.repo.repo}`.toUpperCase() // Source branch, source version result.ref = core.getInput('ref') if (!result.ref) { - if (result.isWorkflowRepository) { + if (isWorkflowRepository) { result.ref = github.context.ref result.commit = github.context.sha