|
| 1 | +# Copyright 2023 Google LLC |
| 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: Test Sample |
| 16 | + |
| 17 | +on: |
| 18 | + workflow_call: |
| 19 | + inputs: |
| 20 | + name: |
| 21 | + required: true |
| 22 | + type: string |
| 23 | + path: |
| 24 | + required: true |
| 25 | + type: string |
| 26 | +jobs: |
| 27 | + test: |
| 28 | + runs-on: ubuntu-latest |
| 29 | + timeout-minutes: 60 |
| 30 | + permissions: |
| 31 | + contents: 'write' |
| 32 | + pull-requests: 'write' |
| 33 | + id-token: 'write' |
| 34 | + defaults: |
| 35 | + run: |
| 36 | + working-directory: ${{ inputs.path }} |
| 37 | + steps: |
| 38 | + |
| 39 | + with: |
| 40 | + ref: ${{github.event.pull_request.head.sha}} |
| 41 | + - uses: 'google-github-actions/[email protected]' |
| 42 | + with: |
| 43 | + workload_identity_provider: 'projects/1046198160504/locations/global/workloadIdentityPools/github-actions-pool/providers/github-actions-provider' |
| 44 | + service_account: '[email protected]' |
| 45 | + create_credentials_file: 'true' |
| 46 | + access_token_lifetime: 600s |
| 47 | + |
| 48 | + with: |
| 49 | + node-version: 16 |
| 50 | + - name: Get npm cache directory |
| 51 | + id: npm-cache-dir |
| 52 | + shell: bash |
| 53 | + run: echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT} |
| 54 | + - uses: actions/cache@v3 |
| 55 | + id: npm-cache |
| 56 | + with: |
| 57 | + path: ${{ steps.npm-cache-dir.outputs.dir }} |
| 58 | + key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} |
| 59 | + restore-keys: | |
| 60 | + ${{ runner.os }}-node- |
| 61 | + - name: install repo dependencies |
| 62 | + run: npm install |
| 63 | + working-directory: . |
| 64 | + - name: install directory dependencies |
| 65 | + run: npm install |
| 66 | + - run: npm run build |
| 67 | + - name: set env vars for scheduled run |
| 68 | + if: github.event.action == 'schedule' |
| 69 | + run: | |
| 70 | + echo "MOCHA_REPORTER_SUITENAME=${{ inputs.name }}" >> $GITHUB_ENV |
| 71 | + echo "MOCHA_REPORTER_OUTPUT=${{github.run_id}}_sponge_log.xml" >> $GITHUB_ENV |
| 72 | + echo "MOCHA_REPORTER=xunit" >> $GITHUB_ENV |
| 73 | + - run: npm test |
| 74 | + - name: upload test results for FlakyBot workflow |
| 75 | + if: github.event.action == 'schedule' && always() |
| 76 | + uses: actions/upload-artifact@v3 |
| 77 | + with: |
| 78 | + name: test-results |
| 79 | + path: ${{ inputs.path }}/${{ env.MOCHA_REPORTER_OUTPUT }} |
| 80 | + retention-days: 1 |
0 commit comments