Skip to content

Commit

Permalink
fix(construct.awscdk.github-pipeline): resolve asset files correctly …
Browse files Browse the repository at this point in the history
…on latest cdk-github-pipelines version

Signed-off-by: Braden Mars <bradenmars@bradenmars.me>
  • Loading branch information
BradenM committed Oct 8, 2024
1 parent 81df0de commit bc481e9
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions packages/construct/awscdk/github-pipeline/src/workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,26 @@ export class GithubWorkflowPipeline extends ghpipelines.GitHubWorkflow {
).jobSteps
}

/**
* Resolve file asset path.
*
* Handles both the older behavior of placing assets directly under cdk.out
* and the newer behavior of placing them under an assembly directory.
*
* @param name Asset name.
* @protected
*/
protected resolveFileAsset(name: string): string | undefined {
const outDir = Stage.of(this)!.outdir
const assemblyNames = [...Object.values(this.getStageAccountIds())]
const assemblyPaths = assemblyNames.map((n) => `assembly-${n}`)
const possiblePaths = [
path.posix.join(outDir, name),
...assemblyPaths.map((p) => path.posix.join(outDir, p, name)),
]
return possiblePaths.find((p) => fs.existsSync(p))
}

/**
* Build matrix for publishing job assets.
* @protected
Expand All @@ -277,11 +297,12 @@ export class GithubWorkflowPipeline extends ghpipelines.GitHubWorkflow {
const assetHashMap: Record<string, string> = this.assetHashMap
const assetJobNames: string[] = Object.values(assetHashMap)

const outDir = Stage.of(this)!.outdir

const jobOutputs = Object.entries(assetHashMap).map(
([assetHash, jobName]) => {
const scriptPath = path.posix.join(outDir, `publish-${jobName}-step.sh`)
const scriptPath = this.resolveFileAsset(`publish-${jobName}-step.sh`)
if (!scriptPath) {
throw new Error(`Could not find script for asset ${jobName}`)
}
const lines = fs
.readFileSync(scriptPath, { encoding: 'utf-8' })
.toString()
Expand Down

0 comments on commit bc481e9

Please sign in to comment.