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 23, 2024
1 parent a902301 commit dbd4d85
Show file tree
Hide file tree
Showing 7 changed files with 345 additions and 32 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
Loading

0 comments on commit dbd4d85

Please sign in to comment.