diff --git a/action.yml b/action.yml index 92504e4e..ca232c9b 100644 --- a/action.yml +++ b/action.yml @@ -33,6 +33,10 @@ inputs: description: 'Whether to set the `distributionSha256Sum` property in `gradle-wrapper.properties`.' required: false default: true + distributions-base-url: + description: 'Use a custom base url to download the distributions file.' + required: false + default: '' paths: description: 'List of paths where to search for Gradle Wrapper files (comma or newline-separated).' required: false diff --git a/dist/index.js b/dist/index.js index 4f67fa75..ca9ca9f3 100644 --- a/dist/index.js +++ b/dist/index.js @@ -817,6 +817,9 @@ class ActionInputs { core .getInput('set-distribution-checksum', { required: false }) .toLowerCase() !== 'false'; + this.distributionsBaseUrl = core.getInput('distributions-base-url', { + required: false + }); this.paths = core .getInput('paths', { required: false }) .split(/[\n,]/) @@ -1190,7 +1193,7 @@ class MainAction { continue; } distTypes.add(wrapper.distType); - const updater = (0, wrapperUpdater_1.createWrapperUpdater)(wrapper, targetRelease, this.inputs.setDistributionChecksum); + const updater = (0, wrapperUpdater_1.createWrapperUpdater)(wrapper, targetRelease, this.inputs.setDistributionChecksum, this.inputs.distributionsBaseUrl); core.startGroup('Updating Wrapper'); yield updater.update(); core.endGroup(); @@ -1560,14 +1563,15 @@ Object.defineProperty(exports, "__esModule", ({ value: true })); exports.createWrapperUpdater = createWrapperUpdater; const core = __importStar(__nccwpck_require__(2186)); const cmd = __importStar(__nccwpck_require__(816)); -function createWrapperUpdater(wrapper, targetRelease, setDistributionChecksum) { - return new WrapperUpdater(wrapper, targetRelease, setDistributionChecksum); +function createWrapperUpdater(wrapper, targetRelease, setDistributionChecksum, distributionsBaseUrl) { + return new WrapperUpdater(wrapper, targetRelease, setDistributionChecksum, distributionsBaseUrl); } class WrapperUpdater { - constructor(wrapper, targetRelease, setDistributionChecksum) { + constructor(wrapper, targetRelease, setDistributionChecksum, distributionsBaseUrl) { this.wrapper = wrapper; this.targetRelease = targetRelease; this.setDistributionChecksum = setDistributionChecksum; + this.distributionsBaseUrl = distributionsBaseUrl; } update() { return __awaiter(this, void 0, void 0, function* () { @@ -1578,6 +1582,10 @@ class WrapperUpdater { '--distribution-type', this.wrapper.distType ]; + if (this.distributionsBaseUrl) { + const url = `${this.distributionsBaseUrl}/gradle-${this.targetRelease.version}-${this.wrapper.distType}.zip`; + args = ['wrapper', '--gradle-distribution-url', url]; + } if (this.setDistributionChecksum) { const sha256sum = this.wrapper.distType === 'bin' ? this.targetRelease.binChecksum diff --git a/src/inputs/index.ts b/src/inputs/index.ts index 1d437059..e90aaa32 100644 --- a/src/inputs/index.ts +++ b/src/inputs/index.ts @@ -22,6 +22,7 @@ export interface Inputs { baseBranch: string; targetBranch: string; setDistributionChecksum: boolean; + distributionsBaseUrl: string; paths: string[]; pathsIgnore: string[]; releaseChannel: string; @@ -44,6 +45,7 @@ class ActionInputs implements Inputs { baseBranch: string; targetBranch: string; setDistributionChecksum: boolean; + distributionsBaseUrl: string; paths: string[]; pathsIgnore: string[]; releaseChannel: string; @@ -84,6 +86,10 @@ class ActionInputs implements Inputs { .getInput('set-distribution-checksum', {required: false}) .toLowerCase() !== 'false'; + this.distributionsBaseUrl = core.getInput('distributions-base-url', { + required: false + }); + this.paths = core .getInput('paths', {required: false}) .split(/[\n,]/) @@ -103,6 +109,7 @@ class ActionInputs implements Inputs { if (!this.releaseChannel) { this.releaseChannel = 'stable'; } + if (!acceptedReleaseChannels.includes(this.releaseChannel)) { throw new Error('release-channel has unexpected value'); } diff --git a/src/tasks/main.ts b/src/tasks/main.ts index f035d466..c423b168 100644 --- a/src/tasks/main.ts +++ b/src/tasks/main.ts @@ -131,7 +131,8 @@ export class MainAction { const updater = createWrapperUpdater( wrapper, targetRelease, - this.inputs.setDistributionChecksum + this.inputs.setDistributionChecksum, + this.inputs.distributionsBaseUrl ); core.startGroup('Updating Wrapper'); diff --git a/src/wrapperUpdater.ts b/src/wrapperUpdater.ts index e2bad395..075bd940 100644 --- a/src/wrapperUpdater.ts +++ b/src/wrapperUpdater.ts @@ -26,24 +26,33 @@ export interface IWrapperUpdater { export function createWrapperUpdater( wrapper: IWrapperInfo, targetRelease: Release, - setDistributionChecksum: boolean + setDistributionChecksum: boolean, + distributionsBaseUrl: string ): IWrapperUpdater { - return new WrapperUpdater(wrapper, targetRelease, setDistributionChecksum); + return new WrapperUpdater( + wrapper, + targetRelease, + setDistributionChecksum, + distributionsBaseUrl + ); } class WrapperUpdater implements IWrapperUpdater { private targetRelease: Release; private wrapper: IWrapperInfo; - private setDistributionChecksum: boolean; + private readonly setDistributionChecksum: boolean; + private readonly distributionsBaseUrl: string; constructor( wrapper: IWrapperInfo, targetRelease: Release, - setDistributionChecksum: boolean + setDistributionChecksum: boolean, + distributionsBaseUrl: string ) { this.wrapper = wrapper; this.targetRelease = targetRelease; this.setDistributionChecksum = setDistributionChecksum; + this.distributionsBaseUrl = distributionsBaseUrl; } async update() { @@ -55,6 +64,11 @@ class WrapperUpdater implements IWrapperUpdater { this.wrapper.distType ]; + if (this.distributionsBaseUrl) { + const url = `${this.distributionsBaseUrl}/gradle-${this.targetRelease.version}-${this.wrapper.distType}.zip`; + args = ['wrapper', '--gradle-distribution-url', url]; + } + if (this.setDistributionChecksum) { const sha256sum = this.wrapper.distType === 'bin' diff --git a/tests/github/gh-ops.test.ts b/tests/github/gh-ops.test.ts index 35630e7e..1ba77c70 100644 --- a/tests/github/gh-ops.test.ts +++ b/tests/github/gh-ops.test.ts @@ -33,6 +33,7 @@ const defaultMockInputs: Inputs = { baseBranch: '', targetBranch: '', setDistributionChecksum: true, + distributionsBaseUrl: '', paths: [], pathsIgnore: [], releaseChannel: '', diff --git a/tests/inputs/inputs.test.ts b/tests/inputs/inputs.test.ts index a7a4500a..cbbc0f67 100644 --- a/tests/inputs/inputs.test.ts +++ b/tests/inputs/inputs.test.ts @@ -46,6 +46,7 @@ describe('getInputs', () => { ActionInputs { "baseBranch": "", "commitMessageTemplate": "Update Gradle Wrapper from %sourceVersion% to %targetVersion%", + "distributionsBaseUrl": "", "labels": [], "mergeMethod": undefined, "paths": [], diff --git a/tests/tasks/main.test.ts b/tests/tasks/main.test.ts index c78bec58..4d1a0574 100644 --- a/tests/tasks/main.test.ts +++ b/tests/tasks/main.test.ts @@ -40,6 +40,7 @@ const defaultMockInputs: Inputs = { baseBranch: '', targetBranch: '', setDistributionChecksum: true, + distributionsBaseUrl: '', paths: [], pathsIgnore: [], releaseChannel: '',