|
| 1 | +name: Deploy |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - master |
| 7 | + paths: |
| 8 | + - 'functions/**' |
| 9 | + - 'scripts/_constants.js' |
| 10 | + - 'scripts/firebase-deploy.js' |
| 11 | + - '*.json' |
| 12 | + |
| 13 | +jobs: |
| 14 | + deploy: |
| 15 | + name: Deploy to Firebase |
| 16 | + runs-on: ubuntu-latest |
| 17 | + if: | |
| 18 | + github.event.head_commit.message != 'Initial commit' && |
| 19 | + !contains(github.event.head_commit.message, '[skip ci]') |
| 20 | +
|
| 21 | + steps: |
| 22 | + - name: Checkout |
| 23 | + uses: actions/checkout@v2 |
| 24 | + |
| 25 | + - name: Setup Node |
| 26 | + uses: actions/setup-node@v2 |
| 27 | + with: |
| 28 | + node-version: '10.x' |
| 29 | + |
| 30 | + - name: Cache dependencies |
| 31 | + uses: actions/cache@v2 |
| 32 | + with: |
| 33 | + path: ~/.npm |
| 34 | + key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} |
| 35 | + restore-keys: | |
| 36 | + ${{ runner.os }}-node- |
| 37 | +
|
| 38 | + - name: Install root dependencies |
| 39 | + run: npm ci --only=production |
| 40 | + |
| 41 | + - name: Install functions dependencies |
| 42 | + run: cd functions && npm ci --only=production --no-optional && cd .. |
| 43 | + env: |
| 44 | + NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 45 | + |
| 46 | + - name: Run deploy |
| 47 | + env: |
| 48 | + FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }} |
| 49 | + FIREBASE_PROJECT_ID: ${{ secrets.FIREBASE_PROJECT_ID }} |
| 50 | + SERVER_OPERATOR_TOKEN: ${{ secrets.SERVER_OPERATOR_TOKEN }} |
| 51 | + run: npm run deploy |
| 52 | + |
| 53 | + update-app-json: |
| 54 | + name: Update application and publish |
| 55 | + runs-on: ubuntu-latest |
| 56 | + needs: deploy |
| 57 | + |
| 58 | + steps: |
| 59 | + - name: Checkout |
| 60 | + uses: actions/checkout@v2 |
| 61 | + |
| 62 | + - name: Write README with base URI |
| 63 | + env: |
| 64 | + FIREBASE_PROJECT_ID: ${{ secrets.FIREBASE_PROJECT_ID }} |
| 65 | + run: | |
| 66 | + echo "App base URI: https://us-central1-$FIREBASE_PROJECT_ID.cloudfunctions.net/app/" \ |
| 67 | + > ./assets/README |
| 68 | +
|
| 69 | + - name: Run Wget and write to JSON file |
| 70 | + env: |
| 71 | + FIREBASE_PROJECT_ID: ${{ secrets.FIREBASE_PROJECT_ID }} |
| 72 | + run: | |
| 73 | + wget -O ./assets/application.json \ |
| 74 | + https://us-central1-$FIREBASE_PROJECT_ID.cloudfunctions.net/app/ |
| 75 | +
|
| 76 | + - name: Config Git and check diff |
| 77 | + run: | |
| 78 | + git config --local user.email '[email protected]' |
| 79 | + git config --local user.name 'GitHub Action' |
| 80 | + git add ./assets/ |
| 81 | + (git diff-index --quiet HEAD && echo "::set-output name=diff::0") || echo "::set-output name=diff::1" |
| 82 | + id: git_diff |
| 83 | + |
| 84 | + - name: Commit local file changes |
| 85 | + if: steps.git_diff.outputs.diff == 1 |
| 86 | + run: | |
| 87 | + git commit -m 'chore(assets): update application body [skip ci]' |
| 88 | +
|
| 89 | + - name: Push changes |
| 90 | + if: steps.git_diff.outputs.diff == 1 |
| 91 | + uses: ad-m/github-push-action@master |
| 92 | + with: |
| 93 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 94 | + branch: master |
| 95 | + |
| 96 | + - name: Check stable package version |
| 97 | + env: |
| 98 | + APP_CHANGED: ${{ steps.git_diff.outputs.diff }} |
| 99 | + run: | |
| 100 | + CAN_PUBLISH=$(node -p "!(/-/.test(require('./package.json').version)) && process.env.APP_CHANGED") |
| 101 | + echo "::set-output name=publish::$CAN_PUBLISH" |
| 102 | + id: pkg_version |
| 103 | + |
| 104 | + - name: Setup Node |
| 105 | + if: steps.pkg_version.outputs.publish == 1 |
| 106 | + uses: actions/setup-node@v2 |
| 107 | + with: |
| 108 | + node-version: '12.x' |
| 109 | + registry-url: 'https://registry.npmjs.org/' |
| 110 | + |
| 111 | + - name: Cache dependencies |
| 112 | + if: steps.pkg_version.outputs.publish == 1 |
| 113 | + uses: actions/cache@v2 |
| 114 | + with: |
| 115 | + path: ~/.npm |
| 116 | + key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} |
| 117 | + restore-keys: | |
| 118 | + ${{ runner.os }}-node- |
| 119 | +
|
| 120 | + - name: Install dependencies |
| 121 | + if: steps.pkg_version.outputs.publish == 1 |
| 122 | + run: npm ci --only=production |
| 123 | + |
| 124 | + - name: Run publish script |
| 125 | + if: steps.pkg_version.outputs.publish == 1 |
| 126 | + env: |
| 127 | + FIREBASE_PROJECT_ID: ${{ secrets.FIREBASE_PROJECT_ID }} |
| 128 | + MARKET_TOKEN: ${{ secrets.MARKET_TOKEN }} |
| 129 | + run: "npm run publish:market" |
| 130 | + continue-on-error: true |
0 commit comments