|
| 1 | +on: |
| 2 | + push: |
| 3 | + branches: [master, production] |
| 4 | + pull_request: |
| 5 | + branches: [master, production] |
| 6 | + |
| 7 | +jobs: |
| 8 | + test: |
| 9 | + runs-on: ubuntu-latest |
| 10 | + steps: |
| 11 | + - uses: actions/checkout@v2 |
| 12 | + - name: Set up Node.js 14 |
| 13 | + uses: actions/setup-node@v1 |
| 14 | + with: |
| 15 | + node-version: 14.x |
| 16 | + - name: Install dependencies |
| 17 | + run: | |
| 18 | + npm install |
| 19 | + - name: Setup codeclimate test coverage reporter |
| 20 | + run: | |
| 21 | + curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter |
| 22 | + chmod +x ./cc-test-reporter |
| 23 | + ./cc-test-reporter before-build |
| 24 | + - name: Run linter |
| 25 | + run: | |
| 26 | + npm run lint |
| 27 | + - name: Run tests |
| 28 | + run: | |
| 29 | + npm run test -- --coverage |
| 30 | + - name: Report test coverage |
| 31 | + env: |
| 32 | + CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }} |
| 33 | + run: | |
| 34 | + ./cc-test-reporter after-build --exit-code 0 |
| 35 | +
|
| 36 | + build: |
| 37 | + runs-on: ubuntu-latest |
| 38 | + steps: |
| 39 | + - uses: actions/checkout@v2 |
| 40 | + - name: Set up Node.js ${{ env.NODE_VERSION }} |
| 41 | + uses: actions/setup-node@v1 |
| 42 | + with: |
| 43 | + node-version: ${{ env.NODE_VERSION }} |
| 44 | + - name: Install dependencies |
| 45 | + run: | |
| 46 | + npm install |
| 47 | + - name: Create an optimized build |
| 48 | + env: |
| 49 | + IS_PROD: ${{ github.ref == 'refs/heads/production' }} |
| 50 | + run: | |
| 51 | + if $IS_PROD; then cat .env.prod > .env; else cat .env.staging > .env; fi |
| 52 | + npm run build |
| 53 | + - name: Archive the build artifacts |
| 54 | + uses: actions/upload-artifact@v2 |
| 55 | + if: ${{ github.ref == 'refs/heads/production' || github.ref == 'refs/heads/staging' }} |
| 56 | + with: |
| 57 | + name: build-artifacts |
| 58 | + path: build |
| 59 | + |
| 60 | + gcs-deploy: |
| 61 | + needs: [test, build] |
| 62 | + runs-on: ubuntu-latest |
| 63 | + if: ${{ github.ref == 'refs/heads/production' || github.ref == 'refs/heads/staging' }} |
| 64 | + steps: |
| 65 | + - uses: actions/checkout@v2 |
| 66 | + - name: Download build artifacts |
| 67 | + uses: actions/download-artifact@v2 |
| 68 | + with: |
| 69 | + name: build-artifacts |
| 70 | + path: build |
| 71 | + - name: Set up Cloud SDK |
| 72 | + uses: google-github-actions/setup-gcloud@master |
| 73 | + with: |
| 74 | + project_id: ${{ github.ref == 'refs/heads/production' && 'cidc-dfci' || 'cidc-dfci-staging' }} |
| 75 | + service_account_key: ${{ github.ref == 'refs/heads/production' && secrets.GCP_SA_KEY_PROD || secrets.GCP_SA_KEY_STAGING }} |
| 76 | + export_default_credentials: true |
| 77 | + - name: Deploy build artifacts to Cloud Storage |
| 78 | + env: |
| 79 | + BUCKET: ${{ github.ref == 'refs/heads/production' && 'gs://cidc-ui-prod' || 'gs://cidc-ui-staging'}} |
| 80 | + run: | |
| 81 | + # Copy the contents of the build directory to the GCS UI bucket |
| 82 | + gsutil -m -h 'Cache-Control:no-cache,max-age=0' cp -r build/* $BUCKET |
| 83 | + # Make all objects in the GCS UI bucket public |
| 84 | + gsutil iam ch allUsers:objectViewer $BUCKET |
0 commit comments