From 43c7e77f89a7ab03dc8d1d09c6de33b4cf6e8603 Mon Sep 17 00:00:00 2001 From: Hiranya Jayathilaka Date: Thu, 16 Jan 2020 11:12:12 -0800 Subject: [PATCH 1/8] chore: Removed Travis CI integration (#326) --- .github/workflows/ci.yml | 6 +++--- .travis.gofmt.sh | 6 ------ .travis.yml | 27 --------------------------- README.md | 4 ++-- 4 files changed, 5 insertions(+), 38 deletions(-) delete mode 100755 .travis.gofmt.sh delete mode 100644 .travis.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 37149aec..c40ae862 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,4 +1,4 @@ -name: Go Continuous Integration +name: Continuous Integration on: [push, pull_request] jobs: @@ -22,7 +22,7 @@ jobs: uses: actions/checkout@v2 with: path: go/src/firebase.google.com/go - + - name: Get dependencies run: go get -t -v $(go list ./... | grep -v integration) @@ -43,7 +43,7 @@ jobs: echo "Go code is not formatted:" gofmt -d -s . exit 1 - fi + fi - name: Run Static Analyzer run: go vet -v firebase.google.com/go/... diff --git a/.travis.gofmt.sh b/.travis.gofmt.sh deleted file mode 100755 index e33451d7..00000000 --- a/.travis.gofmt.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash -if [[ ! -z "$(gofmt -l -s .)" ]]; then - echo "Go code is not formatted:" - gofmt -d -s . - exit 1 -fi diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index a4290f13..00000000 --- a/.travis.yml +++ /dev/null @@ -1,27 +0,0 @@ -language: go - -go: - - "1.11.x" - - "1.12.x" - - "1.13.x" - - master - -matrix: - # Build OK if fails on unstable development versions of Go. - allow_failures: - - go: master - # Don't wait for tests to finish on allow_failures. - # Mark the build finished if tests pass on other versions of Go. - fast_finish: true - -go_import_path: firebase.google.com/go - -install: - - go get golang.org/x/lint/golint - - go get -t -v $(go list ./... | grep -v integration) - -script: - - golint -set_exit_status $(go list ./...) - - if [[ "$TRAVIS_GO_VERSION" =~ ^1\.11\.([0-9]+|x)$ ]]; then ./.travis.gofmt.sh; fi - - go test -v -race -test.short ./... # Run tests with the race detector. - - go vet -v ./... # Run Go static analyzer. diff --git a/README.md b/README.md index 4b0e87b8..899a88d4 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![Build Status](https://travis-ci.org/firebase/firebase-admin-go.svg?branch=master)](https://travis-ci.org/firebase/firebase-admin-go) +[![Build Status](https://github.com/firebase/firebase-admin-go/workflows/Continuous%20Integration/badge.svg)](https://github.com/firebase/firebase-admin-go/actions) [![GoDoc](https://godoc.org/firebase.google.com/go?status.svg)](https://godoc.org/firebase.google.com/go) [![Go Report Card](https://goreportcard.com/badge/github.com/firebase/firebase-admin-go)](https://goreportcard.com/report/github.com/firebase/firebase-admin-go) @@ -42,7 +42,7 @@ requests, code review feedback, and also pull requests. ## Supported Go Versions We support Go v1.11 and higher. -[Continuous integration](https://travis-ci.org/firebase/firebase-admin-go) system +[Continuous integration](https://github.com/firebase/firebase-admin-go/actions) system tests the code on Go v1.11 through v1.13. ## Documentation From aa4e7a42c1f55a3c756fc70d0ef6d885c14e8b40 Mon Sep 17 00:00:00 2001 From: Hiranya Jayathilaka Date: Wed, 19 Feb 2020 13:10:06 -0800 Subject: [PATCH 2/8] chore: Added Actions-based release workflow (#331) * chore: Added Actions-based release workflow * Set GOPATH * Fixed working directory for tests * Decrypting credentials into the testdata directory * Added preflight and post check scripts --- .../resources/integ-service-account.json.gpg | Bin 0 -> 1730 bytes .github/scripts/generate_changelog.sh | 79 +++++++++++++ .github/scripts/publish_post_check.sh | 105 ++++++++++++++++++ .github/scripts/publish_preflight_check.sh | 97 ++++++++++++++++ .github/scripts/run_all_tests.sh | 25 +++++ .github/workflows/ci.yml | 2 +- .github/workflows/publish.yml | 64 +++++++++++ .github/workflows/stage.yml | 74 ++++++++++++ 8 files changed, 445 insertions(+), 1 deletion(-) create mode 100644 .github/resources/integ-service-account.json.gpg create mode 100755 .github/scripts/generate_changelog.sh create mode 100755 .github/scripts/publish_post_check.sh create mode 100755 .github/scripts/publish_preflight_check.sh create mode 100755 .github/scripts/run_all_tests.sh create mode 100644 .github/workflows/publish.yml create mode 100644 .github/workflows/stage.yml diff --git a/.github/resources/integ-service-account.json.gpg b/.github/resources/integ-service-account.json.gpg new file mode 100644 index 0000000000000000000000000000000000000000..145389e0e839675ef92e2712638f3d39dc030fb0 GIT binary patch literal 1730 zcmV;z20i(V4Fm}T0?6uq1v?nDCI8au0gw$8IMvg~=Xcz9UM=*NZ5RCsFH>eO?p z`a^EFF$25U3A=Oe?N{hlAYsHIn1<-8dZs!_SjOD zNc0><*irbMG5XMAmkxEg7Vq=0eMf__RhX2*c>b%81@)u`1gZMPQ zGKW`slEt)@cq-#;Eka6FiLO2c17RPvwoe_$O7(KK55Ff^Y`gYK`IqN1^#GzsAzAJ= z2iDr$?bAYi^{Gd`W)N9aE82E}*GEJlD6Ne!1RN^h|GY+|I?_TzBrmGNd3k|BCt=0+ zlq$1BYyQT)E`HaX^j&P|2@!^L|L&AB=Lf3#hL**Mv%2jw}VoJ1h*g?JA6|73=1pI1!mf43=2 zb%CDko(ScSX&(QBwwJ#&0r2Z3yYpYQ#-@G3e0UUcdCF!@XBNWXu60L$0p+B zKGg9onju-)=jcEDq)n52gLbLRwjRV214Vkq>K)yt_%R!86j(%WjUkm}Z zkld=xUJ}5pRVi0DDM65R?RzmS0v4PdgPj2M!b?qkZeH2kblF4TE5-> z+wx^D+a8D9wMjvx4~3%w==`~DNy)e&VRq>gnoi~d3iv0n9CQwklD^ngCt&HclPN;sYPq-!;(NBWa-ANlB1|rWZQxe7e9&%C!t66F|w!x@^9{lBd zm@=95Fb+n~I{Gu3ck*o*973|Z*l`yJ&93|4`QmqDBP}U6XB)cr6-2&7LXU_`bGFyk z$Y)%4T^<`}!M7))ymrZhN^Q57bN)#fV)M1RDq1%H?Fta$qSF9MyS!B5`8nVdJ51rQPEAZ^O?zsM}O zPhp<9H7#qk*1~nY?Kwyy63(aXTuneshSsSuy&}{cmv3>jcURN+wzjMPjZ|=n$dPnu z3pt(#iEFy1Xy0d@+7OFlqfp{;Fb4x(T2gG= zxu=dWI=75#Cn`d2=HA$qYRp{goK~aRQ`g;(YjSYZc(^(j8n&X~78N1#$D!&gS(uVy zTk&c$0>XvD4+B$~g!xb<3yDfSCiPguMZ9Q}3jwv`{5kx)_{JLg1FHR6&o*QSe6RzF z4GnVbVJgjce+fXr>&#Wqkv)y#R2IFNldAdS%NJm;I{0nCTqEAhTe=%Tt z<4JG}+xXl(>w*ZIV`zr}LJNUbi)+LMRpFZE@Qk0%|Ag_xvgt)NC z%K0pcz3{!a01i+|RU%UUOua$O*?k5)SMr^Ww2)NKENK7-4bml?WYi~(Wm#GVOSk*k z?|?mdMfkR3z-u?0Ep@}-*86k*+PM7w71x@zPV)}3(x|hmy#3B z;;&>t_G6>4eDTRLb+rsozx@J<8Y`Etwhw&i0PZz#$84|6_7N*%xz*%dvH$=8 literal 0 HcmV?d00001 diff --git a/.github/scripts/generate_changelog.sh b/.github/scripts/generate_changelog.sh new file mode 100755 index 00000000..e393f40e --- /dev/null +++ b/.github/scripts/generate_changelog.sh @@ -0,0 +1,79 @@ +#!/bin/bash + +# Copyright 2020 Google Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -e +set -u + +function printChangelog() { + local TITLE=$1 + shift + # Skip the sentinel value. + local ENTRIES=("${@:2}") + if [ ${#ENTRIES[@]} -ne 0 ]; then + echo "### ${TITLE}" + echo "" + for ((i = 0; i < ${#ENTRIES[@]}; i++)) + do + echo "* ${ENTRIES[$i]}" + done + echo "" + fi +} + +if [[ -z "${GITHUB_SHA}" ]]; then + GITHUB_SHA="HEAD" +fi + +LAST_TAG=`git describe --tags $(git rev-list --tags --max-count=1) 2> /dev/null` || true +if [[ -z "${LAST_TAG}" ]]; then + echo "[INFO] No tags found. Including all commits up to ${GITHUB_SHA}." + VERSION_RANGE="${GITHUB_SHA}" +else + echo "[INFO] Last release tag: ${LAST_TAG}." + COMMIT_SHA=`git show-ref -s ${LAST_TAG}` + echo "[INFO] Last release commit: ${COMMIT_SHA}." + VERSION_RANGE="${COMMIT_SHA}..${GITHUB_SHA}" + echo "[INFO] Including all commits in the range ${VERSION_RANGE}." +fi + +echo "" + +# Older versions of Bash (< 4.4) treat empty arrays as unbound variables, which triggers +# errors when referencing them. Therefore we initialize each of these arrays with an empty +# sentinel value, and later skip them. +CHANGES=("") +FIXES=("") +FEATS=("") +MISC=("") + +while read -r line +do + COMMIT_MSG=`echo ${line} | cut -d ' ' -f 2-` + if [[ $COMMIT_MSG =~ ^change(\(.*\))?: ]]; then + CHANGES+=("$COMMIT_MSG") + elif [[ $COMMIT_MSG =~ ^fix(\(.*\))?: ]]; then + FIXES+=("$COMMIT_MSG") + elif [[ $COMMIT_MSG =~ ^feat(\(.*\))?: ]]; then + FEATS+=("$COMMIT_MSG") + else + MISC+=("${COMMIT_MSG}") + fi +done < <(git log ${VERSION_RANGE} --oneline) + +printChangelog "Breaking Changes" "${CHANGES[@]}" +printChangelog "New Features" "${FEATS[@]}" +printChangelog "Bug Fixes" "${FIXES[@]}" +printChangelog "Miscellaneous" "${MISC[@]}" diff --git a/.github/scripts/publish_post_check.sh b/.github/scripts/publish_post_check.sh new file mode 100755 index 00000000..8311ec25 --- /dev/null +++ b/.github/scripts/publish_post_check.sh @@ -0,0 +1,105 @@ + +#!/bin/bash + +# Copyright 2020 Google Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +###################################### Outputs ##################################### + +# 1. version: The version of this release including the 'v' prefix (e.g. v1.2.3). +# 2. changelog: Formatted changelog text for this release. + +#################################################################################### + +set -e +set -u + +function echo_info() { + local MESSAGE=$1 + echo "[INFO] ${MESSAGE}" +} + +function echo_warn() { + local MESSAGE=$1 + echo "[WARN] ${MESSAGE}" +} + +function terminate() { + echo "" + echo_warn "--------------------------------------------" + echo_warn "POST CHECK FAILED" + echo_warn "--------------------------------------------" + exit 1 +} + + +echo_info "Starting publish post check..." +echo_info "Git revision : ${GITHUB_SHA}" +echo_info "Git ref : ${GITHUB_REF}" +echo_info "Workflow triggered by : ${GITHUB_ACTOR}" +echo_info "GitHub event : ${GITHUB_EVENT_NAME}" + + +echo_info "" +echo_info "--------------------------------------------" +echo_info "Extracting release version" +echo_info "--------------------------------------------" +echo_info "" + +echo_info "Loading version from: firebase.go" + +readonly RELEASE_VERSION=`grep "const Version" firebase.go | awk '{print $4}' | tr -d \"` || true +if [[ -z "${RELEASE_VERSION}" ]]; then + echo_warn "Failed to extract release version from: firebase.go" + terminate +fi + +if [[ ! "${RELEASE_VERSION}" =~ ^([0-9]*)\.([0-9]*)\.([0-9]*)$ ]]; then + echo_warn "Malformed release version string: ${RELEASE_VERSION}. Exiting." + terminate +fi + +echo_info "Extracted release version: ${RELEASE_VERSION}" +echo "::set-output name=version::v${RELEASE_VERSION}" + + +echo_info "" +echo_info "--------------------------------------------" +echo_info "Generating changelog" +echo_info "--------------------------------------------" +echo_info "" + +echo_info "---< git fetch origin master --prune --unshallow >---" +git fetch origin master --prune --unshallow +echo "" + +echo_info "Generating changelog from history..." +readonly CURRENT_DIR=$(dirname "$0") +readonly CHANGELOG=`${CURRENT_DIR}/generate_changelog.sh` +echo "$CHANGELOG" + +# Parse and preformat the text to handle multi-line output. +# See https://github.community/t5/GitHub-Actions/set-output-Truncates-Multiline-Strings/td-p/37870 +FILTERED_CHANGELOG=`echo "$CHANGELOG" | grep -v "\\[INFO\\]"` +FILTERED_CHANGELOG="${FILTERED_CHANGELOG//'%'/'%25'}" +FILTERED_CHANGELOG="${FILTERED_CHANGELOG//$'\n'/'%0A'}" +FILTERED_CHANGELOG="${FILTERED_CHANGELOG//$'\r'/'%0D'}" +echo "::set-output name=changelog::${FILTERED_CHANGELOG}" + + +echo "" +echo_info "--------------------------------------------" +echo_info "POST CHECK SUCCESSFUL" +echo_info "--------------------------------------------" diff --git a/.github/scripts/publish_preflight_check.sh b/.github/scripts/publish_preflight_check.sh new file mode 100755 index 00000000..9dad71bb --- /dev/null +++ b/.github/scripts/publish_preflight_check.sh @@ -0,0 +1,97 @@ +#!/bin/bash + +# Copyright 2020 Google Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +set -e +set -u + +function echo_info() { + local MESSAGE=$1 + echo "[INFO] ${MESSAGE}" +} + +function echo_warn() { + local MESSAGE=$1 + echo "[WARN] ${MESSAGE}" +} + +function terminate() { + echo "" + echo_warn "--------------------------------------------" + echo_warn "PREFLIGHT FAILED" + echo_warn "--------------------------------------------" + exit 1 +} + + +echo_info "Starting publish preflight check..." +echo_info "Git revision : ${GITHUB_SHA}" +echo_info "Git ref : ${GITHUB_REF}" +echo_info "Workflow triggered by : ${GITHUB_ACTOR}" +echo_info "GitHub event : ${GITHUB_EVENT_NAME}" + + +echo_info "" +echo_info "--------------------------------------------" +echo_info "Extracting release version" +echo_info "--------------------------------------------" +echo_info "" + +echo_info "Loading version from: firebase.go" + +readonly RELEASE_VERSION=`grep "const Version" firebase.go | awk '{print $4}' | tr -d \"` || true +if [[ -z "${RELEASE_VERSION}" ]]; then + echo_warn "Failed to extract release version from: firebase.go" + terminate +fi + +if [[ ! "${RELEASE_VERSION}" =~ ^([0-9]*)\.([0-9]*)\.([0-9]*)$ ]]; then + echo_warn "Malformed release version string: ${RELEASE_VERSION}. Exiting." + terminate +fi + +echo_info "Extracted release version: ${RELEASE_VERSION}" + + +echo_info "" +echo_info "--------------------------------------------" +echo_info "Checking release tag" +echo_info "--------------------------------------------" +echo_info "" + +echo_info "---< git fetch --depth=1 origin +refs/tags/*:refs/tags/* >---" +git fetch --depth=1 origin +refs/tags/*:refs/tags/* +echo "" + +readonly EXISTING_TAG=`git rev-parse -q --verify "refs/tags/v${RELEASE_VERSION}"` || true +if [[ -n "${EXISTING_TAG}" ]]; then + echo_warn "Tag v${RELEASE_VERSION} already exists. Exiting." + echo_warn "If the tag was created in a previous unsuccessful attempt, delete it and try again." + echo_warn " $ git tag -d v${RELEASE_VERSION}" + echo_warn " $ git push --delete origin v${RELEASE_VERSION}" + + readonly RELEASE_URL="https://github.com/firebase/firebase-admin-go/releases/tag/v${RELEASE_VERSION}" + echo_warn "Delete any corresponding releases at ${RELEASE_URL}." + terminate +fi + +echo_info "Tag v${RELEASE_VERSION} does not exist." + + +echo "" +echo_info "--------------------------------------------" +echo_info "PREFLIGHT SUCCESSFUL" +echo_info "--------------------------------------------" diff --git a/.github/scripts/run_all_tests.sh b/.github/scripts/run_all_tests.sh new file mode 100755 index 00000000..b52b283c --- /dev/null +++ b/.github/scripts/run_all_tests.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +# Copyright 2020 Google Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -e +set -u + +gpg --quiet --batch --yes --decrypt --passphrase="${FIREBASE_SERVICE_ACCT_KEY}" \ + --output testdata/integration_cert.json .github/resources/integ-service-account.json.gpg + +echo "${FIREBASE_API_KEY}" > testdata/integration_apikey.txt + +go test -v -race firebase.google.com/go/... diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c40ae862..3f20d5c5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,5 +1,5 @@ name: Continuous Integration -on: [push, pull_request] +on: push jobs: build: diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 00000000..26609cab --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,64 @@ +# Copyright 2020 Google Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +name: Publish Release + +on: + # Only run the workflow when a PR is merged to the master branch. + pull_request: + branches: master + types: closed + +jobs: + publish_release: + if: github.event.pull_request.merged + + runs-on: ubuntu-latest + + steps: + - name: Checkout source + uses: actions/checkout@v2 + + - name: Publish post check + id: postcheck + run: ./.github/scripts/publish_post_check.sh + + # We pull this action from a custom fork of a contributor until + # https://github.com/actions/create-release/pull/32 is merged. Also note that v1 of + # this action does not support the "body" parameter. + - name: Create release tag + uses: fleskesvor/create-release@1a72e235c178bf2ae6c51a8ae36febc24568c5fe + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ steps.postcheck.outputs.version }} + release_name: Firebase Admin Go SDK ${{ steps.postcheck.outputs.version }} + body: ${{ steps.postcheck.outputs.changelog }} + draft: false + prerelease: false + + # Post to Twitter if explicitly opted-in by adding the label 'release:tweet'. + - name: Post to Twitter + if: success() && + contains(github.event.pull_request.labels.*.name, 'release:tweet') + uses: firebase/firebase-admin-node/.github/actions/send-tweet@master + with: + status: > + ${{ steps.postcheck.outputs.version }} of @Firebase Admin Go SDK is avaialble. + https://github.com/firebase/firebase-admin-go/releases/tag/${{ steps.postcheck.outputs.version }} + consumer-key: ${{ secrets.FIREBASE_TWITTER_CONSUMER_KEY }} + consumer-secret: ${{ secrets.FIREBASE_TWITTER_CONSUMER_SECRET }} + access-token: ${{ secrets.FIREBASE_TWITTER_ACCESS_TOKEN }} + access-token-secret: ${{ secrets.FIREBASE_TWITTER_ACCESS_TOKEN_SECRET }} + continue-on-error: true diff --git a/.github/workflows/stage.yml b/.github/workflows/stage.yml new file mode 100644 index 00000000..39ff581a --- /dev/null +++ b/.github/workflows/stage.yml @@ -0,0 +1,74 @@ +# Copyright 2020 Google Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +name: Stage Release + +on: + # Only run the workflow when a PR is updated or when a developer explicitly requests + # a build by sending a 'firebase_build' event. + pull_request: + types: [opened, synchronize] + + repository_dispatch: + types: + - firebase_build + +jobs: + stage_release: + # To stage a release without publishing it, send a 'firebase_build' event or apply + # the 'release:stage' label to a PR. PRs targetting the master branch are always + # staged. + if: github.event.action == 'firebase_build' || + contains(github.event.pull_request.labels.*.name, 'release:stage') || + github.event.pull_request.base.ref == 'master' + + runs-on: ubuntu-latest + + env: + GOPATH: ${{ github.workspace }}/go + + # When manually triggering the build, the requester can specify a target branch or a tag + # via the 'ref' client parameter. + steps: + - name: Check out code into GOPATH + uses: actions/checkout@v2 + with: + path: go/src/firebase.google.com/go + ref: ${{ github.event.client_payload.ref || github.ref }} + + - name: Set up Go + uses: actions/setup-go@v1 + with: + go-version: 1.11 + + - name: Get dependencies + run: go get -t -v $(go list ./... | grep -v integration) + + - name: Run Linter + run: | + echo + go get golang.org/x/lint/golint + $GOPATH/bin/golint -set_exit_status firebase.google.com/go/... + + - name: Run Tests + working-directory: ./go/src/firebase.google.com/go + run: ./.github/scripts/run_all_tests.sh + env: + FIREBASE_SERVICE_ACCT_KEY: ${{ secrets.FIREBASE_SERVICE_ACCT_KEY }} + FIREBASE_API_KEY: ${{ secrets.FIREBASE_API_KEY }} + + # If triggered by a PR against the master branch, run additional checks. + - name: Publish preflight check + if: github.event.pull_request.base.ref == 'master' + run: ./.github/scripts/publish_preflight_check.sh From 0e690ec7fac075eb73efffe5d4944c42df7aad9c Mon Sep 17 00:00:00 2001 From: Hiranya Jayathilaka Date: Tue, 25 Feb 2020 13:38:06 -0800 Subject: [PATCH 3/8] chore: Running CI workflow on pull_request (#338) --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3f20d5c5..fb8f93ba 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,5 +1,5 @@ name: Continuous Integration -on: push +on: pull_request jobs: build: From 7c2199d6fa879ee2dd15623652071f45a294dc4b Mon Sep 17 00:00:00 2001 From: Rueian Date: Wed, 26 Feb 2020 05:41:28 +0800 Subject: [PATCH 4/8] fix(fcm): correct the iidEndpoint endpoints used for topic management (#335) According to the document https://developers.google.com/instance-id/reference/server, the endpoints should be: https://iid.googleapis.com/iid/v1:batchAdd https://iid.googleapis.com/iid/v1:batchRemove NOT: https://iid.googleapis.com/iid/v1/:batchAdd https://iid.googleapis.com/iid/v1/:batchRemove --- messaging/topic_mgt.go | 6 +++--- messaging/topic_mgt_test.go | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/messaging/topic_mgt.go b/messaging/topic_mgt.go index 8ae170a5..6252cdb5 100644 --- a/messaging/topic_mgt.go +++ b/messaging/topic_mgt.go @@ -26,8 +26,8 @@ import ( const ( iidEndpoint = "https://iid.googleapis.com/iid/v1" - iidSubscribe = ":batchAdd" - iidUnsubscribe = ":batchRemove" + iidSubscribe = "batchAdd" + iidUnsubscribe = "batchRemove" ) var iidErrorCodes = map[string]struct{ Code, Msg string }{ @@ -164,7 +164,7 @@ func (c *iidClient) makeTopicManagementRequest(ctx context.Context, req *iidRequ request := &internal.Request{ Method: http.MethodPost, - URL: fmt.Sprintf("%s/%s", c.iidEndpoint, req.op), + URL: fmt.Sprintf("%s:%s", c.iidEndpoint, req.op), Body: internal.NewJSONEntity(req), } var result iidResponse diff --git a/messaging/topic_mgt_test.go b/messaging/topic_mgt_test.go index 00be6755..68a82a2d 100644 --- a/messaging/topic_mgt_test.go +++ b/messaging/topic_mgt_test.go @@ -41,7 +41,7 @@ func TestSubscribe(t *testing.T) { if err != nil { t.Fatal(err) } - client.iidEndpoint = ts.URL + client.iidEndpoint = ts.URL + "/v1" resp, err := client.SubscribeToTopic(ctx, []string{"id1", "id2"}, "test-topic") if err != nil { @@ -84,7 +84,7 @@ func TestUnsubscribe(t *testing.T) { if err != nil { t.Fatal(err) } - client.iidEndpoint = ts.URL + client.iidEndpoint = ts.URL + "/v1" resp, err := client.UnsubscribeFromTopic(ctx, []string{"id1", "id2"}, "test-topic") if err != nil { @@ -125,7 +125,7 @@ func TestTopicManagementError(t *testing.T) { if err != nil { t.Fatal(err) } - client.iidEndpoint = ts.URL + client.iidEndpoint = ts.URL + "/v1" client.iidClient.httpClient.RetryConfig = nil cases := []struct { @@ -185,7 +185,7 @@ func checkIIDRequest(t *testing.T, b []byte, tr *http.Request, op string) { if tr.Method != http.MethodPost { t.Errorf("Method = %q; want = %q", tr.Method, http.MethodPost) } - wantOp := "/" + op + wantOp := "/v1:" + op if tr.URL.Path != wantOp { t.Errorf("Path = %q; want = %q", tr.URL.Path, wantOp) } From cdf28fbcc6b795d8d60504b11c1e300c0684d2e8 Mon Sep 17 00:00:00 2001 From: 178inaba <178inaba.git@gmail.com> Date: Tue, 10 Mar 2020 05:16:53 +0900 Subject: [PATCH 5/8] fix(fcm): Fix documents of FCM batch request limit (#347) Co-authored-by: Hiranya Jayathilaka --- messaging/messaging_batch.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/messaging/messaging_batch.go b/messaging/messaging_batch.go index 9ada0f0e..cb4e848a 100644 --- a/messaging/messaging_batch.go +++ b/messaging/messaging_batch.go @@ -38,7 +38,7 @@ const multipartBoundary = "__END_OF_PART__" // Messaging (FCM). // // It contains payload information as well as the list of device registration tokens to which the -// message should be sent. A single MulticastMessage may contain up to 100 registration tokens. +// message should be sent. A single MulticastMessage may contain up to 500 registration tokens. type MulticastMessage struct { Tokens []string Data map[string]string @@ -89,7 +89,7 @@ type BatchResponse struct { // SendAll sends the messages in the given array via Firebase Cloud Messaging. // -// The messages array may contain up to 100 messages. SendAll employs batching to send the entire +// The messages array may contain up to 500 messages. SendAll employs batching to send the entire // array of mssages as a single RPC call. Compared to the `Send()` function, // this is a significantly more efficient way to send multiple messages. The responses list // obtained from the return value corresponds to the order of the input messages. An error from @@ -105,7 +105,7 @@ func (c *fcmClient) SendAll(ctx context.Context, messages []*Message) (*BatchRes // This function does not actually deliver any messages to target devices. Instead, it performs all // the SDK-level and backend validations on the messages, and emulates the send operation. // -// The messages array may contain up to 100 messages. SendAllDryRun employs batching to send the +// The messages array may contain up to 500 messages. SendAllDryRun employs batching to send the // entire array of mssages as a single RPC call. Compared to the `SendDryRun()` function, this // is a significantly more efficient way to validate sending multiple messages. The responses list // obtained from the return value corresponds to the order of the input messages. An error from @@ -117,7 +117,7 @@ func (c *fcmClient) SendAllDryRun(ctx context.Context, messages []*Message) (*Ba // SendMulticast sends the given multicast message to all the FCM registration tokens specified. // -// The tokens array in MulticastMessage may contain up to 100 tokens. SendMulticast uses the +// The tokens array in MulticastMessage may contain up to 500 tokens. SendMulticast uses the // `SendAll()` function to send the given message to all the target recipients. The // responses list obtained from the return value corresponds to the order of the input tokens. An // error from SendMulticast indicates a total failure -- i.e. the message could not be sent to any @@ -137,7 +137,7 @@ func (c *fcmClient) SendMulticast(ctx context.Context, message *MulticastMessage // This function does not actually deliver any messages to target devices. Instead, it performs all // the SDK-level and backend validations on the messages, and emulates the send operation. // -// The tokens array in MulticastMessage may contain up to 100 tokens. SendMulticastDryRun uses the +// The tokens array in MulticastMessage may contain up to 500 tokens. SendMulticastDryRun uses the // `SendAllDryRun()` function to send the given message. The responses list obtained from // the return value corresponds to the order of the input tokens. An error from SendMulticastDryRun // indicates a total failure -- i.e. none of the messages were sent to FCM for validation. Partial From 500fe176628cd6f6f17e093f2463994743a569fd Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 31 Mar 2020 15:39:33 -0400 Subject: [PATCH 6/8] Snippets for new Auth features --- snippets/auth.go | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/snippets/auth.go b/snippets/auth.go index a1a87eaa..c4f1d56e 100644 --- a/snippets/auth.go +++ b/snippets/auth.go @@ -185,6 +185,17 @@ func getUserByPhone(ctx context.Context, client *auth.Client) *auth.UserRecord { return u } +func getUserByProviderId(ctx context.Context, client *auth.Client) *auth.UserRecord { + // [START get_user_by_federated_id] + u, err := client.GetUserByProviderID(ctx, "google.com", "google_uid1234") + if err != nil { + log.Fatalf("error getting user by provider ID %s: %v\n", phone, err) + } + log.Printf("Successfully fetched user data: %v\n", u) + // [END get_user_by_federated_id] + return u +} + func createUser(ctx context.Context, client *auth.Client) *auth.UserRecord { // [START create_user_golang] params := (&auth.UserToCreate{}). @@ -239,6 +250,32 @@ func updateUser(ctx context.Context, client *auth.Client) { // [END update_user_golang] } +func updateUserLinkFederated(ctx context.Context, client *auth.Client) { + // [START update_user_link_federated] + // Link the user with a federated identity provider (like Google). + params := (&auth.UserToUpdate{}). + ProviderToLink(&auth.UserProvider{ProviderID: "google.com", UID: "google_uid1234"}) + u, err := client.UpdateUser(ctx, uid, params) + if err != nil { + log.Fatalf("error updating user: %v\n", err) + } + log.Printf("Successfully updated user: %v\n", u) + // [END update_user_link_federated] +} + +func updateUserUnlinkFederated(ctx context.Context, client *auth.Client) { + // [START update_user_unlink_federated] + // Unlink the user from a federated identity provider (like Google). + params := (&auth.UserToUpdate{}). + ProvidersToDelete([]string{"google.com"}) + u, err := client.UpdateUser(ctx, uid, params) + if err != nil { + log.Fatalf("error updating user: %v\n", err) + } + log.Printf("Successfully updated user: %v\n", u) + // [END update_user_unlink_federated] +} + func deleteUser(ctx context.Context, client *auth.Client) { uid := "d" // [START delete_user_golang] From aa48650c75385598932eabb79e47a73953c6de58 Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 31 Mar 2020 15:41:27 -0400 Subject: [PATCH 7/8] Whitespace --- snippets/auth.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snippets/auth.go b/snippets/auth.go index c4f1d56e..952de893 100644 --- a/snippets/auth.go +++ b/snippets/auth.go @@ -252,7 +252,7 @@ func updateUser(ctx context.Context, client *auth.Client) { func updateUserLinkFederated(ctx context.Context, client *auth.Client) { // [START update_user_link_federated] - // Link the user with a federated identity provider (like Google). + // Link the user with a federated identity provider (like Google). params := (&auth.UserToUpdate{}). ProviderToLink(&auth.UserProvider{ProviderID: "google.com", UID: "google_uid1234"}) u, err := client.UpdateUser(ctx, uid, params) From 3c2400c8999933c3fb8898cb64ed4b9626b47098 Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 2 Apr 2020 11:45:34 -0400 Subject: [PATCH 8/8] Review comments --- snippets/auth.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/snippets/auth.go b/snippets/auth.go index 952de893..e7cde1fd 100644 --- a/snippets/auth.go +++ b/snippets/auth.go @@ -189,7 +189,7 @@ func getUserByProviderId(ctx context.Context, client *auth.Client) *auth.UserRec // [START get_user_by_federated_id] u, err := client.GetUserByProviderID(ctx, "google.com", "google_uid1234") if err != nil { - log.Fatalf("error getting user by provider ID %s: %v\n", phone, err) + log.Fatalf("error getting user by provider ID: %v\n", err) } log.Printf("Successfully fetched user data: %v\n", u) // [END get_user_by_federated_id] @@ -251,6 +251,7 @@ func updateUser(ctx context.Context, client *auth.Client) { } func updateUserLinkFederated(ctx context.Context, client *auth.Client) { + uid := "someuid1234" // [START update_user_link_federated] // Link the user with a federated identity provider (like Google). params := (&auth.UserToUpdate{}). @@ -264,6 +265,7 @@ func updateUserLinkFederated(ctx context.Context, client *auth.Client) { } func updateUserUnlinkFederated(ctx context.Context, client *auth.Client) { + uid := "someuid1234" // [START update_user_unlink_federated] // Unlink the user from a federated identity provider (like Google). params := (&auth.UserToUpdate{}).