From aeb3156e6feb694def796660ed3570300392ca18 Mon Sep 17 00:00:00 2001 From: daz Date: Tue, 9 Apr 2024 14:09:02 -0600 Subject: [PATCH] Emit deprecation warning for 'gradle-build-action' --- docs/deprecation-upgrade-guide.md | 46 ++++++++++++++--------- sources/src/configuration.ts | 10 +++++ sources/src/dependency-submission/main.ts | 5 ++- sources/src/deprecation-collector.ts | 4 +- sources/src/job-summary.ts | 5 ++- sources/src/setup-gradle/main.ts | 19 +++++++++- 6 files changed, 64 insertions(+), 25 deletions(-) diff --git a/docs/deprecation-upgrade-guide.md b/docs/deprecation-upgrade-guide.md index 93aabca..99c11d7 100644 --- a/docs/deprecation-upgrade-guide.md +++ b/docs/deprecation-upgrade-guide.md @@ -8,6 +8,23 @@ prompting them to update their workflows. ## Deprecated in v3.x +### The action `gradle/gradle-build-action` has been replaced by `gradle/actions/setup-gradle` + +The `gradle-build-action` action has evolved, so that the core functionality is now to configure the +Gradle environment for GitHub Actions. For clarity and consistency with other action (eg `setup-java`, `setup-node`), the `gradle-build-action` has been replaced by the `setup-gradle` action. + +As of `v3.x`, the `setup-gradle` and `gradle-build-action` actions are functionally identical, +and are released with the same versions. + +To convert your workflows, simply replace: +``` + uses: gradle/gradle-build-action@v3 +``` +with +``` + uses: gradle/actions/setup-gradle@v3 +``` + ### Using the action to execute Gradle via the `arguments` parameter is deprecated The core functionality of the `setup-gradle` (and `gradle-build-action`) actions is to configure your @@ -32,6 +49,12 @@ steps: uses: gradle/actions/setup-gradle@v3 with: arguments: 'test' + + - name: Run build in a subdirectory + uses: gradle/actions/setup-gradle@v3 + with: + build-root-directory: another-build + arguments: 'build' ``` Then replace this with a single call to `setup-gradle` together with separate `run` steps to execute your build. @@ -45,6 +68,10 @@ Then replace this with a single call to `setup-gradle` together with separate `r - name: Run the tests run: ./gradlew test + +- name: Run build in a subdirectory + working-directory: another-build + run: ./gradlew build ``` Using the action in this way gives you more control over how Gradle is executed, while still giving you @@ -52,24 +79,7 @@ all of the benefits of the `setup-gradle` action. The `arguments` parameter is scheduled to be removed in `setup-gradle@v4`. -Note: if you are using the `gradle-build-action`, [see here](#the-gradle-build-action-has-been-replaced-by-the-setup-gradle-action) for more details on how to migrate. - -### The `gradle-build-action` has been replaced by the `setup-gradle` action - -The `gradle-build-action` action has evolved, so that the core functionality is now to configure the -Gradle environment for GitHub Actions. For clarity and consistency with other action (eg `setup-java`, `setup-node`), the `gradle-build-action` has been replaced by the `setup-gradle` action. - -As of `v3.x`, the `setup-gradle` and `gradle-build-action` actions are functionally identical, -and are released with the same versions. - -To convert your workflows, simply replace: -``` - uses: gradle/gradle-build-action@v3 -``` -with -``` - uses: gradle/actions/setup-gradle@v3 -``` +Note: if you are using the `gradle-build-action`, [see here](#the-action-gradlegradle-build-action-has-been-replaced-by-gradleactionssetup-gradle) for more details on how to migrate. ### The `build-scan-terms-of-service` input parameters have been renamed diff --git a/sources/src/configuration.ts b/sources/src/configuration.ts index 757de18..0b23c61 100644 --- a/sources/src/configuration.ts +++ b/sources/src/configuration.ts @@ -7,6 +7,8 @@ import {SUMMARY_ENV_VAR} from '@actions/core/lib/summary' import {parseArgsStringToArgv} from 'string-argv' import path from 'path' +const ACTION_ID_VAR = 'GRADLE_ACTION_ID' + export class DependencyGraphConfig { getDependencyGraphOption(): DependencyGraphOption { const val = core.getInput('dependency-graph') @@ -272,6 +274,14 @@ export function getWorkspaceDirectory(): string { return process.env[`GITHUB_WORKSPACE`] || '' } +export function getActionId(): string | undefined { + return process.env[ACTION_ID_VAR] +} + +export function setActionId(id: string): void { + core.exportVariable(ACTION_ID_VAR, id) +} + export function parseNumericInput(paramName: string, paramValue: string, paramDefault: number): number { if (paramValue.length === 0) { return paramDefault diff --git a/sources/src/dependency-submission/main.ts b/sources/src/dependency-submission/main.ts index fad29e3..c9e99a9 100644 --- a/sources/src/dependency-submission/main.ts +++ b/sources/src/dependency-submission/main.ts @@ -10,7 +10,8 @@ import { CacheConfig, DependencyGraphConfig, DependencyGraphOption, - GradleExecutionConfig + GradleExecutionConfig, + setActionId } from '../configuration' import {saveDeprecationState} from '../deprecation-collector' @@ -19,6 +20,8 @@ import {saveDeprecationState} from '../deprecation-collector' */ export async function run(): Promise { try { + setActionId('gradle/actions/dependency-submission') + // Configure Gradle environment (Gradle User Home) await setupGradle.setup(new CacheConfig(), new BuildScanConfig()) diff --git a/sources/src/deprecation-collector.ts b/sources/src/deprecation-collector.ts index 5cbc47e..a54a51d 100644 --- a/sources/src/deprecation-collector.ts +++ b/sources/src/deprecation-collector.ts @@ -1,5 +1,5 @@ import * as core from '@actions/core' -import * as github from '@actions/github' +import {getActionId} from './configuration' const DEPRECATION_UPGRADE_PAGE = 'https://github.com/gradle/actions/blob/main/docs/deprecation-upgrade-guide.md' const recordedDeprecations: Deprecation[] = [] @@ -29,7 +29,7 @@ export function getDeprecations(): Deprecation[] { export function emitDeprecationWarnings(): void { if (recordedDeprecations.length > 0) { core.warning( - `This job uses deprecated functionality from the '${github.context.action}' action. Consult the Job Summary for more details.` + `This job uses deprecated functionality from the '${getActionId()}' action. Consult the Job Summary for more details.` ) for (const deprecation of recordedDeprecations) { core.info(`DEPRECATION: ${deprecation.message}. See ${deprecation.getDocumentationLink()}`) diff --git a/sources/src/job-summary.ts b/sources/src/job-summary.ts index 8d711d4..1b40f2b 100644 --- a/sources/src/job-summary.ts +++ b/sources/src/job-summary.ts @@ -3,7 +3,7 @@ import * as github from '@actions/github' import {RequestError} from '@octokit/request-error' import {BuildResult} from './build-results' -import {SummaryConfig, getGithubToken} from './configuration' +import {SummaryConfig, getActionId, getGithubToken} from './configuration' import {Deprecation, getDeprecations} from './deprecation-collector' export async function generateJobSummary( @@ -88,7 +88,8 @@ function renderDeprecations(): string { return '' } return ` -

