From 560dcd47b4c43474ac5708445cbb8ae6c2b856a6 Mon Sep 17 00:00:00 2001 From: Jacob Cable Date: Fri, 19 Apr 2024 14:04:23 +0100 Subject: [PATCH] test(*): test change --- .github/workflows/conditional-test.yml | 69 ++++++++++++++------- _emulator/firebase.json | 4 -- firestore-send-email/functions/package.json | 2 +- firestore-send-email/functions/src/index.ts | 2 +- 4 files changed, 48 insertions(+), 29 deletions(-) diff --git a/.github/workflows/conditional-test.yml b/.github/workflows/conditional-test.yml index 03f006ec05..e0cfc7e19d 100644 --- a/.github/workflows/conditional-test.yml +++ b/.github/workflows/conditional-test.yml @@ -12,51 +12,74 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v3 + with: + fetch-depth: 0 # Fetch all history for all branches and tags + ref: ${{ github.head_ref }} # Ensure PR's head is checked out - name: Get changed directories id: set_changed run: | echo "::group::Determining Changed Directories" - # List specific directories you want to check DIRECTORIES="auth-mailchimp-sync delete-user-data firestore-bigquery-export firestore-counter firestore-send-email firestore-shorten-urls-bitly firestore-translate-text rtdb-limit-child-nodes storage-resize-images" - # Initialize an empty string to hold the paths of changed directories - CHANGED_EXTENSIONS="" + # Set commit SHAs for comparison + BASE_SHA=${{ github.event.pull_request.base.sha }} + HEAD_SHA=${{ github.event.pull_request.head.sha }} + + # Initialize an empty JSON array + CHANGED_EXTENSIONS_JSON="[" - # Loop through each directory and check if there have been any changes + if ! git diff --name-only $BASE_SHA $HEAD_SHA > /dev/null 2>&1; then + echo "Error detecting changes using PR base and head SHAs, falling back to default branch comparison." + git fetch --no-tags --depth=1 origin +refs/heads/next:refs/remotes/origin/next + BASE_SHA=$(git rev-parse origin/next) + fi + + first_entry=true for dir in $DIRECTORIES; do - if git diff --name-only ${{ github.event.before }} ${{ github.event.after }} | grep -q "^extensions/$dir/"; then - CHANGED_EXTENSIONS+="$dir " + if git diff --name-only $BASE_SHA $HEAD_SHA | grep -q "^$dir/"; then + if [ "$first_entry" = true ]; then + first_entry=false + else + CHANGED_EXTENSIONS_JSON+=", " + fi + CHANGED_EXTENSIONS_JSON+="\"$dir\"" fi done - # Trim any trailing whitespace and print the output - CHANGED_EXTENSIONS=$(echo $CHANGED_EXTENSIONS | xargs) - echo "Changed extensions: $CHANGED_EXTENSIONS" + CHANGED_EXTENSIONS_JSON+="]" + + # Output the JSON array to the workflow + echo "changed_extensions=$CHANGED_EXTENSIONS_JSON" >> $GITHUB_OUTPUT + echo "Changed extensions: $CHANGED_EXTENSIONS_JSON" echo "::endgroup::" - echo "::set-output name=changed_extensions::$CHANGED_EXTENSIONS" test_extensions: needs: check_changes runs-on: ubuntu-latest strategy: + fail-fast: false matrix: extension: ${{ fromJson(needs.check_changes.outputs.changed_extensions) }} - defaults: - run: - working-directory: extensions/${{ matrix.extension }}/functions steps: - - name: Checkout code - uses: actions/checkout@v3 - - name: Setup node - uses: actions/setup-node@v3 + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 with: node-version: "18" cache: "npm" cache-dependency-path: "**/package-lock.json" - - name: Install dependencies - run: npm install - - name: Build - run: npm run build - - name: Run tests - run: npm test + - name: Install Firebase CLI + uses: nick-invision/retry@v1 + with: + timeout_minutes: 10 + retry_wait_seconds: 60 + max_attempts: 3 + command: npm i -g firebase-tools@11 + - name: Setup e2e secrets + run: | + echo SMTP_PASSWORD=${{ secrets.SENDGRID_API_KEY }} >> _emulator/extensions/firestore-send-email-sendgrid.secret.local + - run: | + echo "Checking directory: ${{ matrix.extension }}/functions" + - run: cd ${{ matrix.extension }}/functions && npm install + - run: cd ${{ matrix.extension }}/functions && npm run build + - run: cd ${{ matrix.extension }}/functions && npm run test:local diff --git a/_emulator/firebase.json b/_emulator/firebase.json index 70e56c96de..c16ca8cb71 100644 --- a/_emulator/firebase.json +++ b/_emulator/firebase.json @@ -1,10 +1,6 @@ { "extensions": { "firestore-send-email": "../firestore-send-email", - "delete-user-data": "../delete-user-data", - "storage-resize-images": "../storage-resize-images", - "firestore-counter": "../firestore-counter", - "firestore-bigquery-export": "../firestore-bigquery-export", "firestore-send-email-sendgrid": "../firestore-send-email" }, "storage": { diff --git a/firestore-send-email/functions/package.json b/firestore-send-email/functions/package.json index 09e9c4a659..05da57cb76 100644 --- a/firestore-send-email/functions/package.json +++ b/firestore-send-email/functions/package.json @@ -11,7 +11,7 @@ "local:emulator": "cd ../../_emulator && firebase emulators:start -P demo-test", "test": "cd ../../_emulator && firebase emulators:exec --only extensions jest -P demo-test", "testIfEmulatorRunning": "wait-on tcp:4001 && jest", - "test:local": "concurrently --kill-others \"npm run local:emulator\" \"npm run testIfEmulatorRunning\"", + "test:local": "concurrently --kill-others \"npm run local:emulator\" \"npm run testIfEmulatorRunning\" --success second", "test:watch": "concurrently \"npm run local:emulator\" \"jest --watch\"", "generate-readme": "firebase ext:info .. --markdown > ../README.md" }, diff --git a/firestore-send-email/functions/src/index.ts b/firestore-send-email/functions/src/index.ts index ce8eb3ed0f..695045bd8d 100644 --- a/firestore-send-email/functions/src/index.ts +++ b/firestore-send-email/functions/src/index.ts @@ -27,7 +27,7 @@ import { parseTlsOptions, setSmtpCredentials } from "./helpers"; import * as events from "./events"; logs.init(); - +console.log(""); let db: admin.firestore.Firestore; let transport: nodemailer.Transporter; let templates: Templates;