mirror of
https://github.com/gradle/actions.git
synced 2026-09-10 19:28:33 +08:00
Report patches available for version
This commit is contained in:
@@ -1,60 +1,129 @@
|
||||
import * as core from '@actions/core'
|
||||
import * as semver from 'semver'
|
||||
|
||||
import {GradleVersion} from './execution/gradle-version'
|
||||
import wrapperChecksums from './wrapper-validation/wrapper-checksums.json'
|
||||
|
||||
const FEATURE_LIFECYCLE_DOC = 'https://docs.gradle.org/current/userguide/feature_lifecycle.html#eol_support'
|
||||
|
||||
const LATEST_RELEASED_MAJOR = determineLatestReleasedMajor(wrapperChecksums.map(entry => entry.version))
|
||||
const RELEASED_VERSIONS = wrapperChecksums
|
||||
.map(entry => entry.version)
|
||||
.filter(version => new GradleVersion(version).isFinalRelease())
|
||||
|
||||
export type SupportStatus = 'active' | 'maintenance' | 'eol'
|
||||
const LATEST_RELEASED_MAJOR = determineLatestReleasedMajor(RELEASED_VERSIONS)
|
||||
|
||||
export function determineLatestReleasedMajor(versions: string[]): number | undefined {
|
||||
const LATEST_PATCHES = latestPatchByMinorLine(RELEASED_VERSIONS)
|
||||
|
||||
export enum SupportStatusKind {
|
||||
Active = 'active',
|
||||
Maintenance = 'maintenance',
|
||||
Eol = 'eol',
|
||||
PatchAvailable = 'patch-available'
|
||||
}
|
||||
|
||||
export type SupportStatus =
|
||||
| {kind: SupportStatusKind.Active}
|
||||
| {kind: SupportStatusKind.Maintenance}
|
||||
| {kind: SupportStatusKind.Eol}
|
||||
| {kind: SupportStatusKind.PatchAvailable; newerPatch: string}
|
||||
|
||||
function determineLatestReleasedMajor(versions: string[]): number {
|
||||
const releasedMajors = versions
|
||||
.map(version => new GradleVersion(version))
|
||||
.filter(parsed => parsed.isFinalRelease())
|
||||
.map(parsed => parsed.major)
|
||||
return releasedMajors.length > 0 ? Math.max(...releasedMajors) : undefined
|
||||
return Math.max(0, ...releasedMajors)
|
||||
}
|
||||
|
||||
export function getSupportStatus(version: GradleVersion, latestMajor: number): SupportStatus {
|
||||
type LatestPatches = Map<string, semver.SemVer>
|
||||
|
||||
function getSupportStatus(version: GradleVersion, latestMajor: number, latestPatches: LatestPatches): SupportStatus {
|
||||
switch (Math.max(0, latestMajor - version.major)) {
|
||||
case 0:
|
||||
return 'active'
|
||||
case 0: {
|
||||
const newerPatch = findNewerPatch(version.version, latestPatches)
|
||||
return newerPatch ? {kind: SupportStatusKind.PatchAvailable, newerPatch} : {kind: SupportStatusKind.Active}
|
||||
}
|
||||
case 1:
|
||||
return 'maintenance'
|
||||
return {kind: SupportStatusKind.Maintenance}
|
||||
default:
|
||||
return 'eol'
|
||||
return {kind: SupportStatusKind.Eol}
|
||||
}
|
||||
}
|
||||
|
||||
export function supportStatusOf(gradleVersion: string): SupportStatus | undefined {
|
||||
if (LATEST_RELEASED_MAJOR === undefined) {
|
||||
function latestPatchByMinorLine(releasedVersions: string[]): LatestPatches {
|
||||
const latestPatches: LatestPatches = new Map()
|
||||
for (const released of releasedVersions) {
|
||||
const version = semver.coerce(released)
|
||||
if (!version) {
|
||||
continue
|
||||
}
|
||||
const minorLine = `${version.major}.${version.minor}`
|
||||
const known = latestPatches.get(minorLine)
|
||||
if (!known || semver.gt(version, known)) {
|
||||
latestPatches.set(minorLine, version)
|
||||
}
|
||||
}
|
||||
return latestPatches
|
||||
}
|
||||
|
||||
function findNewerPatch(gradleVersion: string, latestPatches: LatestPatches): string | undefined {
|
||||
const current = semver.coerce(gradleVersion)
|
||||
if (!current || !new GradleVersion(gradleVersion).isFinalRelease()) {
|
||||
return undefined
|
||||
}
|
||||
return getSupportStatus(new GradleVersion(gradleVersion), LATEST_RELEASED_MAJOR)
|
||||
|
||||
const latest = latestPatches.get(`${current.major}.${current.minor}`)
|
||||
return latest && semver.gt(latest, current) ? latest.version : undefined
|
||||
}
|
||||
|
||||
export function supportStatusOf(gradleVersion: string): SupportStatus {
|
||||
return getSupportStatus(new GradleVersion(gradleVersion), LATEST_RELEASED_MAJOR, LATEST_PATCHES)
|
||||
}
|
||||
|
||||
/** Entry point for tests */
|
||||
export function supportStatusUsing(gradleVersion: string, releasedVersions: string[]): SupportStatus {
|
||||
return getSupportStatus(
|
||||
new GradleVersion(gradleVersion),
|
||||
determineLatestReleasedMajor(releasedVersions),
|
||||
latestPatchByMinorLine(releasedVersions)
|
||||
)
|
||||
}
|
||||
|
||||
export function reportSupportStatus(gradleVersions: string[]): void {
|
||||
if (LATEST_RELEASED_MAJOR === undefined) {
|
||||
return
|
||||
}
|
||||
reportOutdatedVersions(gradleVersions, LATEST_RELEASED_MAJOR, LATEST_PATCHES)
|
||||
}
|
||||
|
||||
/** Entry point for tests */
|
||||
export function reportSupportStatusUsing(gradleVersions: string[], releasedVersions: string[]): void {
|
||||
reportOutdatedVersions(
|
||||
gradleVersions,
|
||||
determineLatestReleasedMajor(releasedVersions),
|
||||
latestPatchByMinorLine(releasedVersions)
|
||||
)
|
||||
}
|
||||
|
||||
function reportOutdatedVersions(gradleVersions: string[], latestMajor: number, latestPatches: LatestPatches): void {
|
||||
for (const gradleVersion of new Set(gradleVersions)) {
|
||||
const version = new GradleVersion(gradleVersion)
|
||||
switch (getSupportStatus(version, LATEST_RELEASED_MAJOR)) {
|
||||
case 'eol':
|
||||
core.warning(eolMessage(version, LATEST_RELEASED_MAJOR), {title: 'Gradle version at end-of-life'})
|
||||
const support = getSupportStatus(version, latestMajor, latestPatches)
|
||||
switch (support.kind) {
|
||||
case SupportStatusKind.Eol:
|
||||
core.warning(eolMessage(version, latestMajor), {title: 'Gradle version at end-of-life'})
|
||||
break
|
||||
case 'maintenance':
|
||||
core.notice(maintenanceMessage(version, LATEST_RELEASED_MAJOR), {
|
||||
title: 'Gradle version in maintenance'
|
||||
})
|
||||
case SupportStatusKind.Maintenance:
|
||||
core.notice(maintenanceMessage(version, latestMajor), {title: 'Gradle version in maintenance'})
|
||||
break
|
||||
case SupportStatusKind.PatchAvailable:
|
||||
core.notice(patchMessage(version, support.newerPatch), {title: 'Gradle patch update available'})
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function patchMessage(version: GradleVersion, newerPatch: string): string {
|
||||
return `Gradle ${version.version} is not the latest patch release: Gradle ${newerPatch} is available in the same release line, and upgrading is recommended. See ${FEATURE_LIFECYCLE_DOC}`
|
||||
}
|
||||
|
||||
function eolMessage(version: GradleVersion, latestMajor: number): string {
|
||||
return `Gradle ${version.version} has reached end-of-life: the ${version.major}.x release line no longer receives bug fixes or security fixes. Gradle ${latestMajor}.x is the current release line, and upgrading is recommended. See ${FEATURE_LIFECYCLE_DOC}`
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import {CacheReport} from './cache-service'
|
||||
import {ProviderNote, renderCachingReport} from './caching-report'
|
||||
import {DependencyGraphConfig, getActionId, getGithubToken, getJobMatrix, SummaryConfig} from './configuration'
|
||||
import {Deprecation, getDeprecations, getErrors} from './deprecation-collector'
|
||||
import {supportStatusOf} from './gradle-support-status'
|
||||
import {SupportStatusKind, supportStatusOf} from './gradle-support-status'
|
||||
|
||||
const FEATURE_LIFECYCLE_DOC = 'https://docs.gradle.org/current/userguide/feature_lifecycle.html#eol_support'
|
||||
|
||||
@@ -169,11 +169,14 @@ function renderBuildResultRow(result: BuildResult): string {
|
||||
}
|
||||
|
||||
function renderGradleVersion(gradleVersion: string): string {
|
||||
switch (supportStatusOf(gradleVersion)) {
|
||||
case 'eol':
|
||||
const support = supportStatusOf(gradleVersion)
|
||||
switch (support.kind) {
|
||||
case SupportStatusKind.Eol:
|
||||
return `${gradleVersion} <span title="End-of-life: no longer receives bug fixes or security fixes">:warning:</span>`
|
||||
case 'maintenance':
|
||||
case SupportStatusKind.Maintenance:
|
||||
return `${gradleVersion} <span title="Maintenance only: receives critical bug fixes and security fixes only">:information_source:</span>`
|
||||
case SupportStatusKind.PatchAvailable:
|
||||
return `${gradleVersion} <span title="Patch update available: Gradle ${support.newerPatch}">:information_source:</span>`
|
||||
default:
|
||||
return gradleVersion
|
||||
}
|
||||
@@ -182,7 +185,7 @@ function renderGradleVersion(gradleVersion: string): string {
|
||||
function renderOutdatedVersions(results: BuildResult[]): string {
|
||||
const hasOutdatedVersion = results
|
||||
.map(result => supportStatusOf(result.gradleVersion))
|
||||
.some(status => status === 'eol' || status === 'maintenance')
|
||||
.some(support => support.kind === SupportStatusKind.Eol || support.kind === SupportStatusKind.Maintenance)
|
||||
if (!hasOutdatedVersion) {
|
||||
return ''
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user