Deprecated usages of ${github.context.action}

+

Deprecation warnings

+This job uses deprecated functionality from the ${getActionId()} action. Follow the links for upgrade details. diff --git a/sources/src/setup-gradle/main.ts b/sources/src/setup-gradle/main.ts index 665a9e1..1cada07 100644 --- a/sources/src/setup-gradle/main.ts +++ b/sources/src/setup-gradle/main.ts @@ -3,14 +3,29 @@ import * as core from '@actions/core' import * as setupGradle from '../setup-gradle' import * as gradle from '../execution/gradle' import * as dependencyGraph from '../dependency-graph' -import {BuildScanConfig, CacheConfig, DependencyGraphConfig, GradleExecutionConfig} from '../configuration' -import {saveDeprecationState} from '../deprecation-collector' +import { + BuildScanConfig, + CacheConfig, + DependencyGraphConfig, + GradleExecutionConfig, + getActionId, + setActionId +} from '../configuration' +import {recordDeprecation, saveDeprecationState} from '../deprecation-collector' /** * The main entry point for the action, called by Github Actions for the step. */ export async function run(): Promise { try { + if (getActionId() === 'gradle/gradle-build-action') { + recordDeprecation( + 'The action `gradle/gradle-build-action` has been replaced by `gradle/actions/setup-gradle`' + ) + } else { + setActionId('gradle/actions/setup-gradle') + } + // Configure Gradle environment (Gradle User Home) await setupGradle.setup(new CacheConfig(), new BuildScanConfig())