|
| 1 | +--- |
| 2 | +name: tests |
| 3 | + |
| 4 | +on: |
| 5 | + pull_request: |
| 6 | + push: |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | +concurrency: |
| 10 | + group: dashboard-${{ github.ref }} |
| 11 | + cancel-in-progress: true |
| 12 | + |
| 13 | +jobs: |
| 14 | + tests: |
| 15 | + name: Run Tests |
| 16 | + runs-on: ubuntu-latest |
| 17 | + |
| 18 | + steps: |
| 19 | + - name: checkout |
| 20 | + uses: actions/checkout@v2 |
| 21 | + |
| 22 | + - uses: actions/setup-node@v2 |
| 23 | + with: |
| 24 | + node-version: "12.22.0" |
| 25 | + cache: "npm" |
| 26 | + - name: Install dependencies |
| 27 | + run: npm install |
| 28 | + |
| 29 | + - name: Run Tests |
| 30 | + if: github.event_name != 'pull_request' |
| 31 | + continue-on-error: true |
| 32 | + id: run-tests |
| 33 | + run: npm test -- --coverage --watchAll=false > /tmp/coverage_report |
| 34 | + |
| 35 | + - name: Post Test Coverage Report in PR |
| 36 | + uses: ArtiomTr/jest-coverage-report-action@v2 |
| 37 | + continue-on-error: true |
| 38 | + if: github.event_name == 'pull_request' |
| 39 | + with: |
| 40 | + test-script: npm run test |
| 41 | + annotations: all |
| 42 | + |
| 43 | + - name: Gain access to test-reports bucket |
| 44 | + if: (steps.run-tests.outcome == 'failure' || steps.run-tests.outcome == 'success') && github.ref == 'refs/heads/develop' |
| 45 | + uses: google-github-actions/setup-gcloud@master |
| 46 | + with: |
| 47 | + project_id: "netdata-cloud-testing" |
| 48 | + service_account_key: ${{ secrets.TEST_AUTOMATION_SERVICE_ACCOUNT }} |
| 49 | + export_default_credentials: true |
| 50 | + |
| 51 | + - name: Upload report to test-reports bucket |
| 52 | + if: (steps.run-tests.outcome == 'failure' || steps.run-tests.outcome == 'success') && github.ref == 'refs/heads/develop' |
| 53 | + run: | |
| 54 | + gsutil -h "Cache-Control: max-age=0, no-store" cp /tmp/coverage_report gs://${{ secrets.TEST_AUTOMATION_STORAGE_BUCKET }}/${{ github.event.repository.name }}/coverage_report |
| 55 | + gsutil acl set project-private gs://${{ secrets.TEST_AUTOMATION_STORAGE_BUCKET }}/${{ github.event.repository.name }}/coverage_report |
| 56 | +
|
| 57 | + - name: Publish test coverage report |
| 58 | + if: (steps.run-tests.outcome == 'failure' || steps.run-tests.outcome == 'success') && github.ref == 'refs/heads/develop' |
| 59 | + uses: aurelien-baudet/workflow-dispatch@v2 |
| 60 | + with: |
| 61 | + repo: netdata/cloud-workflows |
| 62 | + ref: refs/heads/main |
| 63 | + workflow: test_coverage_publisher.yml |
| 64 | + token: ${{ secrets.TEST_AUTOMATION_TOKEN }} |
| 65 | + inputs: '{ "service-name": "${{ github.event.repository.name }}"}' |
0 commit comments