|
| 1 | +name: E2E |
| 2 | + |
| 3 | +on: [push] |
| 4 | + |
| 5 | +env: |
| 6 | + TZ: UTC |
| 7 | + OC_ENV: ci |
| 8 | + NODE_ENV: test |
| 9 | + WEBSITE_URL: http://localhost:3000 |
| 10 | + IMAGES_URL: http://localhost:3001 |
| 11 | + API_URL: http://localhost:3060 |
| 12 | + API_KEY: dvl-1510egmf4a23d80342403fb599qd |
| 13 | + CI: true |
| 14 | + |
| 15 | + E2E_TEST: 1 |
| 16 | + PGHOST: localhost |
| 17 | + PGUSER: postgres |
| 18 | + CYPRESS_RECORD: false |
| 19 | + CYPRESS_VIDEO: false |
| 20 | + CYPRESS_VIDEO_UPLOAD_ON_PASSES: false |
| 21 | + CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }} |
| 22 | + GITHUB_CLIENT_ID: ${{ secrets.GH_CLIENT_ID }} |
| 23 | + GITHUB_CLIENT_SECRET: ${{ secrets.GH_CLIENT_SECRET }} |
| 24 | + API_FOLDER: /home/runner/work/opencollective-pdf/opencollective-pdf/opencollective-api |
| 25 | + FRONTEND_FOLDER: /home/runner/work/opencollective-pdf/opencollective-pdf/opencollective-frontend |
| 26 | + IMAGES_FOLDER: /home/runner/work/opencollective-pdf/opencollective-pdf/opencollective-images |
| 27 | + PDF_FOLDER: /home/runner/work/opencollective-pdf/opencollective-pdf |
| 28 | + TERM: xterm |
| 29 | + STRIPE_WEBHOOK_KEY: ${{ secrets.STRIPE_WEBHOOK_KEY }} |
| 30 | + STRIPE_WEBHOOK_SIGNING_SECRET: ${{ secrets.STRIPE_WEBHOOK_SIGNING_SECRET }} |
| 31 | + |
| 32 | +jobs: |
| 33 | + e2e: |
| 34 | + runs-on: ubuntu-latest |
| 35 | + timeout-minutes: 30 |
| 36 | + |
| 37 | + strategy: |
| 38 | + matrix: |
| 39 | + files: ['0*.js', '1*.js', '2*.js', '3*.js'] |
| 40 | + |
| 41 | + services: |
| 42 | + redis: |
| 43 | + image: redis |
| 44 | + ports: |
| 45 | + - 6379:6379 |
| 46 | + options: --entrypoint redis-server |
| 47 | + postgres: |
| 48 | + image: postgres:13.9 |
| 49 | + env: |
| 50 | + POSTGRES_USER: postgres |
| 51 | + POSTGRES_DB: postgres |
| 52 | + POSTGRES_HOST_AUTH_METHOD: trust |
| 53 | + ports: |
| 54 | + - 5432:5432 |
| 55 | + # needed because the postgres container does not provide a healthcheck |
| 56 | + options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 |
| 57 | + |
| 58 | + steps: |
| 59 | + - name: Update apt |
| 60 | + run: sudo apt-get update || exit 0 |
| 61 | + |
| 62 | + - name: Install Cypress dependencies |
| 63 | + run: sudo apt-get install --no-install-recommends -y libgtk2.0-0 libgtk-3-0 libnotify-dev libgconf-2-4 libnss3 libxss1 libasound2 libxtst6 xauth xvfb fonts-arphic-bkai00mp fonts-arphic-bsmi00lp fonts-arphic-gbsn00lp fonts-arphic-gkai00mp fonts-arphic-ukai fonts-arphic-uming ttf-wqy-zenhei ttf-wqy-microhei xfonts-wqy |
| 64 | + |
| 65 | + - name: Install postgresql-client |
| 66 | + run: sudo apt-get install -y postgresql-client |
| 67 | + |
| 68 | + - name: Install graphicsmagick |
| 69 | + run: sudo apt-get install -y graphicsmagick |
| 70 | + |
| 71 | + - name: Install stripe-cli |
| 72 | + run: | |
| 73 | + sudo apt-get install -y wget |
| 74 | + wget https://github.com/stripe/stripe-cli/releases/download/v1.13.9/stripe_1.13.9_linux_x86_64.tar.gz -O /tmp/stripe_1.13.9_linux_x86_64.tar.gz |
| 75 | + sudo tar xzvf /tmp/stripe_1.13.9_linux_x86_64.tar.gz -C /bin/ |
| 76 | +
|
| 77 | + - name: Checkout |
| 78 | + uses: actions/checkout@v3 |
| 79 | + |
| 80 | + - name: Setup node |
| 81 | + uses: actions/setup-node@v3 |
| 82 | + with: |
| 83 | + node-version-file: 'package.json' |
| 84 | + |
| 85 | + # Npm cache |
| 86 | + |
| 87 | + - name: Restore .npm cache |
| 88 | + uses: actions/cache@v3 |
| 89 | + with: |
| 90 | + path: ~/.npm |
| 91 | + key: ${{ runner.os }}-npm-cache-${{ github.sha }} |
| 92 | + restore-keys: | |
| 93 | + - ${{ runner.os }}-npm-cache-${{ github.sha }} |
| 94 | + - ${{ runner.os }}-npm-cache- |
| 95 | +
|
| 96 | + # Checkout frontend |
| 97 | + |
| 98 | + - name: Set REF in env, removing the `refs/` part |
| 99 | + run: echo "MATCHING_BRANCH_REF=$(echo $GITHUB_REF | sed 's|refs/||')" >> $GITHUB_ENV |
| 100 | + |
| 101 | + - name: Check matching branch |
| 102 | + id: check-matching-branch-frontend |
| 103 | + |
| 104 | + with: |
| 105 | + route: GET /repos/{owner}/{repo}/git/ref/{ref} |
| 106 | + owner: opencollective |
| 107 | + repo: opencollective-frontend |
| 108 | + ref: ${{ env.MATCHING_BRANCH_REF }} |
| 109 | + env: |
| 110 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 111 | + continue-on-error: true |
| 112 | + |
| 113 | + - name: Checkout (frontend - matching branch) |
| 114 | + if: steps.check-matching-branch-frontend.outputs.status == 200 |
| 115 | + uses: actions/checkout@v3 |
| 116 | + with: |
| 117 | + repository: opencollective/opencollective-frontend |
| 118 | + path: opencollective-frontend |
| 119 | + ref: ${{ github.ref }} |
| 120 | + |
| 121 | + - name: Checkout (frontend - main) |
| 122 | + if: steps.check-matching-branch-frontend.outputs.status != 200 |
| 123 | + uses: actions/checkout@v3 |
| 124 | + with: |
| 125 | + repository: opencollective/opencollective-frontend |
| 126 | + path: opencollective-frontend |
| 127 | + |
| 128 | + # Checkout API |
| 129 | + |
| 130 | + - name: Check matching branch |
| 131 | + id: check-matching-branch-api-api |
| 132 | + |
| 133 | + with: |
| 134 | + route: GET /repos/{owner}/{repo}/git/ref/{ref} |
| 135 | + owner: opencollective |
| 136 | + repo: opencollective-api |
| 137 | + ref: ${{ env.MATCHING_BRANCH_REF }} |
| 138 | + env: |
| 139 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 140 | + continue-on-error: true |
| 141 | + |
| 142 | + - name: Checkout (api - matching branch) |
| 143 | + if: steps.check-matching-branch-api.outputs.status == 200 |
| 144 | + uses: actions/checkout@v3 |
| 145 | + with: |
| 146 | + repository: opencollective/opencollective-api |
| 147 | + path: opencollective-api |
| 148 | + ref: ${{ github.ref }} |
| 149 | + |
| 150 | + - name: Checkout (api - main) |
| 151 | + if: steps.check-matching-branch-api.outputs.status != 200 |
| 152 | + uses: actions/checkout@v3 |
| 153 | + with: |
| 154 | + repository: opencollective/opencollective-api |
| 155 | + path: opencollective-api |
| 156 | + |
| 157 | + # Checkout other services |
| 158 | + |
| 159 | + - name: Checkout (images) |
| 160 | + uses: actions/checkout@v3 |
| 161 | + with: |
| 162 | + repository: opencollective/opencollective-images |
| 163 | + path: opencollective-images |
| 164 | + |
| 165 | + # Prepare API |
| 166 | + |
| 167 | + - name: Restore node_modules (api) |
| 168 | + uses: actions/cache@v3 |
| 169 | + id: api-node-modules |
| 170 | + with: |
| 171 | + path: opencollective-api/node_modules |
| 172 | + key: ${{ runner.os }}-api-node-modules-${{ hashFiles('package-lock.json') }}-${{ secrets.CACHE_VERSION }} |
| 173 | + |
| 174 | + - name: Install dependencies (api) |
| 175 | + working-directory: opencollective-api |
| 176 | + if: steps.api-node-modules.outputs.cache-hit != 'true' |
| 177 | + run: npm ci --prefer-offline --no-audit |
| 178 | + |
| 179 | + - name: Restore build (api) |
| 180 | + uses: actions/cache@v3 |
| 181 | + id: api-build |
| 182 | + with: |
| 183 | + path: opencollective-api/dist |
| 184 | + key: ${{ runner.os }}-api-build-${{ github.sha }} |
| 185 | + |
| 186 | + - name: Build (api) |
| 187 | + if: steps.api-build.outputs.cache-hit != 'true' |
| 188 | + working-directory: opencollective-api |
| 189 | + run: npm run build |
| 190 | + |
| 191 | + # Prepare Frontend |
| 192 | + |
| 193 | + - name: Restore node_modules (frontend) |
| 194 | + uses: actions/cache@v3 |
| 195 | + id: frontend-node-modules |
| 196 | + with: |
| 197 | + path: opencollective-frontend/node_modules |
| 198 | + key: ${{ runner.os }}-frontend-node-modules-${{ hashFiles('opencollective-frontend/package-lock.json') }} |
| 199 | + |
| 200 | + - name: Install dependencies (frontend) |
| 201 | + if: steps.frontend-node-modules.outputs.cache-hit != 'true' |
| 202 | + working-directory: opencollective-frontend |
| 203 | + run: CYPRESS_INSTALL_BINARY=0 npm ci --prefer-offline --no-audit |
| 204 | + |
| 205 | + - name: Set commit hash (frontend) |
| 206 | + working-directory: opencollective-frontend |
| 207 | + run: echo "FRONTEND_COMMIT_HASH=$(git rev-parse HEAD)" >> $GITHUB_ENV |
| 208 | + |
| 209 | + - name: Restore .next build (frontend) |
| 210 | + uses: actions/cache@v3 |
| 211 | + id: next-build |
| 212 | + with: |
| 213 | + path: opencollective-frontend/.next |
| 214 | + key: ${{ runner.os }}-next-build-${{ env.FRONTEND_COMMIT_HASH }} |
| 215 | + |
| 216 | + - name: Restore .next cache (frontend) |
| 217 | + if: steps.next-build.outputs.cache-hit != 'true' |
| 218 | + uses: actions/cache@v3 |
| 219 | + with: |
| 220 | + path: opencollective-frontend/.next/cache |
| 221 | + key: ${{ runner.os }}-next-cache-${{ env.FRONTEND_COMMIT_HASH }} |
| 222 | + restore-keys: | |
| 223 | + ${{ runner.os }}-next-cache-${{ env.FRONTEND_COMMIT_HASH }} |
| 224 | + ${{ runner.os }}-next-cache- |
| 225 | +
|
| 226 | + - name: Build (frontend) |
| 227 | + if: steps.next-build.outputs.cache-hit != 'true' |
| 228 | + working-directory: opencollective-frontend |
| 229 | + run: npm run build |
| 230 | + |
| 231 | + # Prepare Images |
| 232 | + |
| 233 | + - name: Restore node_modules (images) |
| 234 | + uses: actions/cache@v3 |
| 235 | + id: images-node-modules |
| 236 | + with: |
| 237 | + path: opencollective-images/node_modules |
| 238 | + key: ${{ runner.os }}-images-node-modules-${{ hashFiles('opencollective-images/package-lock.json') }} |
| 239 | + |
| 240 | + - name: Install dependencies (images) |
| 241 | + working-directory: opencollective-images |
| 242 | + if: steps.images-node-modules.outputs.cache-hit != 'true' |
| 243 | + run: npm ci --prefer-offline --no-audit |
| 244 | + |
| 245 | + - name: Build (images) |
| 246 | + working-directory: opencollective-images |
| 247 | + run: npm run build |
| 248 | + |
| 249 | + # Setup Cypress |
| 250 | + |
| 251 | + - name: Restore Cypress |
| 252 | + uses: actions/cache@v3 |
| 253 | + id: cypress |
| 254 | + with: |
| 255 | + path: ~/.cache/Cypress |
| 256 | + key: ${{ runner.os }}-cypress-${{ hashFiles('opencollective-frontend/node_modules/cypress/package.json') }} |
| 257 | + |
| 258 | + - name: Install Cypress |
| 259 | + if: steps.cypress.outputs.cache-hit != 'true' |
| 260 | + working-directory: opencollective-frontend |
| 261 | + run: npx cypress install |
| 262 | + |
| 263 | + # Run E2E |
| 264 | + - name: Show current directory |
| 265 | + run: pwd |
| 266 | + - name: Show current directory (2) |
| 267 | + run: ls |
| 268 | + - name: Show current directory (3) |
| 269 | + run: ls .. |
| 270 | + |
| 271 | + - name: Setup DB |
| 272 | + working-directory: opencollective-frontend |
| 273 | + run: ./scripts/setup_db.sh |
| 274 | + |
| 275 | + - name: Run E2E with Cypress |
| 276 | + working-directory: opencollective-frontend |
| 277 | + run: ./scripts/run_e2e_tests.sh |
| 278 | + env: |
| 279 | + CYPRESS_TEST_FILES: ${{ matrix.files }} |
| 280 | + |
| 281 | + - name: Archive test screenshots |
| 282 | + uses: actions/upload-artifact@v3 |
| 283 | + with: |
| 284 | + name: screenshots |
| 285 | + path: opencollective-frontend/test/cypress/screenshots |
| 286 | + if: ${{ failure() }} |
0 commit comments