Skip to content

Commit 6578588

Browse files
committed
Add pagination and limit for change set info to prevent GitHub Actions output limits
1 parent d740ac8 commit 6578588

File tree

2 files changed

+106
-67
lines changed

2 files changed

+106
-67
lines changed

dist/index.js

Lines changed: 50 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -50204,38 +50204,56 @@ function executeExistingChangeSet(cfn, stackName, changeSetId) {
5020450204
}
5020550205
function getChangeSetInfo(cfn, changeSetName, stackName) {
5020650206
return __awaiter(this, void 0, void 0, function* () {
50207-
const changeSetStatus = yield cfn.send(new client_cloudformation_1.DescribeChangeSetCommand({
50208-
ChangeSetName: changeSetName,
50209-
StackName: stackName,
50210-
IncludePropertyValues: true
50211-
}));
50212-
const changes = changeSetStatus.Changes || [];
50213-
const hasChanges = changes.length > 0;
50214-
const changesSummary = {
50215-
changes: changes.map(change => ({
50216-
type: change.Type,
50217-
resourceChange: change.ResourceChange
50218-
? {
50219-
action: change.ResourceChange.Action,
50220-
logicalResourceId: change.ResourceChange.LogicalResourceId,
50221-
physicalResourceId: change.ResourceChange.PhysicalResourceId,
50222-
resourceType: change.ResourceChange.ResourceType,
50223-
replacement: change.ResourceChange.Replacement,
50224-
scope: change.ResourceChange.Scope
50225-
}
50226-
: undefined
50227-
})),
50228-
executionStatus: changeSetStatus.ExecutionStatus,
50229-
status: changeSetStatus.Status,
50230-
creationTime: changeSetStatus.CreationTime
50231-
};
50232-
return {
50233-
changeSetId: changeSetStatus.ChangeSetId,
50234-
changeSetName: changeSetStatus.ChangeSetName,
50235-
hasChanges,
50236-
changesCount: changes.length,
50237-
changesSummary: JSON.stringify(changesSummary, null, 2)
50238-
};
50207+
const MAX_CHANGES_IN_SUMMARY = 50; // Limit to prevent exceeding GitHub Actions output limits
50208+
let allChanges = [];
50209+
let nextToken;
50210+
// Paginate through all changes
50211+
do {
50212+
const changeSetStatus = yield cfn.send(new client_cloudformation_1.DescribeChangeSetCommand({
50213+
ChangeSetName: changeSetName,
50214+
StackName: stackName,
50215+
IncludePropertyValues: true,
50216+
NextToken: nextToken
50217+
}));
50218+
const changes = changeSetStatus.Changes || [];
50219+
allChanges = allChanges.concat(changes);
50220+
nextToken = changeSetStatus.NextToken;
50221+
// Get the first response for metadata
50222+
if (!nextToken) {
50223+
const hasChanges = allChanges.length > 0;
50224+
const limitedChanges = allChanges.slice(0, MAX_CHANGES_IN_SUMMARY);
50225+
const truncated = allChanges.length > MAX_CHANGES_IN_SUMMARY;
50226+
const changesSummary = {
50227+
changes: limitedChanges.map(change => ({
50228+
type: change.Type,
50229+
resourceChange: change.ResourceChange
50230+
? {
50231+
action: change.ResourceChange.Action,
50232+
logicalResourceId: change.ResourceChange.LogicalResourceId,
50233+
physicalResourceId: change.ResourceChange.PhysicalResourceId,
50234+
resourceType: change.ResourceChange.ResourceType,
50235+
replacement: change.ResourceChange.Replacement,
50236+
scope: change.ResourceChange.Scope
50237+
}
50238+
: undefined
50239+
})),
50240+
totalChanges: allChanges.length,
50241+
truncated,
50242+
executionStatus: changeSetStatus.ExecutionStatus,
50243+
status: changeSetStatus.Status,
50244+
creationTime: changeSetStatus.CreationTime
50245+
};
50246+
return {
50247+
changeSetId: changeSetStatus.ChangeSetId,
50248+
changeSetName: changeSetStatus.ChangeSetName,
50249+
hasChanges,
50250+
changesCount: allChanges.length,
50251+
changesSummary: JSON.stringify(changesSummary, null, 2)
50252+
};
50253+
}
50254+
} while (nextToken);
50255+
// This should never be reached, but TypeScript requires it
50256+
throw new Error('Unexpected end of pagination');
5023950257
});
5024050258
}
5024150259
function cleanupChangeSet(cfn, stack, params, noEmptyChangeSet, noDeleteFailedChangeSet) {

src/deploy.ts

Lines changed: 56 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -111,43 +111,64 @@ export async function getChangeSetInfo(
111111
changeSetName: string,
112112
stackName: string
113113
): Promise<ChangeSetInfo> {
114-
const changeSetStatus = await cfn.send(
115-
new DescribeChangeSetCommand({
116-
ChangeSetName: changeSetName,
117-
StackName: stackName,
118-
IncludePropertyValues: true
119-
})
120-
)
114+
const MAX_CHANGES_IN_SUMMARY = 50 // Limit to prevent exceeding GitHub Actions output limits
115+
let allChanges: any[] = []
116+
let nextToken: string | undefined
117+
118+
// Paginate through all changes
119+
do {
120+
const changeSetStatus = await cfn.send(
121+
new DescribeChangeSetCommand({
122+
ChangeSetName: changeSetName,
123+
StackName: stackName,
124+
IncludePropertyValues: true,
125+
NextToken: nextToken
126+
})
127+
)
121128

122-
const changes = changeSetStatus.Changes || []
123-
const hasChanges = changes.length > 0
124-
125-
const changesSummary = {
126-
changes: changes.map(change => ({
127-
type: change.Type,
128-
resourceChange: change.ResourceChange
129-
? {
130-
action: change.ResourceChange.Action,
131-
logicalResourceId: change.ResourceChange.LogicalResourceId,
132-
physicalResourceId: change.ResourceChange.PhysicalResourceId,
133-
resourceType: change.ResourceChange.ResourceType,
134-
replacement: change.ResourceChange.Replacement,
135-
scope: change.ResourceChange.Scope
136-
}
137-
: undefined
138-
})),
139-
executionStatus: changeSetStatus.ExecutionStatus,
140-
status: changeSetStatus.Status,
141-
creationTime: changeSetStatus.CreationTime
142-
}
129+
const changes = changeSetStatus.Changes || []
130+
allChanges = allChanges.concat(changes)
131+
nextToken = changeSetStatus.NextToken
132+
133+
// Get the first response for metadata
134+
if (!nextToken) {
135+
const hasChanges = allChanges.length > 0
136+
const limitedChanges = allChanges.slice(0, MAX_CHANGES_IN_SUMMARY)
137+
const truncated = allChanges.length > MAX_CHANGES_IN_SUMMARY
138+
139+
const changesSummary = {
140+
changes: limitedChanges.map(change => ({
141+
type: change.Type,
142+
resourceChange: change.ResourceChange
143+
? {
144+
action: change.ResourceChange.Action,
145+
logicalResourceId: change.ResourceChange.LogicalResourceId,
146+
physicalResourceId: change.ResourceChange.PhysicalResourceId,
147+
resourceType: change.ResourceChange.ResourceType,
148+
replacement: change.ResourceChange.Replacement,
149+
scope: change.ResourceChange.Scope
150+
}
151+
: undefined
152+
})),
153+
totalChanges: allChanges.length,
154+
truncated,
155+
executionStatus: changeSetStatus.ExecutionStatus,
156+
status: changeSetStatus.Status,
157+
creationTime: changeSetStatus.CreationTime
158+
}
143159

144-
return {
145-
changeSetId: changeSetStatus.ChangeSetId,
146-
changeSetName: changeSetStatus.ChangeSetName,
147-
hasChanges,
148-
changesCount: changes.length,
149-
changesSummary: JSON.stringify(changesSummary, null, 2)
150-
}
160+
return {
161+
changeSetId: changeSetStatus.ChangeSetId,
162+
changeSetName: changeSetStatus.ChangeSetName,
163+
hasChanges,
164+
changesCount: allChanges.length,
165+
changesSummary: JSON.stringify(changesSummary, null, 2)
166+
}
167+
}
168+
} while (nextToken)
169+
170+
// This should never be reached, but TypeScript requires it
171+
throw new Error('Unexpected end of pagination')
151172
}
152173

153174
export async function cleanupChangeSet(

0 commit comments

Comments
 (0)