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

Commit

Permalink
Merge pull request #221 from mikepenz/feature/fail_on_error
Browse files Browse the repository at this point in the history
Add option to configure `fail-on-error`
  • Loading branch information
mikepenz committed Feb 28, 2023
2 parents ae1c621 + 7e91645 commit 5aac1cd
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 54 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ The following example showcases a gradle module in the root, without a module na
| `gradle-dependency-path` | Defines the path to the gradle dependency file, relative to the `gradle-project-path`. If not provided, automatically resolved via gradle and the `module` config. |
| `sub-module-mode` | Defines how the action handles sub projects/modules. Possible options `IGNORE`, `COMBINED`, `INDIVIDUAL`, `INDIVIDUAL_DEEP`. Default: `IGNORE`. |
| `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.' |

| **sub-module-mode** | **Description** |
Expand Down
10 changes: 5 additions & 5 deletions __tests__/parse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,35 +122,35 @@ jest.setTimeout(180000)

describe('parseGradleDependencyOutput', () => {
test('parses output of gradle dependency command into dependencies', () => {
const dependencies = parseGradleGraph('test', GRADLE_DEPENDENCY_OUTPUT).packages
const dependencies = parseGradleGraph('test', GRADLE_DEPENDENCY_OUTPUT, 'IGNORE', false).packages

expect(Object.values(dependencies).length).toEqual(GRADLE_EXAMPLE_DEPENDENCY_OUTPUT.length)
expect(dependencies).toEqual(GRADLE_EXAMPLE_DEPENDENCY_OUTPUT)
})

test('parses output of gradle dependency command with unresolved dependencies', () => {
const dependencies = parseGradleGraph('test', GRADLE_DEPENDENCY_OUTPUT_UNRESOLVED).packages
const dependencies = parseGradleGraph('test', GRADLE_DEPENDENCY_OUTPUT_UNRESOLVED, 'IGNORE', false).packages

expect(Object.values(dependencies).length).toEqual(GRADLE_EXAMPLE_DEPENDENCY_OUTPUT_UNRESOLVED.length)
expect(dependencies).toEqual(GRADLE_EXAMPLE_DEPENDENCY_OUTPUT_UNRESOLVED)
})

test('parses output of gradle dependency command with unspecified dependencies', () => {
const dependencies = parseGradleGraph('test', GRADLE_DEPENDENCY_OUTPUT_UNSPECIFIED).packages
const dependencies = parseGradleGraph('test', GRADLE_DEPENDENCY_OUTPUT_UNSPECIFIED, 'IGNORE', false).packages

expect(Object.values(dependencies).length).toEqual(GRADLE_EXAMPLE_DEPENDENCY_OUTPUT_UNSPECIFIED.length)
expect(dependencies).toEqual(GRADLE_EXAMPLE_DEPENDENCY_OUTPUT_UNSPECIFIED)
})

test('parses output of gradle dependency command with bom into dependencies', () => {
const dependencies = parseGradleGraph('test', GRADLE_DEPENDENCY_OUTPUT_SPRING).packages
const dependencies = parseGradleGraph('test', GRADLE_DEPENDENCY_OUTPUT_SPRING, 'IGNORE', false).packages

expect(Object.values(dependencies).length).toEqual(GRADLE_EXAMPLE_DEPENDENCY_OUTPUT_SPRING.length)
expect(dependencies).toEqual(GRADLE_EXAMPLE_DEPENDENCY_OUTPUT_SPRING)
})

test('parses output of gradle dependency command with sub projects', () => {
const rootProject = parseGradleGraph('test', fs.readFileSync('__tests__/elasticoutput.txt', 'utf8'), 'INDIVIDUAL')
const rootProject = parseGradleGraph('test', fs.readFileSync('__tests__/elasticoutput.txt', 'utf8'), 'INDIVIDUAL', false)
expect(rootProject).toEqual(GRADLE_EXAMPLE_DEPENDENCY_WITH_SUB_PROJECTS_OUTPUT)
})
})
21 changes: 13 additions & 8 deletions __tests__/process.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jest.setTimeout(240000)
describe('processBuildEnvironmentDependencyList', () => {
process.env['GITHUB_WORKSPACE'] = '.'
test('run in gradle-example', async () => {
const project = await processBuildEnvironmentDependencyList(true, 'gradle-example')
const project = await processBuildEnvironmentDependencyList(true, 'gradle-example', false)
const dependencies = project.packages
expect(dependencies).toHaveLength(BUILD_ENVIRONMENT_EXPECTED_OUTPUT.length)
expect(dependencies).toEqual(BUILD_ENVIRONMENT_EXPECTED_OUTPUT)
Expand All @@ -31,7 +31,8 @@ describe('processDependencyList', () => {
':app',
'debugCompileClasspath',
new Map<string, string>(),
'IGNORE'
'IGNORE',
false
)
const dependencies = project.packages
expect(dependencies).toHaveLength(EXPECTED_GRADLE_DEPENDENCY_OUTPUT.length)
Expand All @@ -40,14 +41,14 @@ describe('processDependencyList', () => {

test('run in gradle-example with invalid configuration', async () => {
try {
await processDependencyList(true, 'gradle-example', ':app', 'non-existing', new Map<string, string>(), 'IGNORE')
await processDependencyList(true, 'gradle-example', ':app', 'non-existing', new Map<string, string>(), 'IGNORE', false)
} catch (error: any) {
expect(error.message).toEqual("Failed to execute './gradlew :app:dependencies --configuration non-existing'")
}
})

test('run in root', async () => {
const project = await processDependencyList(false, '', ':', 'compileClasspath', new Map<string, string>(), 'IGNORE')
const project = await processDependencyList(false, '', ':', 'compileClasspath', new Map<string, string>(), 'IGNORE', false)
const dependencies = project.packages
expect(dependencies).toHaveLength(EXPECTED_ROOT_GRADLE_DEPENDENCY_OUTPUT.length)
expect(dependencies).toEqual(EXPECTED_ROOT_GRADLE_DEPENDENCY_OUTPUT)
Expand All @@ -63,7 +64,8 @@ describe('prepareDependencyManifest', () => {
'debugCompileClasspath',
undefined,
new Map<string, string>(),
'IGNORE'
'IGNORE',
false
)
expect(manifests).toHaveLength(EXPECTED_GRADLE_DEPENDENCY_MULTI_LEVEL_OUTPUT_IGNORE.length)
expect(manifests).toEqual(EXPECTED_GRADLE_DEPENDENCY_MULTI_LEVEL_OUTPUT_IGNORE)
Expand All @@ -77,7 +79,8 @@ describe('prepareDependencyManifest', () => {
'debugCompileClasspath',
undefined,
new Map<string, string>(),
'COMBINED'
'COMBINED',
false
)
expect(manifests).toHaveLength(EXPECTED_GRADLE_DEPENDENCY_MULTI_LEVEL_OUTPUT_COMBINED.length)
expect(manifests).toEqual(EXPECTED_GRADLE_DEPENDENCY_MULTI_LEVEL_OUTPUT_COMBINED)
Expand All @@ -91,7 +94,8 @@ describe('prepareDependencyManifest', () => {
'debugCompileClasspath',
undefined,
new Map<string, string>(),
'INDIVIDUAL'
'INDIVIDUAL',
false
)
expect(manifests).toHaveLength(EXPECTED_GRADLE_DEPENDENCY_MULTI_LEVEL_OUTPUT_INDIVIDUAL.length)
expect(manifests).toEqual(EXPECTED_GRADLE_DEPENDENCY_MULTI_LEVEL_OUTPUT_INDIVIDUAL)
Expand All @@ -105,7 +109,8 @@ describe('prepareDependencyManifest', () => {
"",
undefined,
new Map<string, string>(),
'IGNORE'
'IGNORE',
false
)

expect(manifest).toHaveLength(EXPECTED_GRADLE_DEPENDENCY_UNFILTERED.length)
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ inputs:
required: false
description: 'Optional mode to also submit the `buildEnvironment` to the dependency submission API. This will execute the `buildEnvironment` task on the root module.'
default: 'false'
fail-on-error:
required: false
description: 'Optional setting to enable an action failure in case any of the dependencies can not be parsed. Default: `false`.'
default: 'false'
correlator:
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.'
Expand Down
51 changes: 31 additions & 20 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.

11 changes: 9 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ async function run(): Promise<void> {
let subModuleMode: 'INDIVIDUAL' | 'INDIVIDUAL_DEEP' | 'COMBINED' | 'IGNORE'
const subModuleModeInput = core.getInput('sub-module-mode')
const includeBuildEnvironment = core.getBooleanInput('include-build-environment')
const failOnError = core.getBooleanInput('fail-on-error')
let correlator = core.getInput('correlator')

// verify inputs are valid
Expand Down Expand Up @@ -88,13 +89,19 @@ async function run(): Promise<void> {
configuration,
gradleDependencyPath.length !== 0 ? gradleDependencyPath[i] : undefined,
moduleBuildConfigurations,
subModuleMode
subModuleMode,
failOnError
)
manifests.push(...subManifests)
}

if (includeBuildEnvironment) {
const buildEnvironmentManifest = await prepareBuildEnvironmentManifest(useGradlew, gradleProjectPath[0], undefined)
const buildEnvironmentManifest = await prepareBuildEnvironmentManifest(
useGradlew,
gradleProjectPath[0],
undefined,
failOnError
)
manifests.push(...buildEnvironmentManifest)
}

Expand Down

0 comments on commit 5aac1cd

Please sign in to comment.