Skip to content

Commit 6edbb95

Browse files
authored
Automatically run integration test on PR merge (#1182)
Setup Github Workflow to automatically run integration test on commits to master branch. The test can be triggered manually by visiting https://github.com/firebase/firebase-functions/actions/workflows/postmerge.yaml. You can also manually trigger the test via: ``` GCLOUD_PROJECT=<my project> npm run test:postmerge ``` Make sure your test project has all necessary resources enambled (i.e. enable Firestore, Storage, RTDB, Auth, etc.) Only one test can run at a time, so I've enforced/disabled concurrency on the workflow.
1 parent 1877e98 commit 6edbb95

File tree

3 files changed

+64
-28
lines changed

3 files changed

+64
-28
lines changed

.github/workflows/postmerge.yaml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Copyright 2022 Google Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
name: Post-merge tests
15+
16+
on:
17+
workflow_dispatch:
18+
workflow_run:
19+
workflows: ['CI Tests']
20+
types: [completed]
21+
branches: [master]
22+
23+
concurrency:
24+
group: postmerge-${{ github.ref }}
25+
cancel-in-progress: true
26+
27+
env:
28+
CI: true
29+
30+
jobs:
31+
postmerge:
32+
runs-on: ubuntu-latest
33+
steps:
34+
- uses: actions/checkout@v3
35+
- uses: actions/setup-node@v3
36+
with:
37+
node-version: 16
38+
39+
- uses: google-github-actions/auth@v0
40+
with:
41+
credentials_json: '${{ secrets.CF3_INTEGRATION_TEST_GOOGLE_CREDENTIALS }}'
42+
create_credentials_file: true
43+
44+
- name: 'Set up Cloud SDK'
45+
uses: google-github-actions/setup-gcloud@v0
46+
47+
- name: 'Setup Firebase CLI'
48+
run: npm i -g firebase-tools
49+
50+
- name: 'Run integration test'
51+
run: npm run test:postmerge
52+
53+
- name: Print debug logs
54+
if: failure()
55+
run: find . -type f -name "*debug.log" | xargs cat

integration_test/run_tests.sh

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,14 @@
33
# Exit immediately if a command exits with a non-zero status.
44
set -e
55

6-
function usage {
7-
echo "Usage: ${0} <project_id> [<token>]"
8-
exit 1
9-
}
6+
PROJECT_ID="${GCLOUD_PROJECT}"
7+
TIMESTAMP=$(date +%s)
108

11-
# This script takes in one required argument specifying a project_id and an
12-
# optional arguement for a CI token that can be obtained by running
13-
# `firebase login:ci`
14-
# Example usage (from root dir) without token:
15-
# ./integration_test/run_tests.sh chenky-test-proj
16-
# Example usage (from root dir) with token:
17-
# ./integration_test/run_tests.sh chenky-test-proj $TOKEN
18-
if [[ "${1}" == "" ]]; then
19-
usage
9+
if [[ "${PROJECT_ID}" == "" ]]; then
10+
echo "process.env.GCLOUD_PROJECT cannot be empty"
11+
exit 1
2012
fi
2113

22-
PROJECT_ID="${1}"
23-
TIMESTAMP=$(date +%s)
24-
TOKEN="${2}"
25-
2614
# Directory where this script lives.
2715
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
2816

@@ -64,22 +52,14 @@ function delete_all_functions {
6452
cd "${DIR}"
6553
# Try to delete, if there are errors it is because the project is already empty,
6654
# in that case do nothing.
67-
if [[ "${TOKEN}" == "" ]]; then
68-
firebase functions:delete integrationTests v1 v2 --force --project=$PROJECT_ID || : &
69-
else
70-
firebase functions:delete integrationTests v1 v2 --force --project=$PROJECT_ID --token=$TOKEN || : &
71-
fi
55+
firebase functions:delete integrationTests v1 v2 --force --project=$PROJECT_ID || : &
7256
wait
7357
announce "Project emptied."
7458
}
7559

7660
function deploy {
7761
# Deploy functions, and security rules for database and Firestore. If the deploy fails, retry twice
78-
if [[ "${TOKEN}" == "" ]]; then
79-
for i in 1 2 3; do firebase deploy --project="${PROJECT_ID}" --only functions,database,firestore && break; done
80-
else
81-
for i in 1 2 3; do firebase deploy --project="${PROJECT_ID}" --token="${TOKEN}" --only functions,database,firestore && break; done
82-
fi
62+
for i in 1 2; do firebase deploy --project="${PROJECT_ID}" --only functions,database,firestore && break; done
8363
}
8464

8565
function run_tests {

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,8 @@
178178
"lint": "tslint --config tslint.json --project tsconfig.json ",
179179
"lint:fix": "tslint --config tslint.json --fix --project tsconfig.json",
180180
"test": "mocha --file ./mocha/setup.ts \"spec/**/*.spec.ts\"",
181-
"test:bin": "./scripts/bin-test/run.sh"
181+
"test:bin": "./scripts/bin-test/run.sh",
182+
"test:postmerge": "./integration_test/run_tests.sh"
182183
},
183184
"dependencies": {
184185
"@types/cors": "^2.8.5",

0 commit comments

Comments
 (0)