From c5a900f019abe83ea3b03d5a7b0f8743db106f38 Mon Sep 17 00:00:00 2001 From: Rob Brackett Date: Mon, 27 Jan 2025 09:58:19 -0800 Subject: [PATCH] Merge client PR check and deploy workflows These workflows are pretty redundant (they do the same thing except one deploys at the end and run in response to different events). That duplication makes it easy for things to get out of sync and make mistakes. This merges the two workflows into one, and makes the deploy step conditional, so it only runs on pushes to `main`, whereas the rest also run on pull requests. --- ...loy_frontend_main.yml => build-client.yml} | 90 +++++++++++++++---- .github/workflows/pr_frontend.yml | 65 -------------- 2 files changed, 75 insertions(+), 80 deletions(-) rename .github/workflows/{deploy_frontend_main.yml => build-client.yml} (53%) delete mode 100644 .github/workflows/pr_frontend.yml diff --git a/.github/workflows/deploy_frontend_main.yml b/.github/workflows/build-client.yml similarity index 53% rename from .github/workflows/deploy_frontend_main.yml rename to .github/workflows/build-client.yml index bd20b49f..8282d027 100644 --- a/.github/workflows/deploy_frontend_main.yml +++ b/.github/workflows/build-client.yml @@ -1,4 +1,4 @@ -name: Deploy Frontend Main +name: Build Client on: push: @@ -6,27 +6,31 @@ on: paths: - ".github/workflows/deploy_frontend_main.yml" - "client/**/*" + pull_request: + paths: + - ".github/workflows/deploy_frontend_main.yml" + - "client/**/*" concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true +env: + node-version: 18 + jobs: build: runs-on: ubuntu-latest defaults: run: working-directory: client - strategy: - matrix: - node-version: [18.x] steps: - uses: actions/checkout@v4 - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v2 + - name: Use Node.js ${{ env.node-version }} + uses: actions/setup-node@v4 with: - node-version: ${{ matrix.node-version }} + node-version: ${{ env.node-version }} - name: Install run: npm ci @@ -43,15 +47,53 @@ jobs: - name: Get directory contents run: ls -la public + - name: Upload static files as artifact + id: deployment + uses: actions/upload-pages-artifact@v3 + with: + path: ./client/public + + test: + runs-on: ubuntu-latest + defaults: + run: + working-directory: client + steps: + - uses: actions/checkout@v4 + + - name: Use Node.js ${{ env.node-version }} + uses: actions/setup-node@v4 + with: + node-version: ${{ env.node-version }} + + - name: Install + run: npm ci + + - name: Unit tests + run: npm test + + lint: + runs-on: ubuntu-latest + defaults: + run: + working-directory: client + steps: + - uses: actions/checkout@v4 + + - name: Use Node.js ${{ env.node-version }} + uses: actions/setup-node@v4 + with: + node-version: ${{ env.node-version }} + + - name: Install + run: npm ci + - name: Lint run: npm run lint - name: License Check run: npm run licenses - - name: Test - run: npm test - # TODO: This was disabled in the original DOI repo. Much of the code here # is pretty out of date, so it is nowhere near passing a security audit, # but it would be good to fix that and re-enable this. @@ -59,15 +101,33 @@ jobs: # - name: Check for security vulnerabilities # run: npm audit --production - - name: Upload static files as artifact - id: deployment - uses: actions/upload-pages-artifact@v3 + translations: + runs-on: ubuntu-latest + defaults: + run: + working-directory: client + steps: + - uses: actions/checkout@v4 + + - name: Use Node.js ${{ env.node-version }} + uses: actions/setup-node@v4 with: - path: ./client/public + node-version: ${{ env.node-version }} + + - name: Install + run: npm ci + + - name: Spanish translation test + run: npm run test:intl-translations deploy: + if: github.ref == 'refs/heads/main' runs-on: ubuntu-latest - needs: build + needs: + - build + - test + - lint + - translations permissions: pages: write id-token: write diff --git a/.github/workflows/pr_frontend.yml b/.github/workflows/pr_frontend.yml deleted file mode 100644 index e8b40e64..00000000 --- a/.github/workflows/pr_frontend.yml +++ /dev/null @@ -1,65 +0,0 @@ -name: Pull Request Frontend -on: - pull_request: -concurrency: - group: ${{ github.workflow }}-${{ github.event.pull_request.number }} - cancel-in-progress: true -env: - node-version: 18.x -jobs: - # JOB to run change detection - detect-fe-changes: - name: Detect frontend changes - runs-on: ubuntu-latest - # Required permissions - permissions: - pull-requests: read - # Set job outputs to values from filter step - outputs: - frontend: ${{ steps.filter.outputs.frontend }} - steps: - # For pull requests it's not necessary to checkout the code - - uses: dorny/paths-filter@v3 - id: filter - with: - filters: | - frontend: - - 'client/**' - - '.github/workflows/pr_frontend.yml' - frontend-build: - name: Frontend build - needs: detect-fe-changes - if: ${{ needs.detect-fe-changes.outputs.frontend == 'true' }} - runs-on: ubuntu-latest - environment: PR - defaults: - run: - working-directory: client - steps: - - uses: actions/checkout@v4 - - name: Use Node.js ${{ env.node-version }} - uses: actions/setup-node@v2 - with: - node-version: ${{ env.node-version }} - - name: Install - run: npm ci - - name: Build - run: npm run build --if-present - env: - # See the client readme for more info on environment variables: - # https://github.com/usds/justice40-tool/blob/main/client/README.md - DATA_SOURCE: cdn - # TODO: Update main URL when either is back up - SITE_URL: "${{ secrets.SITE_URL }}" - - name: Get directory contents - run: ls -la public - - name: Lint - run: npm run lint - - name: License Check - run: npm run licenses - - name: Unit tests - run: npm test - - name: Spanish translation test - run: npm run test:intl-translations - # - name: Check for security vulnerabilities - # run: npm audit --production