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 1fcbc02
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 31 deletions.
73 changes: 50 additions & 23 deletions .github/workflows/conditional-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,51 +12,78 @@ 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="["
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
# Loop through each directory and check if there have been any changes
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: cd ${{ matrix.extension }}/functions && npm install
- run: cd ${{ matrix.extension }}/functions && npm run build
- run: node scripts/changeFirebaseJson.cjs ${{ matrix.extension }}
- name: Start Firebase Emulator
run: cd _emulator && firebase emulators:start &
- run:
cd ${{ matrix.extension }}/functions && npm run testIfEmulatorRunning
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
6 changes: 3 additions & 3 deletions firestore-send-email/functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
"build:watch": "npm run clean && tsc --watch",
"clean": "rimraf lib",
"compile": "tsc",
"local:emulator": "cd ../../_emulator && firebase emulators:start -P demo-test",
"test": "cd ../../_emulator && firebase emulators:exec --only extensions jest -P demo-test",
"local:emulator": "cd ../../_emulator && ./emulator_wrapper.sh",
"test": "cd ../../_emulator && firebase emulators:exec 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 || exit 0\" \"npm run testIfEmulatorRunning\"",
"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
48 changes: 48 additions & 0 deletions scripts/changeFirebaseJson.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const fs = require('fs');
const path = require('path');

// get extensionName from args
// e.g node scripts/changeFirebaseJson.cjs firestore-send-email
const extensionName = process.argv[2];


const filePath = path.join(__dirname,'_emulator','firebase.json'); // Adjust the path as necessary

fs.readFile(filePath, { encoding: 'utf8' }, (err, data) => {
if (err) {
console.error('Error reading file:', err);
return;
}

// Parse the JSON data
let config = JSON.parse(data);

const extensionsFields = {
"firestore-send-email": {
"firestore-send-email": "../firestore-send-email",
"firestore-send-email-sendgrid": "../firestore-send-email"
},
"delete-user-data": {
"delete-user-data": "../delete-user-data"
},
}



// Update the extensions field
config.extensions = {
[extensionName]: extensionsFields[extensionName]
};

// Convert the modified config back to a JSON string
const updatedJson = JSON.stringify(config, null, 2); // Including null and 2 for pretty-printing

// Write the JSON string back to the file
fs.writeFile(filePath, updatedJson, (err) => {
if (err) {
console.error('Error writing file:', err);
} else {
console.log('firebase.json has been updated successfully!');
}
});
});

0 comments on commit 1fcbc02

Please sign in to comment.