|
| 1 | +name: Test |
| 2 | + |
| 3 | +on: [push] |
| 4 | + |
| 5 | +jobs: |
| 6 | + # |
| 7 | + # dependencies job |
| 8 | + # |
| 9 | + dependencies: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + |
| 12 | + steps: |
| 13 | + - uses: actions/checkout@v2 |
| 14 | + - name: Use Node.js 12.x |
| 15 | + uses: actions/setup-node@v2 |
| 16 | + with: |
| 17 | + node-version: '12.x' |
| 18 | + always-auth: true |
| 19 | + registry-url: https://registry.npmjs.org |
| 20 | + - id: cache_npm |
| 21 | + name: Cache Node.js modules |
| 22 | + uses: actions/cache@v2 |
| 23 | + with: |
| 24 | + path: | |
| 25 | + ~/.npm |
| 26 | + ./node_modules.tar.zstd |
| 27 | + key: ${{ runner.OS }}-npm-${{ hashFiles('**/package-lock.json') }} |
| 28 | + restore-keys: | |
| 29 | + ${{ runner.OS }}-npm- |
| 30 | + ${{ runner.OS }}- |
| 31 | + - name: Install dependencies with NPM |
| 32 | + if: steps.cache_npm.outputs.cache-hit != 'true' |
| 33 | + run: npm ci |
| 34 | + env: |
| 35 | + NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} |
| 36 | + - name: Archive node_modules |
| 37 | + if: steps.cache_npm.outputs.cache-hit != 'true' |
| 38 | + run: tar --use-compress-program "zstd -T0 --long=31 -1" -cf node_modules.tar.zstd -P node_modules |
| 39 | + - name: Persisting node_modules artifact |
| 40 | + uses: actions/upload-artifact@v2 |
| 41 | + with: |
| 42 | + name: node_modules.tar.zstd |
| 43 | + path: node_modules.tar.zstd |
| 44 | + |
| 45 | + # |
| 46 | + # lint job |
| 47 | + # |
| 48 | + lint: |
| 49 | + runs-on: ubuntu-latest |
| 50 | + needs: [dependencies] |
| 51 | + |
| 52 | + steps: |
| 53 | + # Setup |
| 54 | + - uses: actions/checkout@v2 |
| 55 | + - name: Use Node.js 12.x |
| 56 | + uses: actions/setup-node@v2 |
| 57 | + with: |
| 58 | + node-version: '12.x' |
| 59 | + always-auth: true |
| 60 | + registry-url: https://registry.npmjs.org |
| 61 | + - name: Restore node_modules artifact |
| 62 | + uses: actions/download-artifact@v2 |
| 63 | + with: |
| 64 | + name: node_modules.tar.zstd |
| 65 | + - name: Unarchive node_modules |
| 66 | + run: tar --use-compress-program "zstd -d --long=31" -xf node_modules.tar.zstd |
| 67 | + # ESLint |
| 68 | + - name: Lint source code |
| 69 | + run: npm run lint |
| 70 | + |
| 71 | + # |
| 72 | + # build job |
| 73 | + # |
| 74 | + build: |
| 75 | + runs-on: ubuntu-latest |
| 76 | + needs: [dependencies] |
| 77 | + |
| 78 | + steps: |
| 79 | + # Setup |
| 80 | + - uses: actions/checkout@v2 |
| 81 | + - name: Use Node.js 12.x |
| 82 | + uses: actions/setup-node@v2 |
| 83 | + with: |
| 84 | + node-version: '12.x' |
| 85 | + always-auth: true |
| 86 | + registry-url: https://registry.npmjs.org |
| 87 | + - name: Restore node_modules artifact |
| 88 | + uses: actions/download-artifact@v2 |
| 89 | + with: |
| 90 | + name: node_modules.tar.zstd |
| 91 | + - name: Unarchive node_modules |
| 92 | + run: tar --use-compress-program "zstd -d --long=31" -xf node_modules.tar.zstd |
| 93 | + # Build |
| 94 | + - name: Build application |
| 95 | + run: npm run build |
| 96 | + env: |
| 97 | + CI: true |
| 98 | + - name: Check build worked correctly |
| 99 | + run: | |
| 100 | + if [ ! -f ./dist/index.js ]; then |
| 101 | + echo "Something went wrong: no ./dist/index.js file was built!" |
| 102 | + exit 1 |
| 103 | + else |
| 104 | + echo "Build appears to be successful: ./dist/index.js was created" |
| 105 | + fi |
| 106 | +
|
| 107 | + # |
| 108 | + # test job |
| 109 | + # |
| 110 | + test: |
| 111 | + runs-on: ubuntu-latest |
| 112 | + needs: [build, lint] |
| 113 | + |
| 114 | + steps: |
| 115 | + # Setup |
| 116 | + - uses: actions/checkout@v2 |
| 117 | + - name: Restore node_modules artifact |
| 118 | + uses: actions/download-artifact@v2 |
| 119 | + with: |
| 120 | + name: node_modules.tar.zstd |
| 121 | + - name: Unarchive node_modules |
| 122 | + run: tar --use-compress-program "zstd -d --long=31" -xf node_modules.tar.zstd |
| 123 | + # Tests |
| 124 | + - name: Run project tests |
| 125 | + run: node_modules/.bin/dotenv -e .env.ci -- npm run test:ci |
| 126 | + env: |
| 127 | + CI: true |
| 128 | + - if: always() |
| 129 | + name: Persisting test-results.html artifact |
| 130 | + uses: actions/upload-artifact@v2 |
| 131 | + with: |
| 132 | + name: test-results.html |
| 133 | + path: test/.results/test-results.html |
0 commit comments