|
| 1 | +# Copyright 2020 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 | + |
| 15 | +name: Release Candidate |
| 16 | + |
| 17 | +on: |
| 18 | + # Only run the workflow when a PR is updated or when a developer explicitly requests |
| 19 | + # a build by sending a 'firebase_build' event. |
| 20 | + pull_request: |
| 21 | + types: [opened, synchronize, closed] |
| 22 | + |
| 23 | + repository_dispatch: |
| 24 | + types: |
| 25 | + - firebase_build |
| 26 | + |
| 27 | +jobs: |
| 28 | + stage_release: |
| 29 | + # To publish a release, merge the release PR with the label 'release:publish'. |
| 30 | + # To stage a release without publishing it, send a 'firebase_build' event or apply |
| 31 | + # the 'release:stage' label to a PR. |
| 32 | + if: github.event.action == 'firebase_build' || |
| 33 | + contains(github.event.pull_request.labels.*.name, 'release:stage') || |
| 34 | + (github.event.pull_request.merged && |
| 35 | + contains(github.event.pull_request.labels.*.name, 'release:publish')) |
| 36 | + |
| 37 | + runs-on: ubuntu-latest |
| 38 | + |
| 39 | + env: |
| 40 | + GOPATH: ${{ github.workspace }}/go |
| 41 | + |
| 42 | + # When manually triggering the build, the requester can specify a target branch or a tag |
| 43 | + # via the 'ref' client parameter. |
| 44 | + steps: |
| 45 | + - name: Check out code into GOPATH |
| 46 | + uses: actions/checkout@v2 |
| 47 | + with: |
| 48 | + path: go/src/firebase.google.com/go |
| 49 | + ref: ${{ github.event.client_payload.ref || github.ref }} |
| 50 | + |
| 51 | + - name: Set up Go |
| 52 | + uses: actions/setup-go@v1 |
| 53 | + with: |
| 54 | + go-version: 1.11 |
| 55 | + |
| 56 | + - name: Get dependencies |
| 57 | + run: go get -t -v $(go list ./... | grep -v integration) |
| 58 | + |
| 59 | + - name: Run Linter |
| 60 | + run: | |
| 61 | + echo |
| 62 | + go get golang.org/x/lint/golint |
| 63 | + $GOPATH/bin/golint -set_exit_status firebase.google.com/go/... |
| 64 | +
|
| 65 | + - name: Run Tests |
| 66 | + working-directory: ./go/src/firebase.google.com/go |
| 67 | + run: ./.github/scripts/run_all_tests.sh |
| 68 | + env: |
| 69 | + FIREBASE_SERVICE_ACCT_KEY: ${{ secrets.FIREBASE_SERVICE_ACCT_KEY }} |
| 70 | + FIREBASE_API_KEY: ${{ secrets.FIREBASE_API_KEY }} |
| 71 | + |
| 72 | + publish_release: |
| 73 | + needs: stage_release |
| 74 | + |
| 75 | + # Check whether the release should be published. We publish only when the trigger PR is |
| 76 | + # 1. merged |
| 77 | + # 2. to the dev branch |
| 78 | + # 3. with the label 'release:publish', and |
| 79 | + # 4. the title prefix '[chore] Release '. |
| 80 | + if: github.event.pull_request.merged && |
| 81 | + github.ref == 'dev' && |
| 82 | + contains(github.event.pull_request.labels.*.name, 'release:publish') && |
| 83 | + startsWith(github.event.pull_request.title, '[chore] Release ') |
| 84 | + |
| 85 | + runs-on: ubuntu-latest |
| 86 | + |
| 87 | + steps: |
| 88 | + - name: Checkout source for publish |
| 89 | + uses: actions/checkout@v2 |
| 90 | + with: |
| 91 | + persist-credentials: false |
| 92 | + |
| 93 | + - name: Publish preflight check |
| 94 | + id: preflight |
| 95 | + run: ./.github/scripts/publish_preflight_check.sh |
| 96 | + |
| 97 | + # We authorize this step with an access token that has write access to the master branch. |
| 98 | + - name: Merge to master |
| 99 | + |
| 100 | + with: |
| 101 | + github-token: ${{ secrets.FIREBASE_GITHUB_TOKEN }} |
| 102 | + script: | |
| 103 | + github.repos.merge({ |
| 104 | + owner: context.repo.owner, |
| 105 | + repo: context.repo.repo, |
| 106 | + base: 'master', |
| 107 | + head: 'dev' |
| 108 | + }) |
| 109 | +
|
| 110 | + # We pull this action from a custom fork of a contributor until |
| 111 | + # https://github.com/actions/create-release/pull/32 is merged. Also note that v1 of |
| 112 | + # this action does not support the "body" parameter. |
| 113 | + - name: Create release tag |
| 114 | + uses: fleskesvor/create-release@1a72e235c178bf2ae6c51a8ae36febc24568c5fe |
| 115 | + env: |
| 116 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 117 | + with: |
| 118 | + tag_name: ${{ steps.preflight.outputs.version }} |
| 119 | + release_name: Firebase Admin Go SDK ${{ steps.preflight.outputs.version }} |
| 120 | + body: ${{ steps.preflight.outputs.changelog }} |
| 121 | + commitish: master |
| 122 | + draft: false |
| 123 | + prerelease: false |
| 124 | + |
| 125 | + # Post to Twitter if explicitly opted-in by adding the label 'release:tweet'. |
| 126 | + - name: Post to Twitter |
| 127 | + if: success() && |
| 128 | + contains(github.event.pull_request.labels.*.name, 'release:tweet') |
| 129 | + uses: firebase/firebase-admin-node/.github/actions/send-tweet@master |
| 130 | + with: |
| 131 | + status: > |
| 132 | + ${{ steps.preflight.outputs.version }} of @Firebase Admin Go SDK is available. |
| 133 | + https://github.com/firebase/firebase-admin-go/releases/tag/${{ steps.preflight.outputs.version }} |
| 134 | + consumer-key: ${{ secrets.FIREBASE_TWITTER_CONSUMER_KEY }} |
| 135 | + consumer-secret: ${{ secrets.FIREBASE_TWITTER_CONSUMER_SECRET }} |
| 136 | + access-token: ${{ secrets.FIREBASE_TWITTER_ACCESS_TOKEN }} |
| 137 | + access-token-secret: ${{ secrets.FIREBASE_TWITTER_ACCESS_TOKEN_SECRET }} |
| 138 | + continue-on-error: true |
0 commit comments