Skip to content

Commit 06ff831

Browse files
authored
Skip distributor re-build (#1917)
1 parent 6a16e3f commit 06ff831

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

.github/workflows/build-test-artifacts.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ jobs:
8282

8383
BuildDistributor:
8484
needs: [BuildAndUpload, BuildAndUploadPackages, BuildDocker]
85+
if: ${{ github.event_name == 'push' || inputs.build-distributor }}
8586
uses: ./.github/workflows/test-build-distributor.yml
8687
secrets: inherit
8788
permissions:

.github/workflows/test-build-distributor.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ env:
33
CWA_GITHUB_TEST_REPO_NAME: "aws/amazon-cloudwatch-agent-test"
44
CWA_GITHUB_TEST_REPO_BRANCH: "main"
55
CHECKOUT_ROOT_DIR: "test"
6+
SSM_DISTRIBUTOR_VERSION_LIMIT: 25
67
on:
78
workflow_dispatch:
89
inputs:
@@ -74,22 +75,39 @@ jobs:
7475
contents: read
7576
outputs:
7677
agent-version: ${{ steps.version.outputs.version }}
78+
should-build: ${{ steps.check.outputs.should-build }}
7779
steps:
7880
- name: Configure AWS Credentials
7981
uses: aws-actions/configure-aws-credentials@v4
8082
with:
8183
role-to-assume: ${{ inputs.TerraformAWSAssumeRole }}
8284
aws-region: ${{ inputs.Region }}
85+
8386
- name: Agent Version
8487
id: version
8588
run: |
8689
aws s3 cp s3://${{ inputs.Bucket }}/${{ inputs.BucketKey }}/CWAGENT_VERSION .
8790
echo "version=$(cat CWAGENT_VERSION)" >> "$GITHUB_OUTPUT"
8891
92+
- name: Check if SSM distributor version already exists
93+
id: check
94+
run: |
95+
if aws ssm describe-document \
96+
--name "${{ inputs.DistributorName }}" \
97+
--region ${{ inputs.Region }} \
98+
--query 'Document.VersionName' \
99+
--output text 2>/dev/null | grep -q "^${{ steps.version.outputs.version }}$"; then
100+
echo "should-build=false" >> "$GITHUB_OUTPUT"
101+
echo "Version ${{ steps.version.outputs.version }} already exists, skipping build"
102+
else
103+
echo "should-build=true" >> "$GITHUB_OUTPUT"
104+
fi
105+
89106
PackageLinux:
90107
name: 'PackageLinux'
91108
runs-on: ubuntu-latest
92109
needs: [AgentVersion]
110+
if: needs.AgentVersion.outputs.should-build == 'true'
93111
permissions:
94112
id-token: write
95113
contents: read
@@ -149,6 +167,7 @@ jobs:
149167
name: 'PackageDarwin'
150168
runs-on: ubuntu-latest
151169
needs: [AgentVersion]
170+
if: needs.AgentVersion.outputs.should-build == 'true'
152171
permissions:
153172
id-token: write
154173
contents: read
@@ -206,6 +225,7 @@ jobs:
206225
name: 'PackageWindows'
207226
runs-on: ubuntu-latest
208227
needs: [AgentVersion]
228+
if: needs.AgentVersion.outputs.should-build == 'true'
209229
permissions:
210230
id-token: write
211231
contents: read
@@ -260,6 +280,7 @@ jobs:
260280
name: 'UploadDistributor'
261281
runs-on: ubuntu-latest
262282
needs: [AgentVersion, PackageLinux, PackageDarwin, PackageWindows]
283+
if: needs.AgentVersion.outputs.should-build == 'true'
263284
permissions:
264285
id-token: write
265286
contents: read
@@ -321,6 +342,16 @@ jobs:
321342
--document-type Package \
322343
--region ${{ inputs.Region }}
323344
345+
- name: Remove oldest if limit hit
346+
if: steps.check-distributor.outputs.exists == 'true'
347+
run: |
348+
VERSION_COUNT=$(aws ssm list-document-versions --name "${{ inputs.DistributorName }}" --region ${{ inputs.Region }} --no-paginate --query 'length(DocumentVersions)' --output text)
349+
if [ "$VERSION_COUNT" -ge ${{ env.SSM_DISTRIBUTOR_VERSION_LIMIT }} ]; then
350+
OLDEST_VERSION=$(aws ssm list-document-versions --name "${{ inputs.DistributorName }}" --region ${{ inputs.Region }} --no-paginate --query 'DocumentVersions[-1].DocumentVersion' --output text)
351+
echo "Deleting oldest version: $OLDEST_VERSION"
352+
aws ssm delete-document --name "${{ inputs.DistributorName }}" --document-version "$OLDEST_VERSION" --region ${{ inputs.Region }}
353+
fi
354+
324355
- name: Update distributor
325356
if: steps.check-distributor.outputs.exists == 'true'
326357
run: |

0 commit comments

Comments
 (0)