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

Commit

Permalink
- [release] v0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mikepenz authored Jul 27, 2022
1 parent 2a5a3b0 commit 03ac371
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 90 deletions.
2 changes: 1 addition & 1 deletion .prettierrc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"printWidth": 80,
"printWidth": 120,
"tabWidth": 2,
"useTabs": false,
"semi": false,
Expand Down
18 changes: 5 additions & 13 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.

4 changes: 2 additions & 2 deletions package-lock.json

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

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.0.6",
"version": "0.1.0",
"private": true,
"description": "Gradle Dependency Submission",
"main": "lib/main.js",
Expand Down
22 changes: 5 additions & 17 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import * as core from '@actions/core'
import * as github from '@actions/github'
import {
Snapshot,
Manifest,
submitSnapshot
} from '@github/dependency-submission-toolkit'
import {Snapshot, Manifest, submitSnapshot} from '@github/dependency-submission-toolkit'
import {prepareDependencyManifest} from './process'

async function run(): Promise<void> {
Expand All @@ -16,14 +12,8 @@ async function run(): Promise<void> {
const gradleDependencyPath = core.getMultilineInput('gradle-dependency-path')

const length = gradleProjectPath.length
if (
[gradleBuildModule, gradleBuildConfiguration, gradleDependencyPath].some(
x => x.length !== length
)
) {
core.setFailed(
'When passing multiple projects, all inputs must have the same amount of items'
)
if ([gradleBuildModule, gradleBuildConfiguration, gradleDependencyPath].some(x => x.length !== length)) {
core.setFailed('When passing multiple projects, all inputs must have the same amount of items')
return
}

Expand All @@ -47,13 +37,11 @@ async function run(): Promise<void> {
{
name: 'mikepenz/gradle-dependency-submission',
url: 'https://github.com/mikepenz/gradle-dependency-submission',
version: '0.0.6'
version: '0.1.0'
},
github.context,
{
correlator: `${github.context.job}-${gradleBuildModule.join(
'-'
)}-${gradleBuildConfiguration}`,
correlator: `${github.context.job}-${gradleBuildModule.join('-')}-${gradleBuildConfiguration}`,
id: github.context.runId.toString()
}
)
Expand Down
38 changes: 8 additions & 30 deletions src/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ const DEPENDENCY_OMITTED = ' (*)'
const DEPENDENCY_LEVEL_INLINE = 5

export function parseGradlePackage(pkg: string, level = 0): PackageURL {
const stripped = pkg
.substring((level + 1) * DEPENDENCY_LEVEL_INLINE)
.trimEnd()
const stripped = pkg.substring((level + 1) * DEPENDENCY_LEVEL_INLINE).trimEnd()
const split = stripped.split(':')
if (split.length < 3) {
core.error(`Could not parse package: '${pkg}'`)
Expand All @@ -22,10 +20,7 @@ export function parseGradlePackage(pkg: string, level = 0): PackageURL {

let strippedLineEnd = lineEnd

if (
lineEnd.endsWith(DEPENDENCY_CONSTRAINT) ||
lineEnd.endsWith(DEPENDENCY_OMITTED)
) {
if (lineEnd.endsWith(DEPENDENCY_CONSTRAINT) || lineEnd.endsWith(DEPENDENCY_OMITTED)) {
strippedLineEnd = lineEnd.substring(0, lineEnd.length - 4)
}
const endParts = strippedLineEnd.trim().split(' -> ')
Expand All @@ -35,28 +30,16 @@ export function parseGradlePackage(pkg: string, level = 0): PackageURL {
} else {
version = endParts[endParts.length - 1].trim()
}
return new PackageURL(
'maven',
packageName,
libraryName,
version ?? null,
null,
null
)
return new PackageURL('maven', packageName, libraryName, version ?? null, null, null)
}

/**
* parseGoModGraph parses an *associative list* of Go packages into tuples into
* an associative list of PackageURLs. This expects the output of 'go mod
* graph' as input
*/
export function parseGradleGraph(
gradleBuildModule: string,
contents: string
): [PackageURL, PackageURL | undefined][] {
core.startGroup(
`📄 Parsing gradle dependencies graph - '${gradleBuildModule}'`
)
export function parseGradleGraph(gradleBuildModule: string, contents: string): [PackageURL, PackageURL | undefined][] {
core.startGroup(`📄 Parsing gradle dependencies graph - '${gradleBuildModule}'`)
const pkgAssocList: [PackageURL, PackageURL | undefined][] = []
const linesIterator = new PeekingIterator(contents.split('\n').values())

Expand Down Expand Up @@ -87,8 +70,7 @@ export function parseGradleDependency(
if (
level !== 0 &&
!(
peekedLine.startsWith(DEPENDENCY_DEPENDENCY_LEVEL_START) ||
peekedLine.startsWith(DEPENDENCY_DEPENDENCY_LEVEL_END)
peekedLine.startsWith(DEPENDENCY_DEPENDENCY_LEVEL_START) || peekedLine.startsWith(DEPENDENCY_DEPENDENCY_LEVEL_END)
)
) {
return
Expand All @@ -104,9 +86,7 @@ export function parseGradleDependency(
const strippedLine = line.substring(level * DEPENDENCY_LEVEL_INLINE)

if (line.startsWith(DEPENDENCY_PROJECT_START)) {
core.info(
`Found a project dependency, skipping (Currently not supported) - ${line}`
)
core.info(`Found a project dependency, skipping (Currently not supported) - ${line}`)
iterator.next() // consume the next item
continue
} else if (
Expand All @@ -130,9 +110,7 @@ export function parseGradleDependency(
strippedLine.startsWith(DEPENDENCY_CHILD_INSET[0]) ||
strippedLine.startsWith(DEPENDENCY_CHILD_INSET[1])
) {
core.debug(
`Found a child dependency at an unsupported level, skipping. '${strippedLine}'`
)
core.debug(`Found a child dependency at an unsupported level, skipping. '${strippedLine}'`)
iterator.next() // consume the next item
continue
} else if (level === 0) {
Expand Down
36 changes: 11 additions & 25 deletions src/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,21 @@ export async function prepareDependencyManifest(
gradleBuildConfiguration: string,
gradleDependencyPath: string
): Promise<Manifest> {
const {packageCache, directDependencies, indirectDependencies} =
await processGradleGraph(
useGradlew,
gradleProjectPath,
gradleBuildModule,
gradleBuildConfiguration
)
const {packageCache, directDependencies, indirectDependencies} = await processGradleGraph(
useGradlew,
gradleProjectPath,
gradleBuildModule,
gradleBuildConfiguration
)

core.startGroup(`📦️ Preparing Dependency Snapshot - '${gradleBuildModule}'`)
const manifest = new Manifest(
path.dirname(gradleDependencyPath),
path.join(gradleProjectPath, gradleDependencyPath)
)
const manifest = new Manifest(path.dirname(gradleDependencyPath), path.join(gradleProjectPath, gradleDependencyPath))

for (const pkgUrl of directDependencies) {
const dep = packageCache.lookupPackage(pkgUrl)
if (!dep) {
core.setFailed(`🚨 Missing direct dependency: ${pkgUrl}`)
throw new Error(
'assertion failed: expected all direct dependencies to have entries in PackageCache'
)
throw new Error('assertion failed: expected all direct dependencies to have entries in PackageCache')
}
manifest.addDirectDependency(dep)
}
Expand All @@ -41,9 +35,7 @@ export async function prepareDependencyManifest(
const dep = packageCache.lookupPackage(pkgUrl)
if (!dep) {
core.setFailed(`🚨 Missing indirect dependency: ${pkgUrl}`)
throw new Error(
'assertion failed: expected all indirect dependencies to have entries in PackageCache'
)
throw new Error('assertion failed: expected all indirect dependencies to have entries in PackageCache')
}
manifest.addIndirectDependency(dep)
}
Expand Down Expand Up @@ -109,18 +101,12 @@ export async function processDependencyList(
const command = useGradlew ? './gradlew' : 'gradle'
const dependencyList = await exec.getExecOutput(
command,
[
`${gradleBuildModule}:dependencies`,
'--configuration',
gradleBuildConfiguration
],
[`${gradleBuildModule}:dependencies`, '--configuration', gradleBuildConfiguration],
{cwd: gradleProjectPath}
)
if (dependencyList.exitCode !== 0) {
core.error(dependencyList.stderr)
core.setFailed(
`'gradle ${gradleBuildModule}:dependencies resolution' failed!`
)
core.setFailed(`'gradle ${gradleBuildModule}:dependencies resolution' failed!`)
throw new Error("Failed to execute 'gradle dependencies'")
}

Expand Down

0 comments on commit 03ac371

Please sign in to comment.