Skip to content

Commit

Permalink
test(*): test change
Browse files Browse the repository at this point in the history
  • Loading branch information
cabljac committed Apr 19, 2024
1 parent 924ddd2 commit 560dcd4
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 29 deletions.
69 changes: 46 additions & 23 deletions .github/workflows/conditional-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 0 additions & 4 deletions _emulator/firebase.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion firestore-send-email/functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
2 changes: 1 addition & 1 deletion firestore-send-email/functions/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 560dcd4

Please sign in to comment.