From 1e2fa056a87c24fa443eb98cb65964d05c6c952f Mon Sep 17 00:00:00 2001 From: Frostebite Date: Fri, 5 Sep 2025 02:28:43 +0100 Subject: [PATCH] test(s3): only list S3 when AWS creds present in CI; skip otherwise --- .../tests/cloud-runner-s3-steps.test.ts | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/model/cloud-runner/tests/cloud-runner-s3-steps.test.ts b/src/model/cloud-runner/tests/cloud-runner-s3-steps.test.ts index b754332b..d4c30eea 100644 --- a/src/model/cloud-runner/tests/cloud-runner-s3-steps.test.ts +++ b/src/model/cloud-runner/tests/cloud-runner-s3-steps.test.ts @@ -23,14 +23,11 @@ describe('Cloud Runner pre-built S3 steps', () => { }); setups(); (() => { - // Check if we're in a CI environment or if AWS CLI is available + // Determine environment capability to run S3 operations const isCI = process.env.GITHUB_ACTIONS === 'true'; let awsAvailable = false; - if (!isCI) { - // Only check AWS CLI locally, skip the test if not available try { - // Use synchronous check for AWS CLI availability const { execSync } = require('child_process'); execSync('aws --version', { stdio: 'ignore' }); awsAvailable = true; @@ -38,9 +35,11 @@ describe('Cloud Runner pre-built S3 steps', () => { awsAvailable = false; } } + const hasAwsCreds = Boolean(process.env.AWS_ACCESS_KEY_ID && process.env.AWS_SECRET_ACCESS_KEY); + const shouldRunS3 = (isCI && hasAwsCreds) || awsAvailable; - // Only run the test if we're in CI or AWS CLI is available - if (isCI || awsAvailable) { + // Only run the test if we have AWS creds in CI, or the AWS CLI is available locally + if (shouldRunS3) { it('Run build and prebuilt s3 cache pull, cache push and upload build', async () => { const overrides = { versioning: 'None', @@ -57,8 +56,8 @@ describe('Cloud Runner pre-built S3 steps', () => { CloudRunnerLogger.log(`run 2 succeeded`); expect(results2Object.BuildSucceeded).toBe(true); - // Only run S3 operations if we're in CI or AWS CLI is available - if (isCI || awsAvailable) { + // Only run S3 operations if environment supports it + if (shouldRunS3) { const results = await CloudRunnerSystem.RunAndReadLines( `aws s3 ls s3://${CloudRunner.buildParameters.awsStackName}/cloud-runner-cache/`, ); @@ -66,8 +65,8 @@ describe('Cloud Runner pre-built S3 steps', () => { } }, 1_000_000_000); } else { - it.skip('Run build and prebuilt s3 cache pull, cache push and upload build - AWS CLI not available locally', () => { - CloudRunnerLogger.log('AWS CLI not available locally, skipping S3 test'); + it.skip('Run build and prebuilt s3 cache pull, cache push and upload build - AWS not configured', () => { + CloudRunnerLogger.log('AWS not configured (no creds/CLI); skipping S3 test'); }); } })();