test: build client once and use in Cypress jobs (#43301)
This commit is contained in:
		
				
					committed by
					
						
						GitHub
					
				
			
			
				
	
			
			
			
						parent
						
							b9d08f2fea
						
					
				
				
					commit
					45a2564dcf
				
			
							
								
								
									
										83
									
								
								.github/workflows/cypress-electron.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										83
									
								
								.github/workflows/cypress-electron.yml
									
									
									
									
										vendored
									
									
								
							@@ -1,83 +0,0 @@
 | 
				
			|||||||
# Mirrors the Cypress workflow with the following changes:
 | 
					 | 
				
			||||||
# - Cypress run has a spec
 | 
					 | 
				
			||||||
# - We create the stats.json file here since the workflow only runs once.
 | 
					 | 
				
			||||||
# - Mailhog is missing since none of the tests use it.
 | 
					 | 
				
			||||||
name: Cypress Electron
 | 
					 | 
				
			||||||
on:
 | 
					 | 
				
			||||||
  push:
 | 
					 | 
				
			||||||
    branches-ignore:
 | 
					 | 
				
			||||||
      - 'renovate/**'
 | 
					 | 
				
			||||||
  pull_request:
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
jobs:
 | 
					 | 
				
			||||||
  cypress-run:
 | 
					 | 
				
			||||||
    name: Test
 | 
					 | 
				
			||||||
    runs-on: ubuntu-18.04
 | 
					 | 
				
			||||||
    strategy:
 | 
					 | 
				
			||||||
      matrix:
 | 
					 | 
				
			||||||
        browsers: [electron]
 | 
					 | 
				
			||||||
        node-version: [14.x]
 | 
					 | 
				
			||||||
    services:
 | 
					 | 
				
			||||||
      mongodb:
 | 
					 | 
				
			||||||
        image: mongo:3.6.19
 | 
					 | 
				
			||||||
        ports:
 | 
					 | 
				
			||||||
          - 27017:27017
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    steps:
 | 
					 | 
				
			||||||
      # We use .npmrc to set the default version to 0, and prevents download during development.
 | 
					 | 
				
			||||||
      # This installs it specifically in the CI runs.
 | 
					 | 
				
			||||||
      - name: Set Action Environment Variables
 | 
					 | 
				
			||||||
        run: |
 | 
					 | 
				
			||||||
          echo "CYPRESS_RECORD_KEY=${{ secrets.CYPRESS_RECORD_KEY }}" >> $GITHUB_ENV
 | 
					 | 
				
			||||||
          echo "GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}" >> $GITHUB_ENV
 | 
					 | 
				
			||||||
          echo "CYPRESS_INSTALL_BINARY=7.7.0" >> $GITHUB_ENV
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      - name: Checkout Source Files
 | 
					 | 
				
			||||||
        uses: actions/checkout@v2
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      - name: Checkout client config
 | 
					 | 
				
			||||||
        uses: actions/checkout@v2
 | 
					 | 
				
			||||||
        with:
 | 
					 | 
				
			||||||
          repository: freeCodeCamp/client-config
 | 
					 | 
				
			||||||
          path: client-config
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      - name: Use Node.js ${{ matrix.node-version }}
 | 
					 | 
				
			||||||
        uses: actions/setup-node@v2
 | 
					 | 
				
			||||||
        with:
 | 
					 | 
				
			||||||
          node-version: ${{ matrix.node-version }}
 | 
					 | 
				
			||||||
          cache: 'npm'
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      - name: Set freeCodeCamp Environment Variables
 | 
					 | 
				
			||||||
        run: cp sample.env .env
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      - name: Install Dependencies
 | 
					 | 
				
			||||||
        run: |
 | 
					 | 
				
			||||||
          npm ci
 | 
					 | 
				
			||||||
          npm run ensure-env
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      - name: Move serve.json to client
 | 
					 | 
				
			||||||
        run: |
 | 
					 | 
				
			||||||
          mkdir -p client/public
 | 
					 | 
				
			||||||
          cp client-config/serve.json client/public/serve.json
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      - name: Seed Database
 | 
					 | 
				
			||||||
        run: npm run seed
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      - name: Cypress run
 | 
					 | 
				
			||||||
        uses: cypress-io/github-action@v2
 | 
					 | 
				
			||||||
        with:
 | 
					 | 
				
			||||||
          record: ${{ env.CYPRESS_RECORD_KEY != 0 }}
 | 
					 | 
				
			||||||
          build: npm run build
 | 
					 | 
				
			||||||
          start: npm run start-ci
 | 
					 | 
				
			||||||
          wait-on: http://localhost:8000
 | 
					 | 
				
			||||||
          wait-on-timeout: 1200
 | 
					 | 
				
			||||||
          config: baseUrl=http://localhost:8000
 | 
					 | 
				
			||||||
          browser: ${{ matrix.browsers }}
 | 
					 | 
				
			||||||
          spec: 'cypress/integration/learn/challenges/projects.js'
 | 
					 | 
				
			||||||
          headless: true
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      - name: Upload Webpack stats
 | 
					 | 
				
			||||||
        uses: actions/upload-artifact@v2
 | 
					 | 
				
			||||||
        with:
 | 
					 | 
				
			||||||
          name: webpack-stats
 | 
					 | 
				
			||||||
          path: client/public/stats.json
 | 
					 | 
				
			||||||
							
								
								
									
										76
									
								
								.github/workflows/cypress.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										76
									
								
								.github/workflows/cypress.yml
									
									
									
									
										vendored
									
									
								
							@@ -6,13 +6,65 @@ on:
 | 
				
			|||||||
  pull_request:
 | 
					  pull_request:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
jobs:
 | 
					jobs:
 | 
				
			||||||
 | 
					  build-client:
 | 
				
			||||||
 | 
					    name: Build
 | 
				
			||||||
 | 
					    runs-on: ubuntu-18.04
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    steps:
 | 
				
			||||||
 | 
					      - name: Checkout Source Files
 | 
				
			||||||
 | 
					        uses: actions/checkout@v2
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      - name: Checkout client-config
 | 
				
			||||||
 | 
					        uses: actions/checkout@v2
 | 
				
			||||||
 | 
					        with:
 | 
				
			||||||
 | 
					          repository: freeCodeCamp/client-config
 | 
				
			||||||
 | 
					          path: client-config
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      - name: Use Node.js 14.x
 | 
				
			||||||
 | 
					        uses: actions/setup-node@v2
 | 
				
			||||||
 | 
					        with:
 | 
				
			||||||
 | 
					          node-version: 14.x
 | 
				
			||||||
 | 
					          cache: 'npm'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      - name: Set freeCodeCamp Environment Variables
 | 
				
			||||||
 | 
					        run: cp sample.env .env
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      - name: Install and Build
 | 
				
			||||||
 | 
					        run: |
 | 
				
			||||||
 | 
					          npm ci
 | 
				
			||||||
 | 
					          npm run build
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      - name: Move serve.json to Public Folder
 | 
				
			||||||
 | 
					        run: cp client-config/serve.json client/public/serve.json
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      # We tar them for performance reasons - uploading a lot of files is slow.
 | 
				
			||||||
 | 
					      - name: Tar Files
 | 
				
			||||||
 | 
					        run: tar -cf client-artifact.tar client/public
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      - name: Upload Client Artifact
 | 
				
			||||||
 | 
					        uses: actions/upload-artifact@v2
 | 
				
			||||||
 | 
					        with:
 | 
				
			||||||
 | 
					          name: client-artifact
 | 
				
			||||||
 | 
					          path: client-artifact.tar
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      - name: Upload Webpack Stats
 | 
				
			||||||
 | 
					        uses: actions/upload-artifact@v2
 | 
				
			||||||
 | 
					        with:
 | 
				
			||||||
 | 
					          name: webpack-stats
 | 
				
			||||||
 | 
					          path: client/public/stats.json
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  cypress-run:
 | 
					  cypress-run:
 | 
				
			||||||
    name: Test
 | 
					    name: Test
 | 
				
			||||||
    runs-on: ubuntu-18.04
 | 
					    runs-on: ubuntu-18.04
 | 
				
			||||||
 | 
					    needs: build-client
 | 
				
			||||||
    strategy:
 | 
					    strategy:
 | 
				
			||||||
      matrix:
 | 
					      matrix:
 | 
				
			||||||
        browsers: [chrome, firefox]
 | 
					        browsers: [chrome, firefox, electron]
 | 
				
			||||||
        node-version: [14.x]
 | 
					        node-version: [14.x]
 | 
				
			||||||
 | 
					        include:
 | 
				
			||||||
 | 
					          - browsers: electron
 | 
				
			||||||
 | 
					            spec: cypress/integration/learn/challenges/projects.js
 | 
				
			||||||
    services:
 | 
					    services:
 | 
				
			||||||
      mongodb:
 | 
					      mongodb:
 | 
				
			||||||
        image: mongo:3.6.19
 | 
					        image: mongo:3.6.19
 | 
				
			||||||
@@ -36,11 +88,14 @@ jobs:
 | 
				
			|||||||
      - name: Checkout Source Files
 | 
					      - name: Checkout Source Files
 | 
				
			||||||
        uses: actions/checkout@v2
 | 
					        uses: actions/checkout@v2
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      - name: Checkout client config
 | 
					      - uses: actions/download-artifact@v2
 | 
				
			||||||
        uses: actions/checkout@v2
 | 
					 | 
				
			||||||
        with:
 | 
					        with:
 | 
				
			||||||
          repository: freeCodeCamp/client-config
 | 
					          name: client-artifact
 | 
				
			||||||
          path: client-config
 | 
					
 | 
				
			||||||
 | 
					      - name: Unpack Client Artifact
 | 
				
			||||||
 | 
					        run: |
 | 
				
			||||||
 | 
					          tar -xf client-artifact.tar
 | 
				
			||||||
 | 
					          rm client-artifact.tar
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      - name: Use Node.js ${{ matrix.node-version }}
 | 
					      - name: Use Node.js ${{ matrix.node-version }}
 | 
				
			||||||
        uses: actions/setup-node@v2
 | 
					        uses: actions/setup-node@v2
 | 
				
			||||||
@@ -51,15 +106,12 @@ jobs:
 | 
				
			|||||||
      - name: Set freeCodeCamp Environment Variables
 | 
					      - name: Set freeCodeCamp Environment Variables
 | 
				
			||||||
        run: cp sample.env .env
 | 
					        run: cp sample.env .env
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      - name: Install Dependencies
 | 
					      - name: Install and Build
 | 
				
			||||||
        run: |
 | 
					        run: |
 | 
				
			||||||
          npm ci
 | 
					          npm ci
 | 
				
			||||||
          npm run ensure-env
 | 
					          npm run ensure-env
 | 
				
			||||||
 | 
					          npm run build:curriculum
 | 
				
			||||||
      - name: Move serve.json to client
 | 
					          npm run build:server
 | 
				
			||||||
        run: |
 | 
					 | 
				
			||||||
          mkdir -p client/public
 | 
					 | 
				
			||||||
          cp client-config/serve.json client/public/serve.json
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
      - name: Seed Database
 | 
					      - name: Seed Database
 | 
				
			||||||
        run: npm run seed
 | 
					        run: npm run seed
 | 
				
			||||||
@@ -68,10 +120,10 @@ jobs:
 | 
				
			|||||||
        uses: cypress-io/github-action@v2
 | 
					        uses: cypress-io/github-action@v2
 | 
				
			||||||
        with:
 | 
					        with:
 | 
				
			||||||
          record: ${{ env.CYPRESS_RECORD_KEY != 0 }}
 | 
					          record: ${{ env.CYPRESS_RECORD_KEY != 0 }}
 | 
				
			||||||
          build: npm run build
 | 
					 | 
				
			||||||
          start: npm run start-ci
 | 
					          start: npm run start-ci
 | 
				
			||||||
          wait-on: http://localhost:8000
 | 
					          wait-on: http://localhost:8000
 | 
				
			||||||
          wait-on-timeout: 1200
 | 
					          wait-on-timeout: 1200
 | 
				
			||||||
          config: baseUrl=http://localhost:8000
 | 
					          config: baseUrl=http://localhost:8000
 | 
				
			||||||
          browser: ${{ matrix.browsers }}
 | 
					          browser: ${{ matrix.browsers }}
 | 
				
			||||||
          headless: true
 | 
					          headless: true
 | 
				
			||||||
 | 
					          spec: ${{ matrix.spec }}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user