diff --git a/README.md b/README.md index 9828e58..3a3954c 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,10 @@ When Git 2.18 or higher is not in your PATH, falls back to the REST API to downl # Default: https://lfscache.office.playeveryware.com/${{ github.repository }} lfs-url: '' + # Credential provider for the Git-LFS server + # Default: github + lfs-url-cred-provider: '' + # Whether to checkout submodules: `true` to checkout submodules or `recursive` to # recursively checkout submodules. # diff --git a/action.yml b/action.yml index bebab9a..45576de 100644 --- a/action.yml +++ b/action.yml @@ -62,6 +62,9 @@ inputs: lfs-url: description: 'URL to use when fetching Git-LFS files' default: 'https://lfscache.office.playeveryware.com/${{ github.repository }}' + lfs-url-cred-provider: + description: 'Credential provider for the Git-LFS server' + default: 'github' submodules: description: > Whether to checkout submodules: `true` to checkout submodules or `recursive` to diff --git a/dist/index.js b/dist/index.js index 7430f13..3dc2770 100644 --- a/dist/index.js +++ b/dist/index.js @@ -18456,6 +18456,7 @@ function getInputs() { // LFS result.lfs = (core.getInput('lfs') || 'false').toUpperCase() === 'TRUE'; result.lfsurl = (core.getInput('lfs-url') || ''); + result.lfsCredProvider = (core.getInput('lfs-url-cred-provider') || ''); core.debug(`lfs = ${result.lfs}`); // Submodules result.submodules = false; @@ -31808,6 +31809,7 @@ const path = __importStar(__webpack_require__(622)); const refHelper = __importStar(__webpack_require__(227)); const stateHelper = __importStar(__webpack_require__(153)); const urlHelper = __importStar(__webpack_require__(81)); +const url_1 = __webpack_require__(835); function getSource(settings) { return __awaiter(this, void 0, void 0, function* () { // Repository URL @@ -31924,12 +31926,25 @@ function getSource(settings) { // LFS URL if (settings.lfs && settings.lfsurl) { core.startGroup('Setting LFS URL'); + let remote = new url_1.URL(settings.lfsurl); + remote.password = core.getInput('token'); yield git - .config('lfs.url', settings.lfsurl, false, false) + .config('lfs.url', remote.href, false, false) .catch(error => { core.info(`Failed to initialize safe directory with error: ${error}`); }); core.endGroup(); + if (settings.lfsCredProvider) { + core.startGroup('Setting LFS credential provider'); + let url = new url_1.URL(settings.lfsurl); + let key = 'credential.' + url.host + '.provider'; + yield git + .config(key, settings.lfsCredProvider, false, false) + .catch(error => { + core.info(`Failed to initialize safe directory with error: ${error}`); + }); + core.endGroup(); + } } // LFS fetch // Explicit lfs-fetch to avoid slow checkout (fetches one lfs object at a time). diff --git a/src/git-source-provider.ts b/src/git-source-provider.ts index 6b969af..1cf9337 100644 --- a/src/git-source-provider.ts +++ b/src/git-source-provider.ts @@ -11,6 +11,7 @@ import * as stateHelper from './state-helper' import * as urlHelper from './url-helper' import {IGitCommandManager} from './git-command-manager' import {IGitSourceSettings} from './git-source-settings' +import {URL} from "url"; export async function getSource(settings: IGitSourceSettings): Promise { // Repository URL @@ -185,14 +186,30 @@ export async function getSource(settings: IGitSourceSettings): Promise { // LFS URL if (settings.lfs && settings.lfsurl) { core.startGroup('Setting LFS URL') + let remote = new URL(settings.lfsurl) + remote.password = core.getInput('token') await git - .config('lfs.url', settings.lfsurl, false, false) + .config('lfs.url', remote.href, false, false) .catch(error => { core.info( `Failed to initialize safe directory with error: ${error}` ) }) core.endGroup() + + if (settings.lfsCredProvider) { + core.startGroup('Setting LFS credential provider') + let url = new URL(settings.lfsurl); + let key = 'credential.' + url.host + '.provider' + await git + .config(key, settings.lfsCredProvider, false, false) + .catch(error => { + core.info( + `Failed to initialize safe directory with error: ${error}` + ) + }) + core.endGroup() + } } // LFS fetch diff --git a/src/git-source-settings.ts b/src/git-source-settings.ts index 762d3ef..5d5b49c 100644 --- a/src/git-source-settings.ts +++ b/src/git-source-settings.ts @@ -44,6 +44,11 @@ export interface IGitSourceSettings { */ lfsurl: string + /** + * The credential provider to usse for the Git LFS server + */ + lfsCredProvider: string + /** * Indicates whether to checkout submodules */ diff --git a/src/input-helper.ts b/src/input-helper.ts index 41ef28c..b2916c5 100644 --- a/src/input-helper.ts +++ b/src/input-helper.ts @@ -92,6 +92,7 @@ export async function getInputs(): Promise { // LFS result.lfs = (core.getInput('lfs') || 'false').toUpperCase() === 'TRUE' result.lfsurl = (core.getInput('lfs-url') || '') + result.lfsCredProvider = (core.getInput('lfs-url-cred-provider') || '') core.debug(`lfs = ${result.lfs}`) // Submodules