Generated graph is submitted immediately by dependency-submission action

While `setup-gradle` must wait until the end of job to submit all of the generated
graphs, the `dependency-submission` action will not save/upload the generated graph
immediately, in the same step where it is generated.
This commit is contained in:
daz
2024-04-07 12:27:51 -06:00
parent 38a821729e
commit 90bf65c87c
7 changed files with 105 additions and 69 deletions

View File

@@ -14,6 +14,7 @@
"no-unused-vars": "off",
"no-shadow": "off",
"sort-imports": "off",
"github/array-foreach": "off",
"@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "^_" }],
"@typescript-eslint/explicit-member-accessibility": ["error", {"accessibility": "no-public"}],
"@typescript-eslint/no-require-imports": "error",

View File

@@ -54,11 +54,6 @@ function maybeExportVariable(variableName: string, value: unknown): void {
}
export async function complete(config: DependencyGraphConfig): Promise<void> {
if (isRunningInActEnvironment()) {
core.info('Dependency graph upload and submit not supported in the ACT environment.')
return
}
const option = config.getDependencyGraphOption()
try {
switch (option) {
@@ -84,6 +79,12 @@ async function findGeneratedDependencyGraphFiles(): Promise<string[]> {
}
async function uploadDependencyGraphs(dependencyGraphFiles: string[], config: DependencyGraphConfig): Promise<void> {
if (isRunningInActEnvironment()) {
core.info('Dependency graph upload not supported in the ACT environment.')
core.info(`Would upload: ${dependencyGraphFiles.join(', ')}`)
return
}
const workspaceDirectory = layout.workspaceDirectory()
const artifactClient = new DefaultArtifactClient()
@@ -111,12 +112,18 @@ async function downloadAndSubmitDependencyGraphs(config: DependencyGraphConfig):
}
async function submitDependencyGraphs(dependencyGraphFiles: string[]): Promise<void> {
for (const jsonFile of dependencyGraphFiles) {
if (isRunningInActEnvironment()) {
core.info('Dependency graph submit not supported in the ACT environment.')
core.info(`Would submit: ${dependencyGraphFiles.join(', ')}`)
return
}
for (const dependencyGraphFile of dependencyGraphFiles) {
try {
await submitDependencyGraphFile(jsonFile)
await submitDependencyGraphFile(dependencyGraphFile)
} catch (error) {
if (error instanceof RequestError) {
throw new Error(translateErrorMessage(jsonFile, error))
throw new Error(translateErrorMessage(dependencyGraphFile, error))
} else {
throw error
}
@@ -184,8 +191,20 @@ async function downloadDependencyGraphs(): Promise<string[]> {
async function findDependencyGraphFiles(dir: string): Promise<string[]> {
const globber = await glob.create(`${dir}/dependency-graph-reports/*.json`)
const graphFiles = globber.glob()
return graphFiles
const allFiles = await globber.glob()
const unprocessedFiles = allFiles.filter(file => !isProcessed(file))
unprocessedFiles.forEach(markProcessed)
return unprocessedFiles
}
function isProcessed(dependencyGraphFile: string): boolean {
const markerFile = `${dependencyGraphFile}.processed`
return fs.existsSync(markerFile)
}
function markProcessed(dependencyGraphFile: string): void {
const markerFile = `${dependencyGraphFile}.processed`
fs.writeFileSync(markerFile, '')
}
function warnOrFail(config: DependencyGraphConfig, option: String, error: unknown): void {

View File

@@ -42,6 +42,8 @@ export async function run(): Promise<void> {
const args: string[] = parseArgsStringToArgv(executionArgs)
const buildRootDirectory = layout.buildRootDirectory()
await execution.executeGradleBuild(executable, buildRootDirectory, args)
await dependencyGraph.complete(config)
} catch (error) {
core.setFailed(String(error))
if (error instanceof Error && error.stack) {

View File

@@ -1,8 +1,7 @@
import * as core from '@actions/core'
import * as setupGradle from '../setup-gradle'
import * as dependencyGraph from '../dependency-graph'
import {CacheConfig, DependencyGraphConfig, SummaryConfig} from '../input-params'
import {CacheConfig, SummaryConfig} from '../input-params'
import {PostActionJobFailure} from '../errors'
// Catch and log any unhandled exceptions. These exceptions can leak out of the uploadChunk method in
@@ -15,10 +14,7 @@ process.on('uncaughtException', e => handleFailure(e))
*/
export async function run(): Promise<void> {
try {
if (await setupGradle.complete(new CacheConfig(), new SummaryConfig())) {
// Only submit the dependency graphs once per job
await dependencyGraph.complete(new DependencyGraphConfig())
}
await setupGradle.complete(new CacheConfig(), new SummaryConfig())
} catch (error) {
if (error instanceof PostActionJobFailure) {
core.setFailed(String(error))