Include provisioned Gradle version as action output

Fixes #259
This commit is contained in:
daz 2023-08-19 11:50:40 -06:00 committed by Daz DeBoer
parent 124cb765ee
commit 8cade330d4
5 changed files with 49 additions and 22 deletions

View file

@ -55,6 +55,17 @@ jobs:
- name: Test use release-candidate - name: Test use release-candidate
working-directory: .github/workflow-samples/no-wrapper working-directory: .github/workflow-samples/no-wrapper
run: gradle help 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: gradle-versions:
strategy: strategy:
@ -80,10 +91,17 @@ jobs:
distribution: temurin distribution: temurin
java-version: 8 java-version: 8
- name: Setup Gradle - name: Setup Gradle
id: setup-gradle
uses: ./ uses: ./
with: with:
cache-read-only: false # For testing, allow writing cache entries on non-default branches cache-read-only: false # For testing, allow writing cache entries on non-default branches
gradle-version: ${{ matrix.gradle }} 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 - name: Run Gradle build
id: gradle id: gradle
working-directory: .github/workflow-samples/no-wrapper${{ matrix.build-root-suffix }} working-directory: .github/workflow-samples/no-wrapper${{ matrix.build-root-suffix }}

View file

@ -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. 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: 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. 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: runs:
using: 'node16' using: 'node16'

20
dist/main/index.js vendored
View file

@ -74827,6 +74827,13 @@ function addToPath(executable) {
}); });
} }
function installGradle(version) { 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* () { return __awaiter(this, void 0, void 0, function* () {
switch (version) { switch (version) {
case 'current': case 'current':
@ -74847,15 +74854,14 @@ function installGradle(version) {
} }
function gradleCurrent() { function gradleCurrent() {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
const versionInfo = yield gradleVersionDeclaration(`${gradleVersionsBaseUrl}/current`); return yield gradleVersionDeclaration(`${gradleVersionsBaseUrl}/current`);
return installGradleVersion(versionInfo);
}); });
} }
function gradleReleaseCandidate() { function gradleReleaseCandidate() {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
const versionInfo = yield gradleVersionDeclaration(`${gradleVersionsBaseUrl}/release-candidate`); const versionInfo = yield gradleVersionDeclaration(`${gradleVersionsBaseUrl}/release-candidate`);
if (versionInfo && versionInfo.version && versionInfo.downloadUrl) { if (versionInfo && versionInfo.version && versionInfo.downloadUrl) {
return installGradleVersion(versionInfo); return versionInfo;
} }
core.info('No current release-candidate found, will fallback to current'); core.info('No current release-candidate found, will fallback to current');
return gradleCurrent(); return gradleCurrent();
@ -74863,14 +74869,12 @@ function gradleReleaseCandidate() {
} }
function gradleNightly() { function gradleNightly() {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
const versionInfo = yield gradleVersionDeclaration(`${gradleVersionsBaseUrl}/nightly`); return yield gradleVersionDeclaration(`${gradleVersionsBaseUrl}/nightly`);
return installGradleVersion(versionInfo);
}); });
} }
function gradleReleaseNightly() { function gradleReleaseNightly() {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
const versionInfo = yield gradleVersionDeclaration(`${gradleVersionsBaseUrl}/release-nightly`); return yield gradleVersionDeclaration(`${gradleVersionsBaseUrl}/release-nightly`);
return installGradleVersion(versionInfo);
}); });
} }
function gradle(version) { function gradle(version) {
@ -74879,7 +74883,7 @@ function gradle(version) {
if (!versionInfo) { if (!versionInfo) {
throw new Error(`Gradle version ${version} does not exists`); throw new Error(`Gradle version ${version} does not exists`);
} }
return installGradleVersion(versionInfo); return versionInfo;
}); });
} }
function gradleVersionDeclaration(url) { function gradleVersionDeclaration(url) {

File diff suppressed because one or more lines are too long

View file

@ -38,6 +38,12 @@ async function addToPath(executable: string): Promise<string> {
} }
async function installGradle(version: 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) { switch (version) {
case 'current': case 'current':
return gradleCurrent() return gradleCurrent()
@ -55,36 +61,33 @@ async function installGradle(version: string): Promise<string> {
} }
} }
async function gradleCurrent(): Promise<string> { async function gradleCurrent(): Promise<GradleVersionInfo> {
const versionInfo = await gradleVersionDeclaration(`${gradleVersionsBaseUrl}/current`) return await gradleVersionDeclaration(`${gradleVersionsBaseUrl}/current`)
return installGradleVersion(versionInfo)
} }
async function gradleReleaseCandidate(): Promise<string> { async function gradleReleaseCandidate(): Promise<GradleVersionInfo> {
const versionInfo = await gradleVersionDeclaration(`${gradleVersionsBaseUrl}/release-candidate`) const versionInfo = await gradleVersionDeclaration(`${gradleVersionsBaseUrl}/release-candidate`)
if (versionInfo && versionInfo.version && versionInfo.downloadUrl) { if (versionInfo && versionInfo.version && versionInfo.downloadUrl) {
return installGradleVersion(versionInfo) return versionInfo
} }
core.info('No current release-candidate found, will fallback to current') core.info('No current release-candidate found, will fallback to current')
return gradleCurrent() return gradleCurrent()
} }
async function gradleNightly(): Promise<string> { async function gradleNightly(): Promise<GradleVersionInfo> {
const versionInfo = await gradleVersionDeclaration(`${gradleVersionsBaseUrl}/nightly`) return await gradleVersionDeclaration(`${gradleVersionsBaseUrl}/nightly`)
return installGradleVersion(versionInfo)
} }
async function gradleReleaseNightly(): Promise<string> { async function gradleReleaseNightly(): Promise<GradleVersionInfo> {
const versionInfo = await gradleVersionDeclaration(`${gradleVersionsBaseUrl}/release-nightly`) return await gradleVersionDeclaration(`${gradleVersionsBaseUrl}/release-nightly`)
return installGradleVersion(versionInfo)
} }
async function gradle(version: string): Promise<string> { async function gradle(version: string): Promise<GradleVersionInfo> {
const versionInfo = await findGradleVersionDeclaration(version) const versionInfo = await findGradleVersionDeclaration(version)
if (!versionInfo) { if (!versionInfo) {
throw new Error(`Gradle version ${version} does not exists`) throw new Error(`Gradle version ${version} does not exists`)
} }
return installGradleVersion(versionInfo) return versionInfo
} }
async function gradleVersionDeclaration(url: string): Promise<GradleVersionInfo> { async function gradleVersionDeclaration(url: string): Promise<GradleVersionInfo> {