mirror of
https://github.com/gradle/gradle-build-action.git
synced 2024-11-22 08:11:07 -05:00
Merge pull request #911 - Improve dependency review support
This commit is contained in:
commit
842c587ad8
7 changed files with 232 additions and 74 deletions
103
README.md
103
README.md
|
@ -546,8 +546,6 @@ You enable GitHub Dependency Graph support by setting the `dependency-graph` act
|
||||||
| `generate-and-submit` | As per `generate`, but any generated dependency graph snapshots will be submitted at the end of the job. |
|
| `generate-and-submit` | As per `generate`, but any generated dependency graph snapshots will be submitted at the end of the job. |
|
||||||
| `download-and-submit` | Download any previously saved dependency graph snapshots, submitting them via the Dependency Submission API. This can be useful to collect all snapshots in a matrix of builds and submit them in one step. |
|
| `download-and-submit` | Download any previously saved dependency graph snapshots, submitting them via the Dependency Submission API. This can be useful to collect all snapshots in a matrix of builds and submit them in one step. |
|
||||||
|
|
||||||
Dependency Graph _submission_ (but not generation) requires the `contents: write` permission, which may need to be explicitly enabled in the workflow file.
|
|
||||||
|
|
||||||
Example of a simple workflow that generates and submits a dependency graph:
|
Example of a simple workflow that generates and submits a dependency graph:
|
||||||
```yaml
|
```yaml
|
||||||
name: Submit dependency graph
|
name: Submit dependency graph
|
||||||
|
@ -566,14 +564,62 @@ jobs:
|
||||||
uses: gradle/gradle-build-action@v2
|
uses: gradle/gradle-build-action@v2
|
||||||
with:
|
with:
|
||||||
dependency-graph: generate-and-submit
|
dependency-graph: generate-and-submit
|
||||||
- name: Run a build, generating the dependency graph snapshot which will be submitted
|
- name: Run a build and generate the dependency graph which will be submitted post-job
|
||||||
run: ./gradlew build
|
run: ./gradlew build
|
||||||
```
|
```
|
||||||
|
|
||||||
The `contents: write` permission is not required to generate the dependency graph, but is required in order to submit the graph via the GitHub API.
|
The `contents: write` permission is not required to generate the dependency graph, but is required in order to submit the graph via the GitHub API. This permission will need to be explicitly enabled in the workflow file for dependency graph submission to succeed.
|
||||||
|
|
||||||
The above configuration will work for workflows that run as a result of commits to a repository branch, but not when a workflow is triggered by a PR from a repository fork.
|
> [!IMPORTANT]
|
||||||
For a configuration that supports this setup, see [Dependency Graphs for pull request workflows](#dependency-graphs-for-pull-request-workflows).
|
> The above configuration will work for workflows that run as a result of commits to a repository branch,
|
||||||
|
> but not when a workflow is triggered by a PR from a repository fork.
|
||||||
|
> This is because the `contents: write` permission is not available when executing a workflow
|
||||||
|
> for a PR submitted from a forked repository.
|
||||||
|
> For a configuration that supports this setup, see [Dependency Graphs for pull request workflows](#dependency-graphs-for-pull-request-workflows).
|
||||||
|
|
||||||
|
### Integrating the `dependency-review-action`
|
||||||
|
|
||||||
|
The GitHub [dependency-review-action](https://github.com/actions/dependency-review-action) helps you
|
||||||
|
understand dependency changes (and the security impact of these changes) for a pull request.
|
||||||
|
For the `dependency-review-action` to succeed, it must run _after_ the dependency graph has been submitted for a PR.
|
||||||
|
|
||||||
|
When using `generate-and-submit`, dependency graph files are submitted at the end of the job, after all steps have been
|
||||||
|
executed. For this reason, the `dependency-review-action` must be executed in a dependent job,
|
||||||
|
and not as a subsequent step in the job that generates the dependency graph.
|
||||||
|
|
||||||
|
Example of a pull request workflow that executes a build for a pull request and runs the `dependency-review-action`:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
name: PR check
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
# Note that this permission will not be available if the PR is from a forked repository
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- name: Setup Gradle to generate and submit dependency graphs
|
||||||
|
uses: gradle/gradle-build-action@v2
|
||||||
|
with:
|
||||||
|
dependency-graph: generate-and-submit
|
||||||
|
- name: Run a build and generate the dependency graph which will be submitted post-job
|
||||||
|
run: ./gradlew build
|
||||||
|
|
||||||
|
dependency-review:
|
||||||
|
needs: build
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
- name: Perform dependency review
|
||||||
|
uses: actions/dependency-review-action@v3
|
||||||
|
```
|
||||||
|
|
||||||
|
See [Dependency Graphs for pull request workflows](#dependency-graphs-for-pull-request-workflows) for a more complex
|
||||||
|
(and less functional) example that will work for pull requests submitted from forked repositories.
|
||||||
|
|
||||||
## Limiting the scope of the dependency graph
|
## Limiting the scope of the dependency graph
|
||||||
|
|
||||||
|
@ -682,6 +728,9 @@ Note: when `download-and-submit` is used in a workflow triggered via [workflow_r
|
||||||
```yaml
|
```yaml
|
||||||
name: run-build-and-generate-dependency-snapshot
|
name: run-build-and-generate-dependency-snapshot
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
@ -693,6 +742,13 @@ jobs:
|
||||||
dependency-graph: generate # Only generate in this job
|
dependency-graph: generate # Only generate in this job
|
||||||
- name: Run a build, generating the dependency graph snapshot which will be submitted
|
- name: Run a build, generating the dependency graph snapshot which will be submitted
|
||||||
run: ./gradlew build
|
run: ./gradlew build
|
||||||
|
|
||||||
|
dependency-review:
|
||||||
|
needs: build
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
- name: Perform dependency review
|
||||||
|
uses: actions/dependency-review-action@v3
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
***Dependent workflow file***
|
***Dependent workflow file***
|
||||||
|
@ -705,7 +761,7 @@ on:
|
||||||
types: [completed]
|
types: [completed]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
submit-snapshots:
|
submit-dependency-graph:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Retrieve dependency graph artifact and submit
|
- name: Retrieve dependency graph artifact and submit
|
||||||
|
@ -714,6 +770,39 @@ jobs:
|
||||||
dependency-graph: download-and-submit
|
dependency-graph: download-and-submit
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Integrating `dependency-review-action` for pull request workflows
|
||||||
|
|
||||||
|
The GitHub [dependency-review-action](https://github.com/actions/dependency-review-action) helps you
|
||||||
|
understand dependency changes (and the security impact of these changes) for a pull request.
|
||||||
|
|
||||||
|
To integrate the `dependency-review-action` into the pull request workflows above, a separate workflow should be added.
|
||||||
|
This workflow will be triggered directly on `pull_request`, but will need to wait until the dependency graph results are
|
||||||
|
submitted before the dependency review can complete. How long to wait is controlled by the `retry-on-snapshot-warnings` input parameters.
|
||||||
|
|
||||||
|
Here's an example of a separate "Dependency Review" workflow that will wait for 10 minutes for the PR check workflow to complete.
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
name: dependency-review
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
pull-requests: write
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
dependency-review:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: 'Dependency Review'
|
||||||
|
uses: actions/dependency-review-action@v3
|
||||||
|
with:
|
||||||
|
retry-on-snapshot-warnings: true
|
||||||
|
retry-on-snapshot-warnings-timeout: 600
|
||||||
|
```
|
||||||
|
|
||||||
|
The `retry-on-snapshot-warnings-timeout` (in seconds) needs to be long enough to allow the entire `run-build-and-generate-dependency-snapshot` and `submit-dependency-snapshot` workflows (above) to complete.
|
||||||
|
|
||||||
## Gradle version compatibility
|
## Gradle version compatibility
|
||||||
|
|
||||||
The GitHub Dependency Graph plugin should be compatible with all versions of Gradle >= 5.0, and has been tested against
|
The GitHub Dependency Graph plugin should be compatible with all versions of Gradle >= 5.0, and has been tested against
|
||||||
|
|
38
dist/main/index.js
vendored
38
dist/main/index.js
vendored
|
@ -70674,13 +70674,19 @@ const artifact = __importStar(__nccwpck_require__(2605));
|
||||||
const github = __importStar(__nccwpck_require__(5438));
|
const github = __importStar(__nccwpck_require__(5438));
|
||||||
const glob = __importStar(__nccwpck_require__(8090));
|
const glob = __importStar(__nccwpck_require__(8090));
|
||||||
const toolCache = __importStar(__nccwpck_require__(7784));
|
const toolCache = __importStar(__nccwpck_require__(7784));
|
||||||
|
const request_error_1 = __nccwpck_require__(537);
|
||||||
const path = __importStar(__nccwpck_require__(1017));
|
const path = __importStar(__nccwpck_require__(1017));
|
||||||
const fs_1 = __importDefault(__nccwpck_require__(7147));
|
const fs_1 = __importDefault(__nccwpck_require__(7147));
|
||||||
const layout = __importStar(__nccwpck_require__(8182));
|
const layout = __importStar(__nccwpck_require__(8182));
|
||||||
const input_params_1 = __nccwpck_require__(3885);
|
const input_params_1 = __nccwpck_require__(3885);
|
||||||
const DEPENDENCY_GRAPH_ARTIFACT = 'dependency-graph';
|
const DEPENDENCY_GRAPH_ARTIFACT = 'dependency-graph';
|
||||||
function setup(option) {
|
function setup(option) {
|
||||||
if (option === input_params_1.DependencyGraphOption.Disabled || option === input_params_1.DependencyGraphOption.DownloadAndSubmit) {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
if (option === input_params_1.DependencyGraphOption.Disabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (option === input_params_1.DependencyGraphOption.DownloadAndSubmit) {
|
||||||
|
yield downloadAndSubmitDependencyGraphs();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
core.info('Enabling dependency graph generation');
|
core.info('Enabling dependency graph generation');
|
||||||
|
@ -70691,12 +70697,14 @@ function setup(option) {
|
||||||
core.exportVariable('GITHUB_DEPENDENCY_GRAPH_SHA', getShaFromContext());
|
core.exportVariable('GITHUB_DEPENDENCY_GRAPH_SHA', getShaFromContext());
|
||||||
core.exportVariable('GITHUB_DEPENDENCY_GRAPH_WORKSPACE', layout.workspaceDirectory());
|
core.exportVariable('GITHUB_DEPENDENCY_GRAPH_WORKSPACE', layout.workspaceDirectory());
|
||||||
core.exportVariable('DEPENDENCY_GRAPH_REPORT_DIR', path.resolve(layout.workspaceDirectory(), 'dependency-graph-reports'));
|
core.exportVariable('DEPENDENCY_GRAPH_REPORT_DIR', path.resolve(layout.workspaceDirectory(), 'dependency-graph-reports'));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
exports.setup = setup;
|
exports.setup = setup;
|
||||||
function complete(option) {
|
function complete(option) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
switch (option) {
|
switch (option) {
|
||||||
case input_params_1.DependencyGraphOption.Disabled:
|
case input_params_1.DependencyGraphOption.Disabled:
|
||||||
|
case input_params_1.DependencyGraphOption.DownloadAndSubmit:
|
||||||
return;
|
return;
|
||||||
case input_params_1.DependencyGraphOption.Generate:
|
case input_params_1.DependencyGraphOption.Generate:
|
||||||
yield uploadDependencyGraphs();
|
yield uploadDependencyGraphs();
|
||||||
|
@ -70704,8 +70712,6 @@ function complete(option) {
|
||||||
case input_params_1.DependencyGraphOption.GenerateAndSubmit:
|
case input_params_1.DependencyGraphOption.GenerateAndSubmit:
|
||||||
yield submitDependencyGraphs(yield uploadDependencyGraphs());
|
yield submitDependencyGraphs(yield uploadDependencyGraphs());
|
||||||
return;
|
return;
|
||||||
case input_params_1.DependencyGraphOption.DownloadAndSubmit:
|
|
||||||
yield downloadAndSubmitDependencyGraphs();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -70729,8 +70735,27 @@ function downloadAndSubmitDependencyGraphs() {
|
||||||
}
|
}
|
||||||
function submitDependencyGraphs(dependencyGraphFiles) {
|
function submitDependencyGraphs(dependencyGraphFiles) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const octokit = getOctokit();
|
|
||||||
for (const jsonFile of dependencyGraphFiles) {
|
for (const jsonFile of dependencyGraphFiles) {
|
||||||
|
try {
|
||||||
|
yield submitDependencyGraphFile(jsonFile);
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
if (error instanceof request_error_1.RequestError) {
|
||||||
|
const relativeJsonFile = getRelativePathFromWorkspace(jsonFile);
|
||||||
|
core.warning(`Failed to submit dependency graph ${relativeJsonFile}.\n` +
|
||||||
|
"Please ensure that the 'contents: write' permission is available for the workflow job.\n" +
|
||||||
|
"Note that this permission is never available for a 'pull_request' trigger from a repository fork.");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function submitDependencyGraphFile(jsonFile) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
const octokit = getOctokit();
|
||||||
const jsonContent = fs_1.default.readFileSync(jsonFile, 'utf8');
|
const jsonContent = fs_1.default.readFileSync(jsonFile, 'utf8');
|
||||||
const jsonObject = JSON.parse(jsonContent);
|
const jsonObject = JSON.parse(jsonContent);
|
||||||
jsonObject.owner = github.context.repo.owner;
|
jsonObject.owner = github.context.repo.owner;
|
||||||
|
@ -70738,7 +70763,6 @@ function submitDependencyGraphs(dependencyGraphFiles) {
|
||||||
const response = yield octokit.request('POST /repos/{owner}/{repo}/dependency-graph/snapshots', jsonObject);
|
const response = yield octokit.request('POST /repos/{owner}/{repo}/dependency-graph/snapshots', jsonObject);
|
||||||
const relativeJsonFile = getRelativePathFromWorkspace(jsonFile);
|
const relativeJsonFile = getRelativePathFromWorkspace(jsonFile);
|
||||||
core.notice(`Submitted ${relativeJsonFile}: ${response.data.message}`);
|
core.notice(`Submitted ${relativeJsonFile}: ${response.data.message}`);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function retrieveDependencyGraphs(workspaceDirectory) {
|
function retrieveDependencyGraphs(workspaceDirectory) {
|
||||||
|
@ -71657,7 +71681,7 @@ function setup() {
|
||||||
const cacheListener = new cache_reporting_1.CacheListener();
|
const cacheListener = new cache_reporting_1.CacheListener();
|
||||||
yield caches.restore(gradleUserHome, cacheListener);
|
yield caches.restore(gradleUserHome, cacheListener);
|
||||||
core.saveState(CACHE_LISTENER, cacheListener.stringify());
|
core.saveState(CACHE_LISTENER, cacheListener.stringify());
|
||||||
dependencyGraph.setup(params.getDependencyGraphOption());
|
yield dependencyGraph.setup(params.getDependencyGraphOption());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.setup = setup;
|
exports.setup = setup;
|
||||||
|
@ -71679,7 +71703,7 @@ function complete() {
|
||||||
else {
|
else {
|
||||||
(0, job_summary_1.logJobSummary)(buildResults, cacheListener);
|
(0, job_summary_1.logJobSummary)(buildResults, cacheListener);
|
||||||
}
|
}
|
||||||
dependencyGraph.complete(params.getDependencyGraphOption());
|
yield dependencyGraph.complete(params.getDependencyGraphOption());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.complete = complete;
|
exports.complete = complete;
|
||||||
|
|
2
dist/main/index.js.map
vendored
2
dist/main/index.js.map
vendored
File diff suppressed because one or more lines are too long
38
dist/post/index.js
vendored
38
dist/post/index.js
vendored
|
@ -70674,13 +70674,19 @@ const artifact = __importStar(__nccwpck_require__(2605));
|
||||||
const github = __importStar(__nccwpck_require__(5438));
|
const github = __importStar(__nccwpck_require__(5438));
|
||||||
const glob = __importStar(__nccwpck_require__(8090));
|
const glob = __importStar(__nccwpck_require__(8090));
|
||||||
const toolCache = __importStar(__nccwpck_require__(7784));
|
const toolCache = __importStar(__nccwpck_require__(7784));
|
||||||
|
const request_error_1 = __nccwpck_require__(537);
|
||||||
const path = __importStar(__nccwpck_require__(1017));
|
const path = __importStar(__nccwpck_require__(1017));
|
||||||
const fs_1 = __importDefault(__nccwpck_require__(7147));
|
const fs_1 = __importDefault(__nccwpck_require__(7147));
|
||||||
const layout = __importStar(__nccwpck_require__(8182));
|
const layout = __importStar(__nccwpck_require__(8182));
|
||||||
const input_params_1 = __nccwpck_require__(3885);
|
const input_params_1 = __nccwpck_require__(3885);
|
||||||
const DEPENDENCY_GRAPH_ARTIFACT = 'dependency-graph';
|
const DEPENDENCY_GRAPH_ARTIFACT = 'dependency-graph';
|
||||||
function setup(option) {
|
function setup(option) {
|
||||||
if (option === input_params_1.DependencyGraphOption.Disabled || option === input_params_1.DependencyGraphOption.DownloadAndSubmit) {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
if (option === input_params_1.DependencyGraphOption.Disabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (option === input_params_1.DependencyGraphOption.DownloadAndSubmit) {
|
||||||
|
yield downloadAndSubmitDependencyGraphs();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
core.info('Enabling dependency graph generation');
|
core.info('Enabling dependency graph generation');
|
||||||
|
@ -70691,12 +70697,14 @@ function setup(option) {
|
||||||
core.exportVariable('GITHUB_DEPENDENCY_GRAPH_SHA', getShaFromContext());
|
core.exportVariable('GITHUB_DEPENDENCY_GRAPH_SHA', getShaFromContext());
|
||||||
core.exportVariable('GITHUB_DEPENDENCY_GRAPH_WORKSPACE', layout.workspaceDirectory());
|
core.exportVariable('GITHUB_DEPENDENCY_GRAPH_WORKSPACE', layout.workspaceDirectory());
|
||||||
core.exportVariable('DEPENDENCY_GRAPH_REPORT_DIR', path.resolve(layout.workspaceDirectory(), 'dependency-graph-reports'));
|
core.exportVariable('DEPENDENCY_GRAPH_REPORT_DIR', path.resolve(layout.workspaceDirectory(), 'dependency-graph-reports'));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
exports.setup = setup;
|
exports.setup = setup;
|
||||||
function complete(option) {
|
function complete(option) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
switch (option) {
|
switch (option) {
|
||||||
case input_params_1.DependencyGraphOption.Disabled:
|
case input_params_1.DependencyGraphOption.Disabled:
|
||||||
|
case input_params_1.DependencyGraphOption.DownloadAndSubmit:
|
||||||
return;
|
return;
|
||||||
case input_params_1.DependencyGraphOption.Generate:
|
case input_params_1.DependencyGraphOption.Generate:
|
||||||
yield uploadDependencyGraphs();
|
yield uploadDependencyGraphs();
|
||||||
|
@ -70704,8 +70712,6 @@ function complete(option) {
|
||||||
case input_params_1.DependencyGraphOption.GenerateAndSubmit:
|
case input_params_1.DependencyGraphOption.GenerateAndSubmit:
|
||||||
yield submitDependencyGraphs(yield uploadDependencyGraphs());
|
yield submitDependencyGraphs(yield uploadDependencyGraphs());
|
||||||
return;
|
return;
|
||||||
case input_params_1.DependencyGraphOption.DownloadAndSubmit:
|
|
||||||
yield downloadAndSubmitDependencyGraphs();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -70729,8 +70735,27 @@ function downloadAndSubmitDependencyGraphs() {
|
||||||
}
|
}
|
||||||
function submitDependencyGraphs(dependencyGraphFiles) {
|
function submitDependencyGraphs(dependencyGraphFiles) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const octokit = getOctokit();
|
|
||||||
for (const jsonFile of dependencyGraphFiles) {
|
for (const jsonFile of dependencyGraphFiles) {
|
||||||
|
try {
|
||||||
|
yield submitDependencyGraphFile(jsonFile);
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
if (error instanceof request_error_1.RequestError) {
|
||||||
|
const relativeJsonFile = getRelativePathFromWorkspace(jsonFile);
|
||||||
|
core.warning(`Failed to submit dependency graph ${relativeJsonFile}.\n` +
|
||||||
|
"Please ensure that the 'contents: write' permission is available for the workflow job.\n" +
|
||||||
|
"Note that this permission is never available for a 'pull_request' trigger from a repository fork.");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function submitDependencyGraphFile(jsonFile) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
const octokit = getOctokit();
|
||||||
const jsonContent = fs_1.default.readFileSync(jsonFile, 'utf8');
|
const jsonContent = fs_1.default.readFileSync(jsonFile, 'utf8');
|
||||||
const jsonObject = JSON.parse(jsonContent);
|
const jsonObject = JSON.parse(jsonContent);
|
||||||
jsonObject.owner = github.context.repo.owner;
|
jsonObject.owner = github.context.repo.owner;
|
||||||
|
@ -70738,7 +70763,6 @@ function submitDependencyGraphs(dependencyGraphFiles) {
|
||||||
const response = yield octokit.request('POST /repos/{owner}/{repo}/dependency-graph/snapshots', jsonObject);
|
const response = yield octokit.request('POST /repos/{owner}/{repo}/dependency-graph/snapshots', jsonObject);
|
||||||
const relativeJsonFile = getRelativePathFromWorkspace(jsonFile);
|
const relativeJsonFile = getRelativePathFromWorkspace(jsonFile);
|
||||||
core.notice(`Submitted ${relativeJsonFile}: ${response.data.message}`);
|
core.notice(`Submitted ${relativeJsonFile}: ${response.data.message}`);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function retrieveDependencyGraphs(workspaceDirectory) {
|
function retrieveDependencyGraphs(workspaceDirectory) {
|
||||||
|
@ -71289,7 +71313,7 @@ function setup() {
|
||||||
const cacheListener = new cache_reporting_1.CacheListener();
|
const cacheListener = new cache_reporting_1.CacheListener();
|
||||||
yield caches.restore(gradleUserHome, cacheListener);
|
yield caches.restore(gradleUserHome, cacheListener);
|
||||||
core.saveState(CACHE_LISTENER, cacheListener.stringify());
|
core.saveState(CACHE_LISTENER, cacheListener.stringify());
|
||||||
dependencyGraph.setup(params.getDependencyGraphOption());
|
yield dependencyGraph.setup(params.getDependencyGraphOption());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.setup = setup;
|
exports.setup = setup;
|
||||||
|
@ -71311,7 +71335,7 @@ function complete() {
|
||||||
else {
|
else {
|
||||||
(0, job_summary_1.logJobSummary)(buildResults, cacheListener);
|
(0, job_summary_1.logJobSummary)(buildResults, cacheListener);
|
||||||
}
|
}
|
||||||
dependencyGraph.complete(params.getDependencyGraphOption());
|
yield dependencyGraph.complete(params.getDependencyGraphOption());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.complete = complete;
|
exports.complete = complete;
|
||||||
|
|
2
dist/post/index.js.map
vendored
2
dist/post/index.js.map
vendored
File diff suppressed because one or more lines are too long
|
@ -4,6 +4,7 @@ import * as github from '@actions/github'
|
||||||
import * as glob from '@actions/glob'
|
import * as glob from '@actions/glob'
|
||||||
import * as toolCache from '@actions/tool-cache'
|
import * as toolCache from '@actions/tool-cache'
|
||||||
import {GitHub} from '@actions/github/lib/utils'
|
import {GitHub} from '@actions/github/lib/utils'
|
||||||
|
import {RequestError} from '@octokit/request-error'
|
||||||
import type {PullRequestEvent} from '@octokit/webhooks-types'
|
import type {PullRequestEvent} from '@octokit/webhooks-types'
|
||||||
|
|
||||||
import * as path from 'path'
|
import * as path from 'path'
|
||||||
|
@ -14,8 +15,13 @@ import {DependencyGraphOption, getJobMatrix} from './input-params'
|
||||||
|
|
||||||
const DEPENDENCY_GRAPH_ARTIFACT = 'dependency-graph'
|
const DEPENDENCY_GRAPH_ARTIFACT = 'dependency-graph'
|
||||||
|
|
||||||
export function setup(option: DependencyGraphOption): void {
|
export async function setup(option: DependencyGraphOption): Promise<void> {
|
||||||
if (option === DependencyGraphOption.Disabled || option === DependencyGraphOption.DownloadAndSubmit) {
|
if (option === DependencyGraphOption.Disabled) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// Download and submit early, for compatability with dependency review.
|
||||||
|
if (option === DependencyGraphOption.DownloadAndSubmit) {
|
||||||
|
await downloadAndSubmitDependencyGraphs()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,6 +41,7 @@ export function setup(option: DependencyGraphOption): void {
|
||||||
export async function complete(option: DependencyGraphOption): Promise<void> {
|
export async function complete(option: DependencyGraphOption): Promise<void> {
|
||||||
switch (option) {
|
switch (option) {
|
||||||
case DependencyGraphOption.Disabled:
|
case DependencyGraphOption.Disabled:
|
||||||
|
case DependencyGraphOption.DownloadAndSubmit: // Performed in setup
|
||||||
return
|
return
|
||||||
case DependencyGraphOption.Generate:
|
case DependencyGraphOption.Generate:
|
||||||
await uploadDependencyGraphs()
|
await uploadDependencyGraphs()
|
||||||
|
@ -42,8 +49,6 @@ export async function complete(option: DependencyGraphOption): Promise<void> {
|
||||||
case DependencyGraphOption.GenerateAndSubmit:
|
case DependencyGraphOption.GenerateAndSubmit:
|
||||||
await submitDependencyGraphs(await uploadDependencyGraphs())
|
await submitDependencyGraphs(await uploadDependencyGraphs())
|
||||||
return
|
return
|
||||||
case DependencyGraphOption.DownloadAndSubmit:
|
|
||||||
await downloadAndSubmitDependencyGraphs()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,9 +71,26 @@ async function downloadAndSubmitDependencyGraphs(): Promise<void> {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function submitDependencyGraphs(dependencyGraphFiles: string[]): Promise<void> {
|
async function submitDependencyGraphs(dependencyGraphFiles: string[]): Promise<void> {
|
||||||
const octokit = getOctokit()
|
|
||||||
|
|
||||||
for (const jsonFile of dependencyGraphFiles) {
|
for (const jsonFile of dependencyGraphFiles) {
|
||||||
|
try {
|
||||||
|
await submitDependencyGraphFile(jsonFile)
|
||||||
|
} catch (error) {
|
||||||
|
if (error instanceof RequestError) {
|
||||||
|
const relativeJsonFile = getRelativePathFromWorkspace(jsonFile)
|
||||||
|
core.warning(
|
||||||
|
`Failed to submit dependency graph ${relativeJsonFile}.\n` +
|
||||||
|
"Please ensure that the 'contents: write' permission is available for the workflow job.\n" +
|
||||||
|
"Note that this permission is never available for a 'pull_request' trigger from a repository fork."
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function submitDependencyGraphFile(jsonFile: string): Promise<void> {
|
||||||
|
const octokit = getOctokit()
|
||||||
const jsonContent = fs.readFileSync(jsonFile, 'utf8')
|
const jsonContent = fs.readFileSync(jsonFile, 'utf8')
|
||||||
|
|
||||||
const jsonObject = JSON.parse(jsonContent)
|
const jsonObject = JSON.parse(jsonContent)
|
||||||
|
@ -79,7 +101,6 @@ async function submitDependencyGraphs(dependencyGraphFiles: string[]): Promise<v
|
||||||
const relativeJsonFile = getRelativePathFromWorkspace(jsonFile)
|
const relativeJsonFile = getRelativePathFromWorkspace(jsonFile)
|
||||||
core.notice(`Submitted ${relativeJsonFile}: ${response.data.message}`)
|
core.notice(`Submitted ${relativeJsonFile}: ${response.data.message}`)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
async function retrieveDependencyGraphs(workspaceDirectory: string): Promise<string[]> {
|
async function retrieveDependencyGraphs(workspaceDirectory: string): Promise<string[]> {
|
||||||
if (github.context.payload.workflow_run) {
|
if (github.context.payload.workflow_run) {
|
||||||
|
|
|
@ -38,7 +38,7 @@ export async function setup(): Promise<void> {
|
||||||
|
|
||||||
core.saveState(CACHE_LISTENER, cacheListener.stringify())
|
core.saveState(CACHE_LISTENER, cacheListener.stringify())
|
||||||
|
|
||||||
dependencyGraph.setup(params.getDependencyGraphOption())
|
await dependencyGraph.setup(params.getDependencyGraphOption())
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function complete(): Promise<void> {
|
export async function complete(): Promise<void> {
|
||||||
|
@ -62,7 +62,7 @@ export async function complete(): Promise<void> {
|
||||||
logJobSummary(buildResults, cacheListener)
|
logJobSummary(buildResults, cacheListener)
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencyGraph.complete(params.getDependencyGraphOption())
|
await dependencyGraph.complete(params.getDependencyGraphOption())
|
||||||
}
|
}
|
||||||
|
|
||||||
async function determineGradleUserHome(): Promise<string> {
|
async function determineGradleUserHome(): Promise<string> {
|
||||||
|
|
Loading…
Reference in a new issue