Skip to content

Commit

Permalink
Merge branch 'custom/url' of github.com:yeikel/update-gradle-wrapper-…
Browse files Browse the repository at this point in the history
…action into yeikel-custom/url
  • Loading branch information
cristiangreco committed Sep 16, 2024
2 parents adc4884 + 6b96bd8 commit c5657a0
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 9 deletions.
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 12 additions & 4 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,]/)
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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* () {
Expand All @@ -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
Expand Down
7 changes: 7 additions & 0 deletions src/inputs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface Inputs {
baseBranch: string;
targetBranch: string;
setDistributionChecksum: boolean;
distributionsBaseUrl: string;
paths: string[];
pathsIgnore: string[];
releaseChannel: string;
Expand All @@ -44,6 +45,7 @@ class ActionInputs implements Inputs {
baseBranch: string;
targetBranch: string;
setDistributionChecksum: boolean;
distributionsBaseUrl: string;
paths: string[];
pathsIgnore: string[];
releaseChannel: string;
Expand Down Expand Up @@ -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,]/)
Expand All @@ -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');
}
Expand Down
3 changes: 2 additions & 1 deletion src/tasks/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
22 changes: 18 additions & 4 deletions src/wrapperUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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'
Expand Down
1 change: 1 addition & 0 deletions tests/github/gh-ops.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const defaultMockInputs: Inputs = {
baseBranch: '',
targetBranch: '',
setDistributionChecksum: true,
distributionsBaseUrl: '',
paths: [],
pathsIgnore: [],
releaseChannel: '',
Expand Down
1 change: 1 addition & 0 deletions tests/inputs/inputs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ describe('getInputs', () => {
ActionInputs {
"baseBranch": "",
"commitMessageTemplate": "Update Gradle Wrapper from %sourceVersion% to %targetVersion%",
"distributionsBaseUrl": "",
"labels": [],
"mergeMethod": undefined,
"paths": [],
Expand Down
1 change: 1 addition & 0 deletions tests/tasks/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const defaultMockInputs: Inputs = {
baseBranch: '',
targetBranch: '',
setDistributionChecksum: true,
distributionsBaseUrl: '',
paths: [],
pathsIgnore: [],
releaseChannel: '',
Expand Down

0 comments on commit c5657a0

Please sign in to comment.