Skip to content

Commit

Permalink
Include provisioned Gradle version as action output
Browse files Browse the repository at this point in the history
  • Loading branch information
bigdaz committed Aug 19, 2023
1 parent 124cb76 commit 8cade33
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 22 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/integ-test-provision-gradle-versions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ jobs:
- name: Test use release-candidate
working-directory: .github/workflow-samples/no-wrapper
run: gradle help
- name: Setup Gradle with current
id: gradle-current
uses: ./
with:
gradle-version: current
- name: Check current version output parameter
if: ${{ !startsWith(steps.gradle-current.outputs.gradle-version , '8.') }}
uses: actions/github-script@v6
with:
script: |
core.setFailed('Gradle version parameter not set correctly: value was "${{ steps.gradle-current.outputs.gradle-version }}"')
gradle-versions:
strategy:
Expand All @@ -80,10 +91,17 @@ jobs:
distribution: temurin
java-version: 8
- name: Setup Gradle
id: setup-gradle
uses: ./
with:
cache-read-only: false # For testing, allow writing cache entries on non-default branches
gradle-version: ${{ matrix.gradle }}
- name: Check output parameter
if: ${{ steps.setup-gradle.outputs.gradle-version != matrix.gradle }}
uses: actions/github-script@v6
with:
script: |
core.setFailed('Gradle version parameter not set correctly: value was "${{ steps.setup-gradle.outputs.gradle-version }}"')
- name: Run Gradle build
id: gradle
working-directory: .github/workflow-samples/no-wrapper${{ matrix.build-root-suffix }}
Expand Down
2 changes: 2 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ outputs:
description: Link to the Build Scan® generated by a Gradle build. Note that this output applies to a Step executing Gradle, not to the `gradle-build-action` Step itself.
dependency-graph-file:
description: Path to the GitHub Dependency Graph snapshot file generated by a Gradle build. Note that this output applies to a Step executing Gradle, not to the `gradle-build-action` Step itself.
gradle-version:
description: Version of Gradle that was setup by the action

runs:
using: 'node16'
Expand Down
20 changes: 12 additions & 8 deletions dist/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74827,6 +74827,13 @@ function addToPath(executable) {
});
}
function installGradle(version) {
return __awaiter(this, void 0, void 0, function* () {
const versionInfo = yield resolveGradleVersion(version);
core.setOutput('gradle-version', versionInfo.version);
return installGradleVersion(versionInfo);
});
}
function resolveGradleVersion(version) {
return __awaiter(this, void 0, void 0, function* () {
switch (version) {
case 'current':
Expand All @@ -74847,30 +74854,27 @@ function installGradle(version) {
}
function gradleCurrent() {
return __awaiter(this, void 0, void 0, function* () {
const versionInfo = yield gradleVersionDeclaration(`${gradleVersionsBaseUrl}/current`);
return installGradleVersion(versionInfo);
return yield gradleVersionDeclaration(`${gradleVersionsBaseUrl}/current`);
});
}
function gradleReleaseCandidate() {
return __awaiter(this, void 0, void 0, function* () {
const versionInfo = yield gradleVersionDeclaration(`${gradleVersionsBaseUrl}/release-candidate`);
if (versionInfo && versionInfo.version && versionInfo.downloadUrl) {
return installGradleVersion(versionInfo);
return versionInfo;
}
core.info('No current release-candidate found, will fallback to current');
return gradleCurrent();
});
}
function gradleNightly() {
return __awaiter(this, void 0, void 0, function* () {
const versionInfo = yield gradleVersionDeclaration(`${gradleVersionsBaseUrl}/nightly`);
return installGradleVersion(versionInfo);
return yield gradleVersionDeclaration(`${gradleVersionsBaseUrl}/nightly`);
});
}
function gradleReleaseNightly() {
return __awaiter(this, void 0, void 0, function* () {
const versionInfo = yield gradleVersionDeclaration(`${gradleVersionsBaseUrl}/release-nightly`);
return installGradleVersion(versionInfo);
return yield gradleVersionDeclaration(`${gradleVersionsBaseUrl}/release-nightly`);
});
}
function gradle(version) {
Expand All @@ -74879,7 +74883,7 @@ function gradle(version) {
if (!versionInfo) {
throw new Error(`Gradle version ${version} does not exists`);
}
return installGradleVersion(versionInfo);
return versionInfo;
});
}
function gradleVersionDeclaration(url) {
Expand Down
2 changes: 1 addition & 1 deletion dist/main/index.js.map

Large diffs are not rendered by default.

29 changes: 16 additions & 13 deletions src/provision.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ async function addToPath(executable: string): Promise<string> {
}

async function installGradle(version: string): Promise<string> {
const versionInfo = await resolveGradleVersion(version)
core.setOutput('gradle-version', versionInfo.version)
return installGradleVersion(versionInfo)
}

async function resolveGradleVersion(version: string): Promise<GradleVersionInfo> {
switch (version) {
case 'current':
return gradleCurrent()
Expand All @@ -55,36 +61,33 @@ async function installGradle(version: string): Promise<string> {
}
}

async function gradleCurrent(): Promise<string> {
const versionInfo = await gradleVersionDeclaration(`${gradleVersionsBaseUrl}/current`)
return installGradleVersion(versionInfo)
async function gradleCurrent(): Promise<GradleVersionInfo> {
return await gradleVersionDeclaration(`${gradleVersionsBaseUrl}/current`)
}

async function gradleReleaseCandidate(): Promise<string> {
async function gradleReleaseCandidate(): Promise<GradleVersionInfo> {
const versionInfo = await gradleVersionDeclaration(`${gradleVersionsBaseUrl}/release-candidate`)
if (versionInfo && versionInfo.version && versionInfo.downloadUrl) {
return installGradleVersion(versionInfo)
return versionInfo
}
core.info('No current release-candidate found, will fallback to current')
return gradleCurrent()
}

async function gradleNightly(): Promise<string> {
const versionInfo = await gradleVersionDeclaration(`${gradleVersionsBaseUrl}/nightly`)
return installGradleVersion(versionInfo)
async function gradleNightly(): Promise<GradleVersionInfo> {
return await gradleVersionDeclaration(`${gradleVersionsBaseUrl}/nightly`)
}

async function gradleReleaseNightly(): Promise<string> {
const versionInfo = await gradleVersionDeclaration(`${gradleVersionsBaseUrl}/release-nightly`)
return installGradleVersion(versionInfo)
async function gradleReleaseNightly(): Promise<GradleVersionInfo> {
return await gradleVersionDeclaration(`${gradleVersionsBaseUrl}/release-nightly`)
}

async function gradle(version: string): Promise<string> {
async function gradle(version: string): Promise<GradleVersionInfo> {
const versionInfo = await findGradleVersionDeclaration(version)
if (!versionInfo) {
throw new Error(`Gradle version ${version} does not exists`)
}
return installGradleVersion(versionInfo)
return versionInfo
}

async function gradleVersionDeclaration(url: string): Promise<GradleVersionInfo> {
Expand Down

0 comments on commit 8cade33

Please sign in to comment.