mirror of
https://github.com/gradle/actions.git
synced 2025-08-18 23:01:27 +08:00
Make dependency-submission and setup-gradle play nicely
Now, a `dependency-submission` step will trigger a dependency-graph generation, even if it follows a `setup-gradle` step in the workflow. Similarly, a `setup-gradle` step with `dependency-graph` configured will function as expected even if it follows a `setup-gradle` step.
This commit is contained in:
parent
ebf4d13461
commit
ed4d086d37
6
.github/workflows/dependency-submission.yml
vendored
6
.github/workflows/dependency-submission.yml
vendored
@ -60,11 +60,5 @@ jobs:
|
|||||||
- name: Generate and submit dependencies
|
- name: Generate and submit dependencies
|
||||||
id: dependency-submission
|
id: dependency-submission
|
||||||
uses: ./dependency-submission
|
uses: ./dependency-submission
|
||||||
continue-on-error: true
|
|
||||||
with:
|
with:
|
||||||
build-root-directory: .github/workflow-samples/groovy-dsl
|
build-root-directory: .github/workflow-samples/groovy-dsl
|
||||||
- name: Assert step failure
|
|
||||||
if: steps.dependency-submission.outcome != 'failure'
|
|
||||||
run: |
|
|
||||||
echo "Dependency submission step should fail after setup-gradle"
|
|
||||||
exit 1
|
|
||||||
|
@ -23,6 +23,7 @@ const DEPENDENCY_GRAPH_PREFIX = 'dependency-graph_'
|
|||||||
|
|
||||||
export async function setup(option: DependencyGraphOption): Promise<void> {
|
export async function setup(option: DependencyGraphOption): Promise<void> {
|
||||||
if (option === DependencyGraphOption.Disabled) {
|
if (option === DependencyGraphOption.Disabled) {
|
||||||
|
core.exportVariable('GITHUB_DEPENDENCY_GRAPH_ENABLED', 'false')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Download and submit early, for compatability with dependency review.
|
// Download and submit early, for compatability with dependency review.
|
||||||
@ -32,7 +33,7 @@ export async function setup(option: DependencyGraphOption): Promise<void> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
core.info('Enabling dependency graph generation')
|
core.info('Enabling dependency graph generation')
|
||||||
maybeExportVariable('GITHUB_DEPENDENCY_GRAPH_ENABLED', 'true')
|
core.exportVariable('GITHUB_DEPENDENCY_GRAPH_ENABLED', 'true')
|
||||||
maybeExportVariable('GITHUB_DEPENDENCY_GRAPH_CONTINUE_ON_FAILURE', getDependencyGraphContinueOnFailure())
|
maybeExportVariable('GITHUB_DEPENDENCY_GRAPH_CONTINUE_ON_FAILURE', getDependencyGraphContinueOnFailure())
|
||||||
maybeExportVariable('GITHUB_DEPENDENCY_GRAPH_JOB_CORRELATOR', getJobCorrelator())
|
maybeExportVariable('GITHUB_DEPENDENCY_GRAPH_JOB_CORRELATOR', getJobCorrelator())
|
||||||
maybeExportVariable('GITHUB_DEPENDENCY_GRAPH_JOB_ID', github.context.runId)
|
maybeExportVariable('GITHUB_DEPENDENCY_GRAPH_JOB_ID', github.context.runId)
|
||||||
|
@ -4,6 +4,8 @@ import * as setupGradle from '../setup-gradle'
|
|||||||
import * as execution from '../execution'
|
import * as execution from '../execution'
|
||||||
import * as provisioner from '../provision'
|
import * as provisioner from '../provision'
|
||||||
import * as layout from '../repository-layout'
|
import * as layout from '../repository-layout'
|
||||||
|
import * as dependencyGraph from '../dependency-graph'
|
||||||
|
|
||||||
import {parseArgsStringToArgv} from 'string-argv'
|
import {parseArgsStringToArgv} from 'string-argv'
|
||||||
import {DependencyGraphOption, getDependencyGraphOption} from '../input-params'
|
import {DependencyGraphOption, getDependencyGraphOption} from '../input-params'
|
||||||
|
|
||||||
@ -12,16 +14,12 @@ import {DependencyGraphOption, getDependencyGraphOption} from '../input-params'
|
|||||||
*/
|
*/
|
||||||
export async function run(): Promise<void> {
|
export async function run(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
if (process.env['GRADLE_BUILD_ACTION_SETUP_COMPLETED']) {
|
|
||||||
core.setFailed(
|
|
||||||
'The dependency-submission action cannot be used in the same Job as the setup-gradle action. Please use a separate Job for dependency submission.'
|
|
||||||
)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Configure Gradle environment (Gradle User Home)
|
// Configure Gradle environment (Gradle User Home)
|
||||||
await setupGradle.setup()
|
await setupGradle.setup()
|
||||||
|
|
||||||
|
// Configure the dependency graph submission
|
||||||
|
await dependencyGraph.setup(getDependencyGraphOption())
|
||||||
|
|
||||||
if (getDependencyGraphOption() === DependencyGraphOption.DownloadAndSubmit) {
|
if (getDependencyGraphOption() === DependencyGraphOption.DownloadAndSubmit) {
|
||||||
// No execution to perform
|
// No execution to perform
|
||||||
return
|
return
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
import * as core from '@actions/core'
|
import * as core from '@actions/core'
|
||||||
import * as setupGradle from '../setup-gradle'
|
import * as setupGradle from '../setup-gradle'
|
||||||
|
import * as dependencyGraph from '../dependency-graph'
|
||||||
|
|
||||||
|
import {getDependencyGraphOption} from '../input-params'
|
||||||
import {PostActionJobFailure} from '../errors'
|
import {PostActionJobFailure} from '../errors'
|
||||||
|
|
||||||
// Catch and log any unhandled exceptions. These exceptions can leak out of the uploadChunk method in
|
// Catch and log any unhandled exceptions. These exceptions can leak out of the uploadChunk method in
|
||||||
@ -12,7 +15,10 @@ process.on('uncaughtException', e => handleFailure(e))
|
|||||||
*/
|
*/
|
||||||
export async function run(): Promise<void> {
|
export async function run(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
await setupGradle.complete()
|
if (await setupGradle.complete()) {
|
||||||
|
// Only submit the dependency graphs once per job
|
||||||
|
await dependencyGraph.complete(getDependencyGraphOption())
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error instanceof PostActionJobFailure) {
|
if (error instanceof PostActionJobFailure) {
|
||||||
core.setFailed(String(error))
|
core.setFailed(String(error))
|
||||||
|
@ -4,8 +4,6 @@ import * as path from 'path'
|
|||||||
import * as os from 'os'
|
import * as os from 'os'
|
||||||
import * as caches from './caches'
|
import * as caches from './caches'
|
||||||
import * as layout from './repository-layout'
|
import * as layout from './repository-layout'
|
||||||
import * as params from './input-params'
|
|
||||||
import * as dependencyGraph from './dependency-graph'
|
|
||||||
import * as jobSummary from './job-summary'
|
import * as jobSummary from './job-summary'
|
||||||
import * as buildScan from './build-scan'
|
import * as buildScan from './build-scan'
|
||||||
|
|
||||||
@ -18,14 +16,14 @@ const USER_HOME = 'USER_HOME'
|
|||||||
const GRADLE_USER_HOME = 'GRADLE_USER_HOME'
|
const GRADLE_USER_HOME = 'GRADLE_USER_HOME'
|
||||||
const CACHE_LISTENER = 'CACHE_LISTENER'
|
const CACHE_LISTENER = 'CACHE_LISTENER'
|
||||||
|
|
||||||
export async function setup(): Promise<void> {
|
export async function setup(): Promise<boolean> {
|
||||||
const userHome = await determineUserHome()
|
const userHome = await determineUserHome()
|
||||||
const gradleUserHome = await determineGradleUserHome()
|
const gradleUserHome = await determineGradleUserHome()
|
||||||
|
|
||||||
// Bypass setup on all but first action step in workflow.
|
// Bypass setup on all but first action step in workflow.
|
||||||
if (process.env[GRADLE_SETUP_VAR]) {
|
if (process.env[GRADLE_SETUP_VAR]) {
|
||||||
core.info('Gradle setup only performed on first gradle/actions step in workflow.')
|
core.info('Gradle setup only performed on first gradle/actions step in workflow.')
|
||||||
return
|
return false
|
||||||
}
|
}
|
||||||
// Record setup complete: visible to all subsequent actions and prevents duplicate setup
|
// Record setup complete: visible to all subsequent actions and prevents duplicate setup
|
||||||
core.exportVariable(GRADLE_SETUP_VAR, true)
|
core.exportVariable(GRADLE_SETUP_VAR, true)
|
||||||
@ -41,15 +39,15 @@ export async function setup(): Promise<void> {
|
|||||||
|
|
||||||
core.saveState(CACHE_LISTENER, cacheListener.stringify())
|
core.saveState(CACHE_LISTENER, cacheListener.stringify())
|
||||||
|
|
||||||
await dependencyGraph.setup(params.getDependencyGraphOption())
|
|
||||||
|
|
||||||
buildScan.setup()
|
buildScan.setup()
|
||||||
|
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function complete(): Promise<void> {
|
export async function complete(): Promise<boolean> {
|
||||||
if (!core.getState(GRADLE_SETUP_VAR)) {
|
if (!core.getState(GRADLE_SETUP_VAR)) {
|
||||||
core.info('Gradle setup post-action only performed for first gradle/actions step in workflow.')
|
core.info('Gradle setup post-action only performed for first gradle/actions step in workflow.')
|
||||||
return
|
return false
|
||||||
}
|
}
|
||||||
core.info('In post-action step')
|
core.info('In post-action step')
|
||||||
|
|
||||||
@ -64,9 +62,9 @@ export async function complete(): Promise<void> {
|
|||||||
|
|
||||||
await jobSummary.generateJobSummary(buildResults, cacheListener)
|
await jobSummary.generateJobSummary(buildResults, cacheListener)
|
||||||
|
|
||||||
await dependencyGraph.complete(params.getDependencyGraphOption())
|
|
||||||
|
|
||||||
core.info('Completed post-action step')
|
core.info('Completed post-action step')
|
||||||
|
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
async function determineGradleUserHome(): Promise<string> {
|
async function determineGradleUserHome(): Promise<string> {
|
||||||
|
@ -5,6 +5,7 @@ import * as execution from '../execution'
|
|||||||
import * as provisioner from '../provision'
|
import * as provisioner from '../provision'
|
||||||
import * as layout from '../repository-layout'
|
import * as layout from '../repository-layout'
|
||||||
import * as params from '../input-params'
|
import * as params from '../input-params'
|
||||||
|
import * as dependencyGraph from '../dependency-graph'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The main entry point for the action, called by Github Actions for the step.
|
* The main entry point for the action, called by Github Actions for the step.
|
||||||
@ -14,6 +15,9 @@ export async function run(): Promise<void> {
|
|||||||
// Configure Gradle environment (Gradle User Home)
|
// Configure Gradle environment (Gradle User Home)
|
||||||
await setupGradle.setup()
|
await setupGradle.setup()
|
||||||
|
|
||||||
|
// Configure the dependency graph submission
|
||||||
|
await dependencyGraph.setup(params.getDependencyGraphOption())
|
||||||
|
|
||||||
// Download and install Gradle if required
|
// Download and install Gradle if required
|
||||||
const executable = await provisioner.provisionGradle()
|
const executable = await provisioner.provisionGradle()
|
||||||
|
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
import * as core from '@actions/core'
|
import * as core from '@actions/core'
|
||||||
import * as setupGradle from '../setup-gradle'
|
import * as setupGradle from '../setup-gradle'
|
||||||
|
import * as dependencyGraph from '../dependency-graph'
|
||||||
|
|
||||||
|
import {getDependencyGraphOption} from '../input-params'
|
||||||
import {PostActionJobFailure} from '../errors'
|
import {PostActionJobFailure} from '../errors'
|
||||||
|
|
||||||
// Catch and log any unhandled exceptions. These exceptions can leak out of the uploadChunk method in
|
// Catch and log any unhandled exceptions. These exceptions can leak out of the uploadChunk method in
|
||||||
@ -12,7 +15,10 @@ process.on('uncaughtException', e => handleFailure(e))
|
|||||||
*/
|
*/
|
||||||
export async function run(): Promise<void> {
|
export async function run(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
await setupGradle.complete()
|
if (await setupGradle.complete()) {
|
||||||
|
// Only submit the dependency graphs once per job
|
||||||
|
await dependencyGraph.complete(getDependencyGraphOption())
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error instanceof PostActionJobFailure) {
|
if (error instanceof PostActionJobFailure) {
|
||||||
core.setFailed(String(error))
|
core.setFailed(String(error))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user