diff --git a/.github/workflows/node.yml b/.github/workflows/node.yml new file mode 100644 index 00000000..afe0b13d --- /dev/null +++ b/.github/workflows/node.yml @@ -0,0 +1,38 @@ +name: CI Tests + +on: + - pull_request + - push + +env: + CI: true + +jobs: + unit: + runs-on: ubuntu-latest + strategy: + matrix: + node-version: + - 8.x + - 10.x + steps: + - uses: actions/checkout@v1 + - uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + + - name: Cache npm + uses: actions/cache@v1 + with: + path: ~/.npm + key: ${{ runner.os }}-node-${{ matrix.node-version }}-${{ hashFiles('**/package-lock.json') }} + + - run: npm install + + - name: "Set up Cloud credentials" + run: echo ${{ secrets.service_account_json_base64 }} | base64 -d > ./scripts/service-account.json + + - name: "Lint and Test" + env: + FIREBASE_TOKEN: ${{ secrets.firebase_token }} + run: ./scripts/test.sh \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index d4b948da..00000000 --- a/.travis.yml +++ /dev/null @@ -1,7 +0,0 @@ -language: node_js -node_js: - - "8" -install: - - npm install -script: - - ./scripts/test.sh diff --git a/README.md b/README.md index b5448610..ff43fd38 100644 --- a/README.md +++ b/README.md @@ -9,4 +9,6 @@ We love contributions! See [CONTRIBUTING.md](./CONTRIBUTING.md) for guidelines. ## Build Status -[![Build Status](https://travis-ci.org/firebase/snippets-node.svg?branch=master)](https://travis-ci.org/firebase/snippets-node) \ No newline at end of file +[![Actions Status][gh-actions-badge]][gh-actions] +[gh-actions]: https://github.com/firebase/snippets-node/actions +[gh-actions-badge]: https://github.com/firebase/snippets-node/workflows/CI%20Tests/badge.svg \ No newline at end of file diff --git a/firestore/main/index.js b/firestore/main/index.js index 586570d0..c2992479 100644 --- a/firestore/main/index.js +++ b/firestore/main/index.js @@ -1062,12 +1062,9 @@ function deleteQueryBatch(db, query, batchSize, resolve, reject) { // ============================================================================ describe('Firestore Smoketests', () => { - let db; - before(() => { - admin.initializeApp(); - db = admin.firestore(); - }); + admin.initializeApp(); + const db = admin.firestore(); it('should get an empty document', () => { return getDocumentEmpty(db); diff --git a/scripts/set-credentials.sh b/scripts/set-credentials.sh new file mode 100755 index 00000000..65f40cad --- /dev/null +++ b/scripts/set-credentials.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash +set -e + +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" + +if [[ -z $CI ]]; then + echo "CI is unset, assuming local testing." +else + echo "CI=${CI}, setting GOOGLE_APPLICATION_CREDENTIALS" + export GOOGLE_APPLICATION_CREDENTIALS="${DIR}/service-account.json" +fi + +echo "Application Default Credentials: ${GOOGLE_APPLICATION_CREDENTIALS}" \ No newline at end of file diff --git a/scripts/test.sh b/scripts/test.sh index ee019f47..e8420122 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -1,5 +1,7 @@ set -e +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" + # 0) Bootstrap echo "Bootstrapping..." npm run lerna-bootstrap @@ -9,4 +11,5 @@ echo "Linting..." npm run lint # 2) Run tests in emulator -npx firebase --project="test-snippets-node" emulators:exec --only firestore "npm run lerna-test" \ No newline at end of file +source ${DIR}/set-credentials.sh +npx firebase --project="firestore-snippets" emulators:exec --only firestore "npm run lerna-test"