diff --git a/.github/workflows/deploy-feature-branch.yml b/.github/workflows/deploy-feature-branch.yml index 2404ac9ae..57e992671 100644 --- a/.github/workflows/deploy-feature-branch.yml +++ b/.github/workflows/deploy-feature-branch.yml @@ -1,12 +1,12 @@ on: pull_request: branches: - - main + - main types: - opened - reopened name: Initial Feature Branch Deploy -jobs: +jobs: deploy: permissions: write-all runs-on: ubuntu-latest @@ -26,12 +26,12 @@ jobs: npm ci cd cdk-infra/ npm ci - npm run deploy:feature:stack -- -c env=stg -c customFeatureName=enhancedApp-stg-${{github.head_ref}} auto-builder-stack-enhancedApp-stg-${{github.head_ref}}-queues - npm run deploy:feature:stack -- -c env=stg -c customFeatureName=enhancedApp-stg-${{github.head_ref}} auto-builder-stack-enhancedApp-stg-${{github.head_ref}}-worker - npm run deploy:feature:stack -- -c env=stg -c customFeatureName=enhancedApp-stg-${{github.head_ref}} auto-builder-stack-enhancedApp-stg-${{github.head_ref}}-webhooks --outputs-file outputs.json - - name: Get Webhook URL + npm run deploy:feature:stack -- -c isFeatureBranch=true -c env=stg -c customFeatureName=enhancedApp-stg-${{github.head_ref}} auto-builder-stack-enhancedApp-stg-${{github.head_ref}}-queues + npm run deploy:feature:stack -- -c isFeatureBranch=true -c env=stg -c customFeatureName=enhancedApp-stg-${{github.head_ref}} auto-builder-stack-enhancedApp-stg-${{github.head_ref}}-worker + npm run deploy:feature:stack -- -c isFeatureBranch=true -c env=stg -c customFeatureName=enhancedApp-stg-${{github.head_ref}} auto-builder-stack-enhancedApp-stg-${{github.head_ref}}-webhooks --outputs-file outputs.json + - name: Get Webhook URL uses: mongodb/docs-worker-actions/comment-pr@main - env: + env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Cache root node_modules id: cache-root diff --git a/.github/workflows/update-feature-branch.yml b/.github/workflows/update-feature-branch.yml index 151a8faed..a7a6f534e 100644 --- a/.github/workflows/update-feature-branch.yml +++ b/.github/workflows/update-feature-branch.yml @@ -9,10 +9,10 @@ concurrency: group: environment-stg-feature-${{ github.ref }} cancel-in-progress: true name: Update Feature Branch Infrastructure -jobs: +jobs: prep-build: runs-on: ubuntu-latest - + steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 @@ -73,7 +73,7 @@ jobs: if: steps.filter.outputs.webhooks == 'true' run: | cd cdk-infra/ - npm run deploy:feature:stack -- -c env=stg -c customFeatureName=enhancedApp-stg-${{github.head_ref}} \ + npm run deploy:feature:stack -- -c isFeatureBranch=true -c env=stg -c customFeatureName=enhancedApp-stg-${{github.head_ref}} \ auto-builder-stack-enhancedApp-stg-${{github.head_ref}}-webhooks build-worker: needs: prep-build @@ -109,5 +109,5 @@ jobs: if: steps.filter.outputs.worker == 'true' run: | cd cdk-infra/ - npm run deploy:feature:stack -- -c env=stg -c customFeatureName=enhancedApp-stg-${{github.head_ref}} \ - auto-builder-stack-enhancedApp-stg-${{github.head_ref}}-worker \ No newline at end of file + npm run deploy:feature:stack -- -c isFeatureBranch=true -c env=stg -c customFeatureName=enhancedApp-stg-${{github.head_ref}} \ + auto-builder-stack-enhancedApp-stg-${{github.head_ref}}-worker diff --git a/cdk-infra/lib/constructs/worker/worker-env-construct.ts b/cdk-infra/lib/constructs/worker/worker-env-construct.ts index 48a7589c8..1b532a16c 100644 --- a/cdk-infra/lib/constructs/worker/worker-env-construct.ts +++ b/cdk-infra/lib/constructs/worker/worker-env-construct.ts @@ -2,7 +2,14 @@ import { IQueue } from 'aws-cdk-lib/aws-sqs'; import { StringParameter } from 'aws-cdk-lib/aws-ssm'; import { Construct } from 'constructs'; import { getCdnInvalidatorUrl } from '../../../utils/cdn'; -import { getEnv, envShortToFullName, getIsEnhanced, getUseCustomBuckets, getFeatureName } from '../../../utils/env'; +import { + getEnv, + envShortToFullName, + getIsEnhanced, + getUseCustomBuckets, + getFeatureName, + getIsFeatureBranch, +} from '../../../utils/env'; import { getSearchIndexFolder } from '../../../utils/search-index'; import { getSsmPathPrefix } from '../../../utils/ssm'; @@ -90,11 +97,12 @@ export class WorkerEnvConstruct extends Construct { SEARCH_INDEX_FOLDER: getSearchIndexFolder(env), ENHANCED: `${getIsEnhanced()}`, USE_CUSTOM_BUCKETS: `${getUseCustomBuckets()}`, - FEATURE_NAME: `${getFeatureName()}`, + FEATURE_NAME: getFeatureName(), GATSBY_TEST_SEARCH_UI: 'false', GATSBY_SHOW_CHATBOT: gatsbyUseChatbot, GATSBY_HIDE_UNIFIED_FOOTER_LOCALE: gatsbyHideUnifiedFooterLocale, GATSBY_MARIAN_URL: gatsbyMarianUrl, + IS_FEATURE_BRANCH: getIsFeatureBranch(), }; } } diff --git a/cdk-infra/utils/env.ts b/cdk-infra/utils/env.ts index 9979090fb..7b8969f49 100644 --- a/cdk-infra/utils/env.ts +++ b/cdk-infra/utils/env.ts @@ -92,6 +92,19 @@ export function getSnootyParserVersion(): string { return snootyParserVersion; } + +export function getIsFeatureBranch() { + checkContextInit(); + const isFeatureBranch = contextVarsMap.get('isFeatureBranch'); + + if (!isFeatureBranch) { + console.warn('Error! The context variable isFeatureBranch is not defined.'); + return ''; + } + + return isFeatureBranch; +} + export function getFeatureName(): string { checkContextInit(); diff --git a/src/job/jobHandler.ts b/src/job/jobHandler.ts index e2a48371a..0434f7367 100644 --- a/src/job/jobHandler.ts +++ b/src/job/jobHandler.ts @@ -113,7 +113,11 @@ export abstract class JobHandler { // completed after the Gatsby Cloud build via the SnootyBuildComplete lambda. const { _id: jobId, user } = this.currJob; const gatsbyCloudSiteId = await this._repoEntitlementsRepo.getGatsbySiteIdByGithubUsername(user); - if (gatsbyCloudSiteId && this.currJob.payload.jobType === 'githubPush') { + if ( + gatsbyCloudSiteId && + this.currJob.payload.jobType === 'githubPush' && + process.env.IS_FEATURE_BRANCH !== 'true' + ) { this.logger.info( jobId, `User ${user} has a Gatsby Cloud site. The Autobuilder will not mark the build as completed right now.` @@ -353,7 +357,12 @@ export abstract class JobHandler { // Call Gatsby Cloud preview webhook after persistence module finishes for staging builds const isFeaturePreviewWebhookEnabled = process.env.GATSBY_CLOUD_PREVIEW_WEBHOOK_ENABLED?.toLowerCase() === 'true'; - if (key === 'persistence-module' && this.name === 'Staging' && isFeaturePreviewWebhookEnabled) { + if ( + key === 'persistence-module' && + this.name === 'Staging' && + isFeaturePreviewWebhookEnabled && + process.env.IS_FEATURE_BRANCH !== 'true' + ) { await this.callGatsbyCloudWebhook(); } }