Skip to content
This repository has been archived by the owner on Jan 25, 2024. It is now read-only.

Commit

Permalink
Merge branch 'online-photo-submission-main'
Browse files Browse the repository at this point in the history
  • Loading branch information
mikepenz authored Jul 14, 2023
2 parents 8f010cb + 6f0c1b2 commit 9034250
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 45 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ The following example showcases a gradle module in the root, without a module na
| `include-build-environment` | Optional mode to enable the submission of the `buildEnvironment` as individual Manifest via the dependency submission API. Default: `false`. |
| `fail-on-error` | Optional setting to enable an action failure in case any of the dependencies can not be parsed. Default: `false`. |
| `correlator` | 'Optional correlator string to submit to GitHub to identify the dependency submission. Defaults to generating based on gradle-build-module and gradle-build-configuration.' |
| `legacy-support` | 'Disabled by default. Optional setting to enable support for gradle versions below 7.5. Warning: When enabled, the action will retrieve all properties and retrieve the property value of interest. During the parsing this may include other properties. Prefer to upgrade to gradle 7.5 or newer instead!' |

| **sub-module-mode** | **Description** |
| ----- | ---- |
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ inputs:
required: false
description: 'Optional correlator string to submit to GitHub to identify the dependency submission. Defaults to generating based on gradle-build-module and gradle-build-configuration.'
default: ''
legacy-support:
required: false
description: 'Enables support for gradle versions below 7.5. Note: If enabled, all properties are read by the action as `--property` was only introduced in Gradle 7.5 or newer.'
default: 'false'
runs:
using: 'node16'
main: 'dist/index.js'
63 changes: 41 additions & 22 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gradle-dependency-submission",
"version": "0.8.2",
"version": "v0.9.0",
"private": true,
"description": "Gradle Dependency Submission",
"main": "lib/main.js",
Expand Down
47 changes: 35 additions & 12 deletions src/gradle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export async function singlePropertySupport(useGradlew: boolean, gradleProjectPa
return true
} else {
core.warning(
`The current gradle version does not support retrieving a single property. Found version: ${version}. At least required: 7.5.0`
`The current gradle version does not support retrieving a single property. Found version: ${version}.`
)
return false
}
Expand Down Expand Up @@ -132,19 +132,21 @@ export async function retrieveGradleBuildEnvironment(useGradlew: boolean, gradle
export async function retrieveGradleBuildPath(
useGradlew: boolean,
gradleProjectPath: string,
gradleBuildModule: string
gradleBuildModule: string,
legacySupport: boolean
): Promise<string | undefined> {
return retrieveGradleProperty(useGradlew, gradleProjectPath, gradleBuildModule, 'buildFile')
return retrieveGradleProperty(useGradlew, gradleProjectPath, gradleBuildModule, 'buildFile', legacySupport)
}

/**
* Retrieves the `name` `property` from the configured gradle project.
*/
export async function retrieveGradleProjectName(
useGradlew: boolean,
gradleProjectPath: string
gradleProjectPath: string,
legacySupport: boolean
): Promise<string | undefined> {
return retrieveGradleProperty(useGradlew, gradleProjectPath, ':', 'name')
return retrieveGradleProperty(useGradlew, gradleProjectPath, ':', 'name', legacySupport)
}

/**
Expand All @@ -154,16 +156,27 @@ async function retrieveGradleProperty(
useGradlew: boolean,
gradleProjectPath: string,
gradleBuildModule: string,
property: string
property: string,
legacySupport: boolean
): Promise<string | undefined> {
if (!(await singlePropertySupport(useGradlew, gradleProjectPath))) {
return undefined
}
const singlePropertySupported = await singlePropertySupport(useGradlew, gradleProjectPath)

const command = retrieveGradleCLI(useGradlew)
const module = verifyModule(gradleBuildModule)

const propertyOutput = await exec.getExecOutput(command, [`${module}:properties`, '-q', '--property', property], {
let commandArgs = []
if (singlePropertySupported) {
commandArgs = [`${module}:properties`, '-q', '--property', property]
} else if (legacySupport) {
commandArgs = [`${module}:properties`, '-q']
} else {
core.error(
`To enable support for legacy gradle versions without single property support, enable 'legacy-support'. (This will read all properties, read description before proceeding.)`
)
return undefined
}

const propertyOutput = await exec.getExecOutput(command, commandArgs, {
cwd: gradleProjectPath,
silent: !core.isDebug(),
ignoreReturnCode: true
Expand All @@ -175,9 +188,19 @@ async function retrieveGradleProperty(
}

const output = propertyOutput.stdout
const matched = output.match(new RegExp(`[\\S\\s]*?(${property}: )(.+)\n`))

if (matched != null) {
let matched = null

if (singlePropertySupported) {
matched = output.match(new RegExp(`[\\S\\s]*?(${property}: )(.+)\n`))
} else {
matched = output
.split('\n')
.map(it => it.match(new RegExp(`[\\S\\s]*?(${property}: )(.+)`)))
.find(it => it !== null)
}

if (matched !== null && matched !== undefined) {
return matched[2]
}

Expand Down
9 changes: 6 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ async function run(): Promise<void> {
const includeBuildEnvironment = core.getBooleanInput('include-build-environment')
const failOnError = core.getBooleanInput('fail-on-error')
let correlator = core.getInput('correlator')
const legacySupport = core.getBooleanInput('legacy-support')

// verify inputs are valid
if (gradleProjectPath.length === 0) {
Expand Down Expand Up @@ -90,7 +91,8 @@ async function run(): Promise<void> {
gradleDependencyPath.length !== 0 ? gradleDependencyPath[i] : undefined,
moduleBuildConfigurations,
subModuleMode,
failOnError
failOnError,
legacySupport
)
manifests.push(...subManifests)
}
Expand All @@ -100,7 +102,8 @@ async function run(): Promise<void> {
useGradlew,
gradleProjectPath[0],
undefined,
failOnError
failOnError,
legacySupport
)
manifests.push(...buildEnvironmentManifest)
}
Expand All @@ -109,7 +112,7 @@ async function run(): Promise<void> {
{
name: 'mikepenz/gradle-dependency-submission',
url: 'https://github.com/mikepenz/gradle-dependency-submission',
version: '0.8.2'
version: 'v1.0.1'
},
github.context,
{
Expand Down
15 changes: 9 additions & 6 deletions src/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ export async function prepareDependencyManifest(
gradleDependencyPath: string | undefined,
moduleBuildConfiguration: Map<string, string>,
subModuleMode: 'INDIVIDUAL' | 'INDIVIDUAL_DEEP' | 'COMBINED' | 'IGNORE',
failOnError: boolean
failOnError = false,
legacySupport = false
): Promise<Manifest[]> {
const rootProject = await processDependencyList(
useGradlew,
Expand All @@ -40,7 +41,7 @@ export async function prepareDependencyManifest(
// construct the Manifests
const manifests: Manifest[] = []
for (const result of transformProject(rootProject, subModuleMode)) {
manifests.push(await buildManifest(result, useGradlew, gradleProjectPath))
manifests.push(await buildManifest(result, useGradlew, gradleProjectPath, legacySupport))
}
return manifests
}
Expand All @@ -52,7 +53,8 @@ export async function prepareBuildEnvironmentManifest(
useGradlew: boolean,
gradleProjectPath: string,
gradleDependencyPath: string | undefined,
failOnError: boolean
failOnError: boolean,
legacySupport: boolean
): Promise<Manifest[]> {
const rootProject = await processBuildEnvironmentDependencyList(useGradlew, gradleProjectPath, failOnError)

Expand All @@ -62,7 +64,7 @@ export async function prepareBuildEnvironmentManifest(
// construct the Manifests
const manifests: Manifest[] = []
for (const result of transformProject(rootProject, 'COMBINED')) {
manifests.push(await buildManifest(result, useGradlew, gradleProjectPath, 'buildEnvironment'))
manifests.push(await buildManifest(result, useGradlew, gradleProjectPath, legacySupport, 'buildEnvironment'))
}
return manifests
}
Expand Down Expand Up @@ -145,13 +147,14 @@ async function buildManifest(
result: Result,
useGradlew: boolean,
gradleProjectPath: string,
legacySupport: boolean,
manifestName: string | undefined = undefined
): Promise<Manifest> {
const {project, packageCache, directDependencies, indirectDependencies} = result

let dependencyPath: string
if (project.dependencyPath === undefined) {
const buildPath = await retrieveGradleBuildPath(useGradlew, gradleProjectPath, project.name)
const buildPath = await retrieveGradleBuildPath(useGradlew, gradleProjectPath, project.name, legacySupport)
if (buildPath === undefined) {
core.setFailed(`🚨 Could not retrieve the gradle dependency path (to the build.gradle) for ${project.name}`)
throw new Error(`Failed to retrieve gradle build path.`)
Expand All @@ -166,7 +169,7 @@ async function buildManifest(
let name = manifestName || path.dirname(dependencyPath)
if (name === '.') {
// if no project name is available, retrieve it from gradle or fallback to `dependencyPath`
name = (await retrieveGradleProjectName(useGradlew, gradleProjectPath)) || dependencyPath
name = (await retrieveGradleProjectName(useGradlew, gradleProjectPath, legacySupport)) || dependencyPath
}
const manifest = new Manifest(name, dependencyPath)
core.info(`Connection ${directDependencies.length} direct dependencies`)
Expand Down

0 comments on commit 9034250

Please sign in to comment.