@@ -4838,15 +4838,15 @@ class GitCommandManager {
4838
4838
}
4839
4839
config(configKey, configValue) {
4840
4840
return __awaiter(this, void 0, void 0, function* () {
4841
- yield this.execGit(['config', configKey, configValue]);
4841
+ yield this.execGit(['config', '--local', configKey, configValue]);
4842
4842
});
4843
4843
}
4844
4844
configExists(configKey) {
4845
4845
return __awaiter(this, void 0, void 0, function* () {
4846
4846
const pattern = configKey.replace(/[^a-zA-Z0-9_]/g, x => {
4847
4847
return `\\${x}`;
4848
4848
});
4849
- const output = yield this.execGit(['config', '--name-only', '--get-regexp', pattern], true);
4849
+ const output = yield this.execGit(['config', '--local', '-- name-only', '--get-regexp', pattern], true);
4850
4850
return output.exitCode === 0;
4851
4851
});
4852
4852
}
@@ -4932,19 +4932,19 @@ class GitCommandManager {
4932
4932
}
4933
4933
tryConfigUnset(configKey) {
4934
4934
return __awaiter(this, void 0, void 0, function* () {
4935
- const output = yield this.execGit(['config', '--unset-all', configKey], true);
4935
+ const output = yield this.execGit(['config', '--local', '-- unset-all', configKey], true);
4936
4936
return output.exitCode === 0;
4937
4937
});
4938
4938
}
4939
4939
tryDisableAutomaticGarbageCollection() {
4940
4940
return __awaiter(this, void 0, void 0, function* () {
4941
- const output = yield this.execGit(['config', 'gc.auto', '0'], true);
4941
+ const output = yield this.execGit(['config', '--local', ' gc.auto', '0'], true);
4942
4942
return output.exitCode === 0;
4943
4943
});
4944
4944
}
4945
4945
tryGetFetchUrl() {
4946
4946
return __awaiter(this, void 0, void 0, function* () {
4947
- const output = yield this.execGit(['config', '--get', 'remote.origin.url'], true);
4947
+ const output = yield this.execGit(['config', '--local', '-- get', 'remote.origin.url'], true);
4948
4948
if (output.exitCode !== 0) {
4949
4949
return '';
4950
4950
}
@@ -5121,7 +5121,7 @@ function getSource(settings) {
5121
5121
// Downloading using REST API
5122
5122
core.info(`The repository will be downloaded using the GitHub REST API`);
5123
5123
core.info(`To create a local Git repository instead, add Git ${gitCommandManager.MinimumGitVersion} or higher to the PATH`);
5124
- yield githubApiHelper.downloadRepository(settings.accessToken , settings.repositoryOwner, settings.repositoryName, settings.ref, settings.commit, settings.repositoryPath);
5124
+ yield githubApiHelper.downloadRepository(settings.authToken , settings.repositoryOwner, settings.repositoryName, settings.ref, settings.commit, settings.repositoryPath);
5125
5125
}
5126
5126
else {
5127
5127
// Save state for POST action
@@ -5137,30 +5137,34 @@ function getSource(settings) {
5137
5137
}
5138
5138
// Remove possible previous extraheader
5139
5139
yield removeGitConfig(git, authConfigKey);
5140
- // Add extraheader (auth)
5141
- const base64Credentials = Buffer.from(`x-access-token:${settings.accessToken}`, 'utf8').toString('base64');
5142
- core.setSecret(base64Credentials);
5143
- const authConfigValue = `AUTHORIZATION: basic ${base64Credentials}`;
5144
- yield git.config(authConfigKey, authConfigValue);
5145
- // LFS install
5146
- if (settings.lfs) {
5147
- yield git.lfsInstall();
5148
- }
5149
- // Fetch
5150
- const refSpec = refHelper.getRefSpec(settings.ref, settings.commit);
5151
- yield git.fetch(settings.fetchDepth, refSpec);
5152
- // Checkout info
5153
- const checkoutInfo = yield refHelper.getCheckoutInfo(git, settings.ref, settings.commit);
5154
- // LFS fetch
5155
- // Explicit lfs-fetch to avoid slow checkout (fetches one lfs object at a time).
5156
- // Explicit lfs fetch will fetch lfs objects in parallel.
5157
- if (settings.lfs) {
5158
- yield git.lfsFetch(checkoutInfo.startPoint || checkoutInfo.ref);
5140
+ try {
5141
+ // Config auth token
5142
+ yield configureAuthToken(git, settings.authToken);
5143
+ // LFS install
5144
+ if (settings.lfs) {
5145
+ yield git.lfsInstall();
5146
+ }
5147
+ // Fetch
5148
+ const refSpec = refHelper.getRefSpec(settings.ref, settings.commit);
5149
+ yield git.fetch(settings.fetchDepth, refSpec);
5150
+ // Checkout info
5151
+ const checkoutInfo = yield refHelper.getCheckoutInfo(git, settings.ref, settings.commit);
5152
+ // LFS fetch
5153
+ // Explicit lfs-fetch to avoid slow checkout (fetches one lfs object at a time).
5154
+ // Explicit lfs fetch will fetch lfs objects in parallel.
5155
+ if (settings.lfs) {
5156
+ yield git.lfsFetch(checkoutInfo.startPoint || checkoutInfo.ref);
5157
+ }
5158
+ // Checkout
5159
+ yield git.checkout(checkoutInfo.ref, checkoutInfo.startPoint);
5160
+ // Dump some info about the checked out commit
5161
+ yield git.log1();
5162
+ }
5163
+ finally {
5164
+ if (!settings.persistCredentials) {
5165
+ yield removeGitConfig(git, authConfigKey);
5166
+ }
5159
5167
}
5160
- // Checkout
5161
- yield git.checkout(checkoutInfo.ref, checkoutInfo.startPoint);
5162
- // Dump some info about the checked out commit
5163
- yield git.log1();
5164
5168
}
5165
5169
});
5166
5170
}
@@ -5265,23 +5269,21 @@ function prepareExistingDirectory(git, repositoryPath, repositoryUrl, clean) {
5265
5269
}
5266
5270
});
5267
5271
}
5272
+ function configureAuthToken(git, authToken) {
5273
+ return __awaiter(this, void 0, void 0, function* () {
5274
+ // Add extraheader (auth)
5275
+ const base64Credentials = Buffer.from(`x-access-token:${authToken}`, 'utf8').toString('base64');
5276
+ core.setSecret(base64Credentials);
5277
+ const authConfigValue = `AUTHORIZATION: basic ${base64Credentials}`;
5278
+ yield git.config(authConfigKey, authConfigValue);
5279
+ });
5280
+ }
5268
5281
function removeGitConfig(git, configKey) {
5269
5282
return __awaiter(this, void 0, void 0, function* () {
5270
5283
if ((yield git.configExists(configKey)) &&
5271
5284
!(yield git.tryConfigUnset(configKey))) {
5272
5285
// Load the config contents
5273
- core.warning(`Failed to remove '${configKey}' from the git config. Attempting to remove the config value by editing the file directly.`);
5274
- const configPath = path.join(git.getWorkingDirectory(), '.git', 'config');
5275
- fsHelper.fileExistsSync(configPath);
5276
- let contents = fs.readFileSync(configPath).toString() || '';
5277
- // Filter - only includes lines that do not contain the config key
5278
- const upperConfigKey = configKey.toUpperCase();
5279
- const split = contents
5280
- .split('\n')
5281
- .filter(x => !x.toUpperCase().includes(upperConfigKey));
5282
- contents = split.join('\n');
5283
- // Rewrite the config file
5284
- fs.writeFileSync(configPath, contents);
5286
+ core.warning(`Failed to remove '${configKey}' from the git config`);
5285
5287
}
5286
5288
});
5287
5289
}
@@ -8403,12 +8405,12 @@ const retryHelper = __importStar(__webpack_require__(587));
8403
8405
const toolCache = __importStar(__webpack_require__(533));
8404
8406
const v4_1 = __importDefault(__webpack_require__(826));
8405
8407
const IS_WINDOWS = process.platform === 'win32';
8406
- function downloadRepository(accessToken , owner, repo, ref, commit, repositoryPath) {
8408
+ function downloadRepository(authToken , owner, repo, ref, commit, repositoryPath) {
8407
8409
return __awaiter(this, void 0, void 0, function* () {
8408
8410
// Download the archive
8409
8411
let archiveData = yield retryHelper.execute(() => __awaiter(this, void 0, void 0, function* () {
8410
8412
core.info('Downloading the archive');
8411
- return yield downloadArchive(accessToken , owner, repo, ref, commit);
8413
+ return yield downloadArchive(authToken , owner, repo, ref, commit);
8412
8414
}));
8413
8415
// Write archive to disk
8414
8416
core.info('Writing archive to disk');
@@ -8449,9 +8451,9 @@ function downloadRepository(accessToken, owner, repo, ref, commit, repositoryPat
8449
8451
});
8450
8452
}
8451
8453
exports.downloadRepository = downloadRepository;
8452
- function downloadArchive(accessToken , owner, repo, ref, commit) {
8454
+ function downloadArchive(authToken , owner, repo, ref, commit) {
8453
8455
return __awaiter(this, void 0, void 0, function* () {
8454
- const octokit = new github.GitHub(accessToken );
8456
+ const octokit = new github.GitHub(authToken );
8455
8457
const params = {
8456
8458
owner: owner,
8457
8459
repo: repo,
@@ -12764,8 +12766,11 @@ function getInputs() {
12764
12766
// LFS
12765
12767
result.lfs = (core.getInput('lfs') || 'false').toUpperCase() === 'TRUE';
12766
12768
core.debug(`lfs = ${result.lfs}`);
12767
- // Access token
12768
- result.accessToken = core.getInput('token');
12769
+ // Auth token
12770
+ result.authToken = core.getInput('token');
12771
+ // Persist credentials
12772
+ result.persistCredentials =
12773
+ (core.getInput('persist-credentials') || 'false').toUpperCase() === 'TRUE';
12769
12774
return result;
12770
12775
}
12771
12776
exports.getInputs = getInputs;
0 commit comments