Preparing for new location

This commit is contained in:
Peter Murray
2022-08-12 12:15:51 +00:00
committed by GitHub
parent b0ccd5d3fa
commit 411752e8de
28 changed files with 24074 additions and 1 deletions
+9
View File
@@ -0,0 +1,9 @@
{
"image": "ghcr.io/octodemo/container-nodejs-development:base-20220830",
"extensions": [
"Orta.vscode-jest",
],
// Install JDK and Maven for testing purposes
"postCreateCommand": ".devcontainer/install_maven.sh",
"postStartCommand": "npm install"
}
+20
View File
@@ -0,0 +1,20 @@
#!/bin/bash
echo -x
JDK_VERSION="18.0.2.1"
JDK_INSTALLER="/tmp/openjdk.tar.gz"
MVN_VERSION="3.8.6"
MVN_INSTALLER="/tmp/mvn.tar.gz"
wget https://download.java.net/java/GA/jdk${JDK_VERSION}/db379da656dc47308e138f21b33976fa/1/GPL/openjdk-${JDK_VERSION}_linux-x64_bin.tar.gz -O ${JDK_INSTALLER}
tar -xC /usr/local/sbin -vf ${JDK_INSTALLER}
ln -s /usr/local/sbin/jdk-${JDK_VERSION}/bin/java /usr/local/sbin/java
ln -s /usr/local/sbin/jdk-${JDK_VERSION}/bin/javac /usr/local/sbin/javac
wget https://dlcdn.apache.org/maven/maven-3/${MVN_VERSION}/binaries/apache-maven-${MVN_VERSION}-bin.tar.gz -O ${MVN_INSTALLER}
tar -xC /usr/local/sbin -vf ${MVN_INSTALLER}
ln -s /usr/local/sbin/apache-maven-${MVN_VERSION}/bin/mvn /usr/local/sbin/mvn
+24
View File
@@ -0,0 +1,24 @@
name: Test Local Action
on:
workflow_dispatch:
inputs:
directory:
type: string
default: test-data/maven/simple
required: true
jobs:
test:
name: Test
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Run local Action
uses: ./
with:
directory: ${{ inputs.directory }}
+5
View File
@@ -0,0 +1,5 @@
lib
node_modules
target
+26
View File
@@ -0,0 +1,26 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
<<<<<<< HEAD
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}/node_modules/.bin/mocha",
"args": [
"-r",
"ts-node/register",
"--colors",
"${workspaceFolder}/src/depgraph.test.ts"
],
}
=======
>>>>>>> 4b5ca60 (Initial commit)
]
}
+48
View File
@@ -0,0 +1,48 @@
{
<<<<<<< HEAD
"debug.onTaskErrors": "showErrors",
"files.trimTrailingWhitespace": true,
"editor.tabSize": 2,
"editor.insertSpaces": true,
"editor.detectIndentation": false,
"[javascript]": {
"editor.tabSize": 2
},
"[json]": {
"editor.tabSize": 2
},
"[yaml]": {
"editor.tabSize": 2
},
"[html]": {
"editor.tabSize": 2
},
// GitHub Codespace Theme
"workbench.colorTheme": "GitHub Dark Dimmed"
}
=======
"debug.onTaskErrors": "showErrors",
"files.trimTrailingWhitespace": true,
"editor.tabSize": 2,
"editor.insertSpaces": true,
"editor.detectIndentation": false,
"[javascript]": {
"editor.tabSize": 2
},
"[json]": {
"editor.tabSize": 2
},
"[yaml]": {
"editor.tabSize": 2
},
"[html]": {
"editor.tabSize": 2
},
// GitHub Codespace Theme
"workbench.colorTheme": "GitHub Dark Dimmed",
"jest.autoRun": {
"watch": false,
"onSave": "test-file"
}
}
>>>>>>> 4b5ca60 (Initial commit)
+74
View File
@@ -0,0 +1,74 @@
# Contributor Covenant Code of Conduct
## Our Pledge
In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, gender identity and expression, level of experience,
nationality, personal appearance, race, religion, or sexual identity and
orientation.
## Our Standards
Examples of behavior that contributes to creating a positive environment
include:
* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting
## Our Responsibilities
Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.
Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.
## Scope
This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at opensource@github.com. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.
Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at [http://contributor-covenant.org/version/1/4][version]
[homepage]: http://contributor-covenant.org
[version]: http://contributor-covenant.org/version/1/4/
+31
View File
@@ -0,0 +1,31 @@
## Contributing
[fork]: https://github.com/advanced-security/maven-dependency-submission-action/fork
[pr]: https://github.com/advanced-security/maven-dependency-submission-action/compare
[code-of-conduct]: CODE_OF_CONDUCT.md
Hi there! We're thrilled that you'd like to contribute to this project. Your help is essential for keeping it great.
Contributions to this project are [released](https://help.github.com/articles/github-terms-of-service/#6-contributions-under-repository-license) to the public under the [project's open source license](LICENSE.txt).
Please note that this project is released with a [Contributor Code of Conduct][code-of-conduct]. By participating in this project you agree to abide by its terms.
## Submitting a pull request
0. [Fork][fork] and clone the repository
0. Create a new branch: `git checkout -b my-branch-name`
0. Make your change, add tests, and make sure the tests still pass
0. Push to your fork and [submit a pull request][pr]
0. Pat your self on the back and wait for your pull request to be reviewed and merged.
Here are a few things you can do that will increase the likelihood of your pull request being accepted:
- Write tests.
- Keep your change as focused as possible. If there are multiple changes you would like to make that are not dependent upon each other, consider submitting them as separate pull requests.
- Write a [good commit message](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html).
## Resources
- [How to Contribute to Open Source](https://opensource.guide/how-to-contribute/)
- [Using Pull Requests](https://help.github.com/articles/about-pull-requests/)
- [GitHub Help](https://help.github.com)
+21
View File
@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2022 GitHub, Inc
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+48 -1
View File
@@ -1 +1,48 @@
# maven-dependency-tree-action # maven-dependency-submission-action
This is a GitHub Action that will generate a complete dependency graph for a Maven project and submit the graph to the GitHub repository so that the graph is complete and includes all the transitive dependencies.
The action will invoke maven using the `com.github.ferstl:depgraph-maven-plugin:4.0.1` plugin to generate JSON output of the complete dependency graph, which is then processed and submitted using the [Dependency Submission Toolkit](https://github.com/github/dependency-submission-toolkit) to the GitHub repository.
> **Warning** The dependency submission APIs and toolkit are still currently in beta and as such subject to changes in future releases.
## Usage
### Pre-requisites
For this action to work properly, you must have the Maven available on PATH (`mvn`) and configured to be able to access and pull your dependencies from whatever sources you have defined (i.e. a properly configured settings.xml or all details provided in the POM).
### Inputs
* `directory` - The directory that contains the `pom.xml` that will be used to generate the dependency graph from. Defaults to the `github.workspace` which is where the source will check out to by default when using `actions/checkout` .
* `token` - The GitHub token that will be used to submit the generated dependency snapshot to the repository. Defaults to the `github.token` from the actions environment.
## Examples
Generating and submitting a dependency snapshot using the defaults:
```
- name: Submit Dependency Snapshot
uses: advanced-security/maven-dependency-submission-action@v1
```
Upon success it will generate a snapshot captured from Maven POM like;
![Screenshot 2022-08-15 at 09 33 47](https://user-images.githubusercontent.com/681306/184603264-3cd69fda-75ff-4a46-b014-630acab60fab.png)
## Limitations
Currently the action is limited to single module Maven projects, with a future update that will add support for multi-module based projects.
## Development
To develop on this project, a Codespace has been provided that will provide all the necessary tools and installation of a JDK and Maven for the test suite to pass. Just opne a Codespace and you can start to develop in the quickest possible timeframe.
The codebase is in TypeScript to make it easier for maintenance.
The source code lives under `src` and the Action is provided in the `src/index.ts` file.
To build the software `npm` has been configured with scripts for `test` and `build` script to validate any work before publishing the action code.
+31
View File
@@ -0,0 +1,31 @@
Thanks for helping make GitHub safe for everyone.
## Security
GitHub takes the security of our software products and services seriously, including all of the open source code repositories managed through our GitHub organizations, such as [GitHub](https://github.com/GitHub).
Even though [open source repositories are outside of the scope of our bug bounty program](https://bounty.github.com/index.html#scope) and therefore not eligible for bounty rewards, we will ensure that your finding gets passed along to the appropriate maintainers for remediation.
## Reporting Security Issues
If you believe you have found a security vulnerability in any GitHub-owned repository, please report it to us through coordinated disclosure.
**Please do not report security vulnerabilities through public GitHub issues, discussions, or pull requests.**
Instead, please send an email to opensource-security[@]github.com.
Please include as much of the information listed below as you can to help us better understand and resolve the issue:
* The type of issue (e.g., buffer overflow, SQL injection, or cross-site scripting)
* Full paths of source file(s) related to the manifestation of the issue
* The location of the affected source code (tag/branch/commit or direct URL)
* Any special configuration required to reproduce the issue
* Step-by-step instructions to reproduce the issue
* Proof-of-concept or exploit code (if possible)
* Impact of the issue, including how an attacker might exploit the issue
This information will help us triage your report more quickly.
## Policy
See [GitHub's Safe Harbor Policy](https://docs.github.com/en/github/site-policy/github-bug-bounty-program-legal-safe-harbor#1-safe-harbor-terms)
+17
View File
@@ -0,0 +1,17 @@
name: Maven Dependency Tree Dependency Submission
description: A GitHub Action for Maven project to submit a complete dependency tree to populate the GitHub Dependency Graph
inputs:
directory:
description: The directory that contains the maven project
type: string
default: ${{ github.workspace }}
token:
description: The GitHub token to use to submit the depedency snapshot to the repository
type: string
default: ${{ github.token }}
runs:
using: node16
main: dist/index.js
+14014
View File
File diff suppressed because one or more lines are too long
+1
View File
File diff suppressed because one or more lines are too long
+1
View File
File diff suppressed because one or more lines are too long
+6
View File
@@ -0,0 +1,6 @@
module.exports = {
verbose: true,
transform: {
'^.+\\.(ts|tsx)?$': 'ts-jest'
},
}
+7227
View File
File diff suppressed because it is too large Load Diff
+36
View File
@@ -0,0 +1,36 @@
{
"name": "maven-dependency-tree-action",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "npm ci && tsc && npm exec -- @vercel/ncc build --source-map lib/index.js",
"test": "jest"
},
"repository": {
"type": "git",
"url": "git+https://github.com/advanced-security/maven-dependency-tree-action.git"
},
"keywords": [],
"author": "GitHub, Inc",
"license": "MIT",
"bugs": {
"url": "https://github.com/advanced-security/maven-dependency-tree-action/issues"
},
"homepage": "https://github.com/advanced-security/maven-dependency-tree-action#readme",
"dependencies": {
"@actions/core": "^1.9.1",
"@github/dependency-submission-toolkit": "^1.2.2",
"packageurl-js": "^0.0.7"
},
"devDependencies": {
"@types/chai": "^4.3.1",
"@types/jest": "^28.1.6",
"@vercel/ncc": "^0.34.0",
"chai": "^4.3.6",
"jest": "^28.1.3",
"ts-jest": "^28.0.7",
"ts-node": "^10.8.2",
"typescript": "^4.7.4"
}
}
+122
View File
@@ -0,0 +1,122 @@
import { expect } from 'chai';
import { parseDependencyJson, MavenDependencyGraph } from './depgraph';
import * as path from 'path';
describe('depgraph', () => {
it('should load a dependency JSON file', () => {
const depGraph = parseDependencyJson(getTestDataFile('maven-plugin'));
expect(depGraph.artifacts).to.have.length(96);
expect(depGraph.dependencies).to.have.length(95);
const artifact = depGraph.artifacts[0];
expect(artifact.groupId).to.equal('org.apache.maven.plugins');
expect(artifact.artifactId).to.equal('maven-dependency-plugin');
expect(artifact.version).to.equal('4.0.0-SNAPSHOT');
expect(artifact.id).to.equal('org.apache.maven.plugins:maven-dependency-plugin:maven-plugin');
const dependency = depGraph.dependencies[0];
expect(dependency.resolution).to.equal('INCLUDED');
expect(dependency.from).to.equal('org.apache.maven.plugins:maven-dependency-plugin:maven-plugin');
expect(dependency.to).to.equal('org.apache.maven:maven-artifact:jar');
});
describe('parseDependencies', () => {
describe('maven-plugin', () => {
let depGraph;
beforeAll(() => {
depGraph = parseDependencyJson(getTestDataFile('maven-plugin'));
})
it('should parse out the top level dependencies', () => {
const mavenDependencies = new MavenDependencyGraph(depGraph);
const topLevelDependencies = mavenDependencies.getDirectDependencies();
expect(mavenDependencies.getPackageCount()).to.equal(96);
const names = topLevelDependencies.map(pkg => pkg.packageID());
expect(names).to.have.members([
"pkg:maven/org.apache.maven/maven-artifact@3.1.1",
"pkg:maven/org.apache.maven/maven-plugin-api@3.1.1",
"pkg:maven/org.apache.maven/maven-model@3.1.1",
"pkg:maven/org.apache.maven/maven-core@3.1.1",
"pkg:maven/org.apache.maven/maven-repository-metadata@3.1.1",
"pkg:maven/org.apache.maven/maven-settings@3.1.1",
"pkg:maven/org.apache.maven/maven-aether-provider@3.1.1",
"pkg:maven/org.apache.maven.reporting/maven-reporting-impl@3.1.0",
"pkg:maven/commons-io/commons-io@2.11.0",
"pkg:maven/org.codehaus.plexus/plexus-archiver@4.2.2",
"pkg:maven/org.codehaus.plexus/plexus-utils@3.4.1",
"pkg:maven/org.codehaus.plexus/plexus-io@3.2.0",
"pkg:maven/org.apache.maven.shared/maven-dependency-analyzer@1.12.0",
"pkg:maven/org.apache.maven.shared/maven-dependency-tree@3.1.0",
"pkg:maven/org.apache.maven.shared/maven-common-artifact-filters@3.2.0",
"pkg:maven/org.apache.maven.shared/maven-artifact-transfer@0.13.1",
"pkg:maven/org.apache.maven.shared/maven-shared-utils@3.3.4",
"pkg:maven/org.apache.commons/commons-lang3@3.12.0",
"pkg:maven/org.apache.commons/commons-collections4@4.2",
"pkg:maven/org.apache.maven.plugin-tools/maven-plugin-annotations@3.6.4",
"pkg:maven/org.eclipse.aether/aether-api@0.9.0.M2",
"pkg:maven/org.eclipse.aether/aether-util@0.9.0.M2",
"pkg:maven/org.eclipse.aether/aether-connector-wagon@0.9.0.M2",
"pkg:maven/org.apache.maven.wagon/wagon-http-lightweight@3.4.0",
"pkg:maven/junit/junit@4.13.2",
"pkg:maven/org.apache.maven.plugin-testing/maven-plugin-testing-tools@3.1.0",
"pkg:maven/org.apache.maven.plugin-testing/maven-plugin-testing-harness@3.1.0",
"pkg:maven/org.mockito/mockito-core@4.3.1",
"pkg:maven/org.codehaus.plexus/plexus-interpolation@1.26",
"pkg:maven/org.apache.maven/maven-compat@3.1.1",
"pkg:maven/org.eclipse.jetty/jetty-server@9.4.45.v20220203",
"pkg:maven/org.eclipse.jetty/jetty-util@9.4.45.v20220203",
"pkg:maven/org.eclipse.jetty/jetty-security@9.4.45.v20220203",
"pkg:maven/org.slf4j/slf4j-simple@1.7.36",
"pkg:maven/commons-beanutils/commons-beanutils@1.9.4"
]);
});
it('should provide a manifest', () => {
const mavenDependencies = new MavenDependencyGraph(depGraph);
const manifest = mavenDependencies.createManifest();
expect(manifest.name).to.equal('maven-dependency-plugin');
expect(manifest.countDependencies()).to.equal(95);
});
});
describe('bookstore-v3', () => {
let depGraph;
beforeAll(() => {
depGraph = parseDependencyJson(getTestDataFile('bookstore-v3'));
})
it('should parse out the top level dependencies', () => {
const mavenDependencies = new MavenDependencyGraph(depGraph);
const topLevelDependencies = mavenDependencies.getDirectDependencies();
expect(mavenDependencies.getPackageCount()).to.equal(21);
const names = topLevelDependencies.map(pkg => pkg.packageID());
expect(names).to.have.members([
"pkg:maven/org.eclipse.jetty/jetty-server@10.0.0",
"pkg:maven/org.eclipse.jetty/jetty-servlet@10.0.0",
"pkg:maven/org.thymeleaf/thymeleaf@3.0.12.RELEASE",
"pkg:maven/org.json/json@20210307",
"pkg:maven/org.xerial/sqlite-jdbc@3.32.3.2",
"pkg:maven/org.apache.logging.log4j/log4j-slf4j18-impl@2.17.2",
"pkg:maven/junit/junit@4.13"
]);
});
});
});
});
function getTestDataFile(name: string) {
return path.join(__dirname, '..', 'test-data', 'dependency-trees', `${name}.json`);
}
+210
View File
@@ -0,0 +1,210 @@
import * as fs from 'fs';
import { PackageURL } from 'packageurl-js'
import { PackageCache, Package, Manifest } from '@github/dependency-submission-toolkit';
import { DependencyScope } from '@github/dependency-submission-toolkit/dist/manifest';
type Depgraph = {
graphName: string,
artifacts: DepgraphArtifact[],
dependencies: DepgraphDependency[],
}
type DepgraphArtifact = {
id: string,
numericId: number,
groupId: string,
artifactId: string,
version: string,
optional?: boolean,
scopes?: string[],
types?: string[],
}
type DepgraphDependency = {
from: string,
to: string,
numericFrom: number,
numericTo: number,
resolution: string,
}
export class MavenDependencyGraph {
private depGraph: Depgraph;
private packageUrlToArtifact: Map<string, DepgraphArtifact>;
private cache: PackageCache;
private directDependencies: Array<Package>;
// //@ ts-ignore
// private rootPackage: DepgraphArtifact;
constructor(graph: Depgraph) {
this.depGraph = graph;
this.cache = new PackageCache();
this.packageUrlToArtifact = new Map();
this.directDependencies = [];
this.parseDependencies();
}
getProjectName() {
return this.depGraph.graphName;
}
getAllPackageUrls() {
return Object.keys(this.packageUrlToArtifact);
}
getArtifactForPackageUrl(packageUrl: string) {
return this.packageUrlToArtifact[packageUrl];
}
getDirectDependencies() {
return this.directDependencies;
}
getPackageCount() {
return this.cache.countPackages();
}
createManifest(): Manifest {
const manifest = new Manifest(this.getProjectName());
const packageUrlToArtifact = this.packageUrlToArtifact;
this.directDependencies.forEach(depPackage => {
const artifact = this.packageUrlToArtifact[depPackage.packageURL.toString()];
let scope = getDependencyScopeForMavenScope(artifact.scopes);
manifest.addDirectDependency(depPackage, scope);
function addTransitiveDeps(dependencies) {
if (dependencies) {
dependencies.forEach(transitiveDep => {
const transitiveDepArtifact = packageUrlToArtifact[transitiveDep.packageURL.toString()];
const transitiveDepScope = getDependencyScopeForMavenScope(transitiveDepArtifact.scopes);
manifest.addIndirectDependency(transitiveDep, transitiveDepScope);
addTransitiveDeps(transitiveDep.dependencies);
});
}
}
addTransitiveDeps(depPackage.dependencies);
});
return manifest;
}
private parseDependencies() {
const graph = this.depGraph;
const cache = this.cache;
const rootPackageArtifactId = graph.graphName;
let rootPackageNumericId = 0;
const dependencyIdMap = dependencyMap(graph.dependencies);
const idToPackageCachePackage : Map<string, Package> = new Map<string, Package>();
// Create the packages for all known artifacts
graph.artifacts.forEach((artifact: DepgraphArtifact) => {
const artifactUrl: PackageURL = artifactToPackageURL(artifact);
const pkg = cache.package(artifactUrl);
idToPackageCachePackage[artifact.id] = pkg;
// Store a reference from the package URL to the original artifact as the artifact has extra metadata we need later for scopes and optionality
this.packageUrlToArtifact[artifactUrl.toString()] = artifact;
if (artifact.artifactId === rootPackageArtifactId) {
rootPackageNumericId = artifact.numericId - 1;
}
});
// Now that all packages are known, process the dependencies for each and link them
Object.keys(dependencyIdMap).forEach(fromId => {
const pkg: Package = idToPackageCachePackage[fromId];
if (!pkg) {
throw new Error(`Package '${fromId}' was not found in the cache.`);
}
const deps = dependencyIdMap[fromId];
if (deps) {
// Process each dependency id and link to the package in the cache
deps.forEach(dependencyId => {
const dependencyPkg = idToPackageCachePackage[dependencyId];
if (!dependencyPkg) {
throw new Error(`Failed to find a dependency package for '${dependencyId}'`);
}
pkg.dependsOn(dependencyPkg);
});
}
});
this.directDependencies = getDirectDependencies(rootPackageNumericId, graph.dependencies).map(id => {return idToPackageCachePackage[id]});
}
}
export function parseDependencyJson(file: string): Depgraph {
try {
const data: Buffer = fs.readFileSync(file);
try {
const depGraph: Depgraph = JSON.parse(data.toString('utf-8'));
return depGraph;
} catch(err: any) {
throw new Error(`Failed to parse JSON payload: ${err.message}`);
}
} catch(err: any) {
throw new Error(`Failed to load file ${file}: ${err}`);
}
}
export function artifactToPackageURL(artifact: DepgraphArtifact): PackageURL {
return new PackageURL(
'maven',
artifact.groupId,
artifact.artifactId,
artifact.version,
undefined,
undefined
);
}
function getDependencyScopeForMavenScope(mavenScopes: string[] | undefined | null): DependencyScope {
// Once the API scopes are improved and expanded we should be able to perform better mapping here from Maven to cater for
// provided, runtime, compile, test, system, etc... in the future.
if (mavenScopes) {
if (mavenScopes.includes('test')) {
return 'development';
}
}
// The default scope for now as we only have runtime and development currently
return 'runtime';
}
function dependencyMap(dependencies: DepgraphDependency[]): Map<string, string[] | undefined> {
const map = new Map<string, string[]>();
dependencies.forEach(dependency => {
const fromUrl = dependency.from;
let deps = map[fromUrl];
if (!deps) {
deps = [];
map[fromUrl] = deps;
}
deps.push(dependency.to);
});
return map;
}
function getDirectDependencies(rootPackageNumericId: number, dependencies: DepgraphDependency[]): string[] {
const topLevel = dependencies.filter(dependency => { return dependency.numericFrom === rootPackageNumericId; });
return topLevel.map(dep => { return dep.to; });
}
+29
View File
@@ -0,0 +1,29 @@
import * as core from '@actions/core';
import {Snapshot, submitSnapshot} from '@github/dependency-submission-toolkit';
import { generateSnapshot } from './snapshot-generator';
async function run() {
let snapshot: Snapshot | undefined;
try {
const directory = core.getInput('directory', { required: true });
snapshot = await generateSnapshot(directory);
} catch (err: any) {
core.error(err);
core.setFailed(`Failed to generate a dependency snapshot, check logs for more details, ${err}`);
}
if (snapshot) {
core.startGroup(`Dependency Snapshot`);
core.info(snapshot.prettyJSON())
core.endGroup();
core.info(`Submitting Snapshot...`)
await submitSnapshot(snapshot);
core.info(`completed.`)
}
}
run();
+50
View File
@@ -0,0 +1,50 @@
import * as fs from 'fs';
import * as core from '@actions/core';
//TODO remove this or make it work...
export type MavenScope = 'provided' | 'compile' | 'test'
export type MavenArtifactType = 'jar' | 'pom' | 'test' | 'sources' | 'test-sources' | 'war' | 'maven-plugin'
export type MavenArtifact = {
groupId: string
artifactId: string
version: string
dependencies?: MavenArtifact[]
scope: MavenScope
type: MavenArtifactType
}
export function parseDependencyTree(file: string): MavenArtifact | undefined {
const lines = loadFileContents(file);
if (!lines) {
return;
}
lines.forEach(line => {
if (line.startsWith('\+-') || line.startsWith('\\-') || line.startsWith('\|')) {
}
})
}
function loadFileContents(file: string): String[] | undefined {
const exists = fs.existsSync(file);
if (exists) {
const fileStats = fs.statSync(file);
if (fileStats.isFile()) {
const contents = fs.readFileSync(file, {encoding: 'utf-8'});
return contents.split(/\r?\n/);
} else {
core.setFailed(`Dependency file was not a file; '${file}'.`);
}
} else {
core.setFailed(`Dependency file was not found; '${file}'.`);
}
return undefined;
}
+33
View File
@@ -0,0 +1,33 @@
import * as path from 'path';
import {generateDependencyGraph, generateSnapshot} from './snapshot-generator';
describe('snapshot-generator', () => {
jest.setTimeout(20000);
describe('#generateDependencyGraph()', () => {
it('should generate a snapshot for a simple project', async () => {
const projectDir = getMavenProjectDirectory('simple');
const depGraph = await generateDependencyGraph(projectDir);
expect(depGraph.dependencies.length).toBe(20);
});
});
describe('#generateSnapshot()', () => {
const version = require('../package.json')['version'];
it('should generate a snapshot for a simple project', async () => {
const projectDir = getMavenProjectDirectory('simple');
const snapshot = await generateSnapshot(projectDir);
expect(snapshot.manifests['bookstore-v3']).toBeDefined();
expect(snapshot.detector.version).toBe(version);
});
});
});
function getMavenProjectDirectory(name: string): string {
return path.join(__dirname, '..', 'test-data', 'maven', name);
}
+79
View File
@@ -0,0 +1,79 @@
import * as exec from '@actions/exec';
import * as core from '@actions/core';
import * as path from 'path';
import {Snapshot} from '@github/dependency-submission-toolkit';
import { MavenDependencyGraph, parseDependencyJson } from './depgraph';
const version = require('../package.json')['version'];
export async function generateSnapshot(directory: string) {
const depgraph = await generateDependencyGraph(directory);
try {
const mavenDependencies = new MavenDependencyGraph(depgraph);
const manifest = mavenDependencies.createManifest();
const snapshot = new Snapshot(getDetector());
snapshot.addManifest(manifest);
return snapshot;
} catch (err: any) {
core.error(err);
throw new Error(`Could not generate a snapshot of the dependencies; ${err.message}`);
}
}
function getDetector() {
return {
name: 'maven-dependency-tree-detector',
url: 'https://github.com/octodemo/maven-dependency-tree-action',
version: version
};
}
export async function generateDependencyGraph(directory: string) {
try {
let executionOutput = '';
let errors = '';
const options = {
cwd: directory,
listeners: {
stdout: (data: Buffer) => {
executionOutput += data.toString();
},
stderr: (data: Buffer) => {
errors += data.toString();
}
}
};
const mavenArguments = [
'com.github.ferstl:depgraph-maven-plugin:4.0.1:graph',
'-DgraphFormat=json',
];
core.startGroup('depgraph-maven-plugin');
await exec.exec('mvn', mavenArguments, options);
core.info(executionOutput);
core.info(errors);
core.endGroup();
} catch(err: any) {
core.error(err);
throw new Error(`A problem was encountered generating dependency files, please check execution logs for details; ${err.message}`);
}
//TODO need to account for multi module projects
// Now we have the target/dependency-graph.json file to process
const file = path.join(directory, 'target', 'dependency-graph.json');
try {
return parseDependencyJson(file);
} catch (err: any) {
core.error(err);
throw new Error(`Could not parse maven dependency file, '${file}': ${err.message}`);
}
}
@@ -0,0 +1,314 @@
{
"graphName" : "bookstore-v3",
"artifacts" : [ {
"id" : "org.eclipse.jetty:jetty-server:jar",
"numericId" : 1,
"groupId" : "org.eclipse.jetty",
"artifactId" : "jetty-server",
"version" : "10.0.0",
"optional" : false,
"scopes" : [ "compile" ],
"types" : [ "jar" ]
}, {
"id" : "org.eclipse.jetty.toolchain:jetty-servlet-api:jar",
"numericId" : 2,
"groupId" : "org.eclipse.jetty.toolchain",
"artifactId" : "jetty-servlet-api",
"version" : "4.0.5",
"optional" : false,
"scopes" : [ "compile" ],
"types" : [ "jar" ]
}, {
"id" : "org.eclipse.jetty:jetty-http:jar",
"numericId" : 3,
"groupId" : "org.eclipse.jetty",
"artifactId" : "jetty-http",
"version" : "10.0.0",
"optional" : false,
"scopes" : [ "compile" ],
"types" : [ "jar" ]
}, {
"id" : "org.eclipse.jetty:jetty-util:jar",
"numericId" : 4,
"groupId" : "org.eclipse.jetty",
"artifactId" : "jetty-util",
"version" : "10.0.0",
"optional" : false,
"scopes" : [ "compile" ],
"types" : [ "jar" ]
}, {
"id" : "org.eclipse.jetty:jetty-io:jar",
"numericId" : 5,
"groupId" : "org.eclipse.jetty",
"artifactId" : "jetty-io",
"version" : "10.0.0",
"optional" : false,
"scopes" : [ "compile" ],
"types" : [ "jar" ]
}, {
"id" : "org.slf4j:slf4j-api:jar",
"numericId" : 6,
"groupId" : "org.slf4j",
"artifactId" : "slf4j-api",
"version" : "2.0.0-alpha1",
"optional" : false,
"scopes" : [ "compile" ],
"types" : [ "jar" ]
}, {
"id" : "com.github.octodemo:bookstore-v3:jar",
"numericId" : 7,
"groupId" : "com.github.octodemo",
"artifactId" : "bookstore-v3",
"version" : "1.0.0-SNAPSHOT",
"optional" : false,
"scopes" : [ "compile" ],
"types" : [ "jar" ]
}, {
"id" : "org.eclipse.jetty:jetty-servlet:jar",
"numericId" : 8,
"groupId" : "org.eclipse.jetty",
"artifactId" : "jetty-servlet",
"version" : "10.0.0",
"optional" : false,
"scopes" : [ "compile" ],
"types" : [ "jar" ]
}, {
"id" : "org.eclipse.jetty:jetty-security:jar",
"numericId" : 9,
"groupId" : "org.eclipse.jetty",
"artifactId" : "jetty-security",
"version" : "10.0.0",
"optional" : false,
"scopes" : [ "compile" ],
"types" : [ "jar" ]
}, {
"id" : "ognl:ognl:jar",
"numericId" : 10,
"groupId" : "ognl",
"artifactId" : "ognl",
"version" : "3.1.26",
"optional" : false,
"scopes" : [ "compile" ],
"types" : [ "jar" ]
}, {
"id" : "org.javassist:javassist:jar",
"numericId" : 11,
"groupId" : "org.javassist",
"artifactId" : "javassist",
"version" : "3.20.0-GA",
"optional" : false,
"scopes" : [ "compile" ],
"types" : [ "jar" ]
}, {
"id" : "org.thymeleaf:thymeleaf:jar",
"numericId" : 12,
"groupId" : "org.thymeleaf",
"artifactId" : "thymeleaf",
"version" : "3.0.12.RELEASE",
"optional" : false,
"scopes" : [ "compile" ],
"types" : [ "jar" ]
}, {
"id" : "org.attoparser:attoparser:jar",
"numericId" : 13,
"groupId" : "org.attoparser",
"artifactId" : "attoparser",
"version" : "2.0.5.RELEASE",
"optional" : false,
"scopes" : [ "compile" ],
"types" : [ "jar" ]
}, {
"id" : "org.unbescape:unbescape:jar",
"numericId" : 14,
"groupId" : "org.unbescape",
"artifactId" : "unbescape",
"version" : "1.1.6.RELEASE",
"optional" : false,
"scopes" : [ "compile" ],
"types" : [ "jar" ]
}, {
"id" : "org.json:json:jar",
"numericId" : 15,
"groupId" : "org.json",
"artifactId" : "json",
"version" : "20210307",
"optional" : false,
"scopes" : [ "compile" ],
"types" : [ "jar" ]
}, {
"id" : "org.xerial:sqlite-jdbc:jar",
"numericId" : 16,
"groupId" : "org.xerial",
"artifactId" : "sqlite-jdbc",
"version" : "3.32.3.2",
"optional" : false,
"scopes" : [ "compile" ],
"types" : [ "jar" ]
}, {
"id" : "org.apache.logging.log4j:log4j-slf4j18-impl:jar",
"numericId" : 17,
"groupId" : "org.apache.logging.log4j",
"artifactId" : "log4j-slf4j18-impl",
"version" : "2.17.2",
"optional" : false,
"scopes" : [ "compile" ],
"types" : [ "jar" ]
}, {
"id" : "org.apache.logging.log4j:log4j-api:jar",
"numericId" : 18,
"groupId" : "org.apache.logging.log4j",
"artifactId" : "log4j-api",
"version" : "2.17.2",
"optional" : false,
"scopes" : [ "compile" ],
"types" : [ "jar" ]
}, {
"id" : "org.apache.logging.log4j:log4j-core:jar",
"numericId" : 19,
"groupId" : "org.apache.logging.log4j",
"artifactId" : "log4j-core",
"version" : "2.17.2",
"optional" : false,
"scopes" : [ "runtime" ],
"types" : [ "jar" ]
}, {
"id" : "junit:junit:jar",
"numericId" : 20,
"groupId" : "junit",
"artifactId" : "junit",
"version" : "4.13",
"optional" : false,
"scopes" : [ "test" ],
"types" : [ "jar" ]
}, {
"id" : "org.hamcrest:hamcrest-core:jar",
"numericId" : 21,
"groupId" : "org.hamcrest",
"artifactId" : "hamcrest-core",
"version" : "1.3",
"optional" : false,
"scopes" : [ "test" ],
"types" : [ "jar" ]
} ],
"dependencies" : [ {
"from" : "org.eclipse.jetty:jetty-server:jar",
"to" : "org.eclipse.jetty.toolchain:jetty-servlet-api:jar",
"numericFrom" : 0,
"numericTo" : 1,
"resolution" : "INCLUDED"
}, {
"from" : "org.eclipse.jetty:jetty-http:jar",
"to" : "org.eclipse.jetty:jetty-util:jar",
"numericFrom" : 2,
"numericTo" : 3,
"resolution" : "INCLUDED"
}, {
"from" : "org.eclipse.jetty:jetty-server:jar",
"to" : "org.eclipse.jetty:jetty-http:jar",
"numericFrom" : 0,
"numericTo" : 2,
"resolution" : "INCLUDED"
}, {
"from" : "org.eclipse.jetty:jetty-server:jar",
"to" : "org.eclipse.jetty:jetty-io:jar",
"numericFrom" : 0,
"numericTo" : 4,
"resolution" : "INCLUDED"
}, {
"from" : "org.eclipse.jetty:jetty-server:jar",
"to" : "org.slf4j:slf4j-api:jar",
"numericFrom" : 0,
"numericTo" : 5,
"resolution" : "INCLUDED"
}, {
"from" : "com.github.octodemo:bookstore-v3:jar",
"to" : "org.eclipse.jetty:jetty-server:jar",
"numericFrom" : 6,
"numericTo" : 0,
"resolution" : "INCLUDED"
}, {
"from" : "org.eclipse.jetty:jetty-servlet:jar",
"to" : "org.eclipse.jetty:jetty-security:jar",
"numericFrom" : 7,
"numericTo" : 8,
"resolution" : "INCLUDED"
}, {
"from" : "com.github.octodemo:bookstore-v3:jar",
"to" : "org.eclipse.jetty:jetty-servlet:jar",
"numericFrom" : 6,
"numericTo" : 7,
"resolution" : "INCLUDED"
}, {
"from" : "ognl:ognl:jar",
"to" : "org.javassist:javassist:jar",
"numericFrom" : 9,
"numericTo" : 10,
"resolution" : "INCLUDED"
}, {
"from" : "org.thymeleaf:thymeleaf:jar",
"to" : "ognl:ognl:jar",
"numericFrom" : 11,
"numericTo" : 9,
"resolution" : "INCLUDED"
}, {
"from" : "org.thymeleaf:thymeleaf:jar",
"to" : "org.attoparser:attoparser:jar",
"numericFrom" : 11,
"numericTo" : 12,
"resolution" : "INCLUDED"
}, {
"from" : "org.thymeleaf:thymeleaf:jar",
"to" : "org.unbescape:unbescape:jar",
"numericFrom" : 11,
"numericTo" : 13,
"resolution" : "INCLUDED"
}, {
"from" : "com.github.octodemo:bookstore-v3:jar",
"to" : "org.thymeleaf:thymeleaf:jar",
"numericFrom" : 6,
"numericTo" : 11,
"resolution" : "INCLUDED"
}, {
"from" : "com.github.octodemo:bookstore-v3:jar",
"to" : "org.json:json:jar",
"numericFrom" : 6,
"numericTo" : 14,
"resolution" : "INCLUDED"
}, {
"from" : "com.github.octodemo:bookstore-v3:jar",
"to" : "org.xerial:sqlite-jdbc:jar",
"numericFrom" : 6,
"numericTo" : 15,
"resolution" : "INCLUDED"
}, {
"from" : "org.apache.logging.log4j:log4j-slf4j18-impl:jar",
"to" : "org.apache.logging.log4j:log4j-api:jar",
"numericFrom" : 16,
"numericTo" : 17,
"resolution" : "INCLUDED"
}, {
"from" : "org.apache.logging.log4j:log4j-slf4j18-impl:jar",
"to" : "org.apache.logging.log4j:log4j-core:jar",
"numericFrom" : 16,
"numericTo" : 18,
"resolution" : "INCLUDED"
}, {
"from" : "com.github.octodemo:bookstore-v3:jar",
"to" : "org.apache.logging.log4j:log4j-slf4j18-impl:jar",
"numericFrom" : 6,
"numericTo" : 16,
"resolution" : "INCLUDED"
}, {
"from" : "junit:junit:jar",
"to" : "org.hamcrest:hamcrest-core:jar",
"numericFrom" : 19,
"numericTo" : 20,
"resolution" : "INCLUDED"
}, {
"from" : "com.github.octodemo:bookstore-v3:jar",
"to" : "junit:junit:jar",
"numericFrom" : 6,
"numericTo" : 19,
"resolution" : "INCLUDED"
} ]
}
File diff suppressed because it is too large Load Diff
+139
View File
@@ -0,0 +1,139 @@
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.octodemo</groupId>
<artifactId>bookstore-v3</artifactId>
<version>${revision}${changelist}${sha1}</version>
<packaging>jar</packaging>
<description>A Java example project to demonstrate a Java development stack with Maven, GitHub Actions, GitHub Package Registry and Azure.</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>11</java.version>
<!--
Dependency Versions
-->
<jetty.version>10.0.0</jetty.version>
<log4j.version>2.17.2</log4j.version>
<!--
Properties used to create a CD style version number for the Maven build
-->
<revision>1.0.0</revision>
<changelist></changelist>
<sha1>-SNAPSHOT</sha1>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-bom</artifactId>
<version>${jetty.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf</artifactId>
<version>3.0.12.RELEASE</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20210307</version>
</dependency>
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.32.3.2</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j18-impl</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.1.1</version>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>8.29</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<!-- To enable debug compilation use the maven.compiler.debug user property -->
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<plugin>
<groupId>com.github.ekryd.echo-maven-plugin</groupId>
<artifactId>echo-maven-plugin</artifactId>
<version>1.3.2</version>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.6</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
+19
View File
@@ -0,0 +1,19 @@
{
"compilerOptions": {
"target": "es6",
"module": "CommonJS",
"outDir": "./lib",
"rootDir": "./src",
"strict": true,
"sourceMap": true,
"noImplicitAny": false,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"moduleResolution": "node"
},
"exclude": [
"node_modules",
"**/*.test.ts"
]
}