Skip to content

Commit c5657a0

Browse files
committed
Merge branch 'custom/url' of github.com:yeikel/update-gradle-wrapper-action into yeikel-custom/url
2 parents adc4884 + 6b96bd8 commit c5657a0

File tree

8 files changed

+46
-9
lines changed

8 files changed

+46
-9
lines changed

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ inputs:
3333
description: 'Whether to set the `distributionSha256Sum` property in `gradle-wrapper.properties`.'
3434
required: false
3535
default: true
36+
distributions-base-url:
37+
description: 'Use a custom base url to download the distributions file.'
38+
required: false
39+
default: ''
3640
paths:
3741
description: 'List of paths where to search for Gradle Wrapper files (comma or newline-separated).'
3842
required: false

dist/index.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,9 @@ class ActionInputs {
817817
core
818818
.getInput('set-distribution-checksum', { required: false })
819819
.toLowerCase() !== 'false';
820+
this.distributionsBaseUrl = core.getInput('distributions-base-url', {
821+
required: false
822+
});
820823
this.paths = core
821824
.getInput('paths', { required: false })
822825
.split(/[\n,]/)
@@ -1190,7 +1193,7 @@ class MainAction {
11901193
continue;
11911194
}
11921195
distTypes.add(wrapper.distType);
1193-
const updater = (0, wrapperUpdater_1.createWrapperUpdater)(wrapper, targetRelease, this.inputs.setDistributionChecksum);
1196+
const updater = (0, wrapperUpdater_1.createWrapperUpdater)(wrapper, targetRelease, this.inputs.setDistributionChecksum, this.inputs.distributionsBaseUrl);
11941197
core.startGroup('Updating Wrapper');
11951198
yield updater.update();
11961199
core.endGroup();
@@ -1560,14 +1563,15 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
15601563
exports.createWrapperUpdater = createWrapperUpdater;
15611564
const core = __importStar(__nccwpck_require__(2186));
15621565
const cmd = __importStar(__nccwpck_require__(816));
1563-
function createWrapperUpdater(wrapper, targetRelease, setDistributionChecksum) {
1564-
return new WrapperUpdater(wrapper, targetRelease, setDistributionChecksum);
1566+
function createWrapperUpdater(wrapper, targetRelease, setDistributionChecksum, distributionsBaseUrl) {
1567+
return new WrapperUpdater(wrapper, targetRelease, setDistributionChecksum, distributionsBaseUrl);
15651568
}
15661569
class WrapperUpdater {
1567-
constructor(wrapper, targetRelease, setDistributionChecksum) {
1570+
constructor(wrapper, targetRelease, setDistributionChecksum, distributionsBaseUrl) {
15681571
this.wrapper = wrapper;
15691572
this.targetRelease = targetRelease;
15701573
this.setDistributionChecksum = setDistributionChecksum;
1574+
this.distributionsBaseUrl = distributionsBaseUrl;
15711575
}
15721576
update() {
15731577
return __awaiter(this, void 0, void 0, function* () {
@@ -1578,6 +1582,10 @@ class WrapperUpdater {
15781582
'--distribution-type',
15791583
this.wrapper.distType
15801584
];
1585+
if (this.distributionsBaseUrl) {
1586+
const url = `${this.distributionsBaseUrl}/gradle-${this.targetRelease.version}-${this.wrapper.distType}.zip`;
1587+
args = ['wrapper', '--gradle-distribution-url', url];
1588+
}
15811589
if (this.setDistributionChecksum) {
15821590
const sha256sum = this.wrapper.distType === 'bin'
15831591
? this.targetRelease.binChecksum

src/inputs/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export interface Inputs {
2222
baseBranch: string;
2323
targetBranch: string;
2424
setDistributionChecksum: boolean;
25+
distributionsBaseUrl: string;
2526
paths: string[];
2627
pathsIgnore: string[];
2728
releaseChannel: string;
@@ -44,6 +45,7 @@ class ActionInputs implements Inputs {
4445
baseBranch: string;
4546
targetBranch: string;
4647
setDistributionChecksum: boolean;
48+
distributionsBaseUrl: string;
4749
paths: string[];
4850
pathsIgnore: string[];
4951
releaseChannel: string;
@@ -84,6 +86,10 @@ class ActionInputs implements Inputs {
8486
.getInput('set-distribution-checksum', {required: false})
8587
.toLowerCase() !== 'false';
8688

89+
this.distributionsBaseUrl = core.getInput('distributions-base-url', {
90+
required: false
91+
});
92+
8793
this.paths = core
8894
.getInput('paths', {required: false})
8995
.split(/[\n,]/)
@@ -103,6 +109,7 @@ class ActionInputs implements Inputs {
103109
if (!this.releaseChannel) {
104110
this.releaseChannel = 'stable';
105111
}
112+
106113
if (!acceptedReleaseChannels.includes(this.releaseChannel)) {
107114
throw new Error('release-channel has unexpected value');
108115
}

src/tasks/main.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ export class MainAction {
131131
const updater = createWrapperUpdater(
132132
wrapper,
133133
targetRelease,
134-
this.inputs.setDistributionChecksum
134+
this.inputs.setDistributionChecksum,
135+
this.inputs.distributionsBaseUrl
135136
);
136137

137138
core.startGroup('Updating Wrapper');

src/wrapperUpdater.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,33 @@ export interface IWrapperUpdater {
2626
export function createWrapperUpdater(
2727
wrapper: IWrapperInfo,
2828
targetRelease: Release,
29-
setDistributionChecksum: boolean
29+
setDistributionChecksum: boolean,
30+
distributionsBaseUrl: string
3031
): IWrapperUpdater {
31-
return new WrapperUpdater(wrapper, targetRelease, setDistributionChecksum);
32+
return new WrapperUpdater(
33+
wrapper,
34+
targetRelease,
35+
setDistributionChecksum,
36+
distributionsBaseUrl
37+
);
3238
}
3339

3440
class WrapperUpdater implements IWrapperUpdater {
3541
private targetRelease: Release;
3642
private wrapper: IWrapperInfo;
37-
private setDistributionChecksum: boolean;
43+
private readonly setDistributionChecksum: boolean;
44+
private readonly distributionsBaseUrl: string;
3845

3946
constructor(
4047
wrapper: IWrapperInfo,
4148
targetRelease: Release,
42-
setDistributionChecksum: boolean
49+
setDistributionChecksum: boolean,
50+
distributionsBaseUrl: string
4351
) {
4452
this.wrapper = wrapper;
4553
this.targetRelease = targetRelease;
4654
this.setDistributionChecksum = setDistributionChecksum;
55+
this.distributionsBaseUrl = distributionsBaseUrl;
4756
}
4857

4958
async update() {
@@ -55,6 +64,11 @@ class WrapperUpdater implements IWrapperUpdater {
5564
this.wrapper.distType
5665
];
5766

67+
if (this.distributionsBaseUrl) {
68+
const url = `${this.distributionsBaseUrl}/gradle-${this.targetRelease.version}-${this.wrapper.distType}.zip`;
69+
args = ['wrapper', '--gradle-distribution-url', url];
70+
}
71+
5872
if (this.setDistributionChecksum) {
5973
const sha256sum =
6074
this.wrapper.distType === 'bin'

tests/github/gh-ops.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const defaultMockInputs: Inputs = {
3333
baseBranch: '',
3434
targetBranch: '',
3535
setDistributionChecksum: true,
36+
distributionsBaseUrl: '',
3637
paths: [],
3738
pathsIgnore: [],
3839
releaseChannel: '',

tests/inputs/inputs.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ describe('getInputs', () => {
4646
ActionInputs {
4747
"baseBranch": "",
4848
"commitMessageTemplate": "Update Gradle Wrapper from %sourceVersion% to %targetVersion%",
49+
"distributionsBaseUrl": "",
4950
"labels": [],
5051
"mergeMethod": undefined,
5152
"paths": [],

tests/tasks/main.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const defaultMockInputs: Inputs = {
4040
baseBranch: '',
4141
targetBranch: '',
4242
setDistributionChecksum: true,
43+
distributionsBaseUrl: '',
4344
paths: [],
4445
pathsIgnore: [],
4546
releaseChannel: '',

0 commit comments

Comments
 (0)