|
| 1 | +# |
| 2 | +# This workflow will run unit tests, smoke e2e tests and attempt to publish package to NPM. |
| 3 | +# |
| 4 | + |
| 5 | +name: Test and publish to NPM |
| 6 | +on: |
| 7 | + push: {} |
| 8 | + pull_request: {} |
| 9 | + workflow_dispatch: {} |
| 10 | +jobs: |
| 11 | + common-unit-tests: |
| 12 | + runs-on: ubuntu-latest |
| 13 | + timeout-minutes: 10 |
| 14 | + strategy: |
| 15 | + matrix: |
| 16 | + node: [18] |
| 17 | + steps: |
| 18 | + - name: Set up NodeJS |
| 19 | + uses: actions/setup-node@v4 |
| 20 | + with: |
| 21 | + node-version: ${{ matrix.node }} |
| 22 | + - name: Git checkout |
| 23 | + uses: actions/checkout@v4 |
| 24 | + - name: NPM ci, build, & test |
| 25 | + run: | |
| 26 | + npm ci |
| 27 | + npm run build --if-present |
| 28 | + npm run coverage |
| 29 | + cd templates/project-ts |
| 30 | + npm install || true |
| 31 | + npm run test |
| 32 | + env: |
| 33 | + CI: true |
| 34 | + - name: Upload coverage reports to Codecov |
| 35 | + uses: codecov/codecov-action@v4 |
| 36 | + with: |
| 37 | + token: ${{ secrets.CODECOV_TOKEN }} |
| 38 | + files: ./coverage/lcov.info |
| 39 | + flags: unittests |
| 40 | + name: zkapp-cli |
| 41 | + verbose: true |
| 42 | + handle_no_reports_found: true |
| 43 | + fail_ci_if_error: false |
| 44 | + |
| 45 | + sudoku-example-unit-tests: |
| 46 | + runs-on: ubuntu-latest |
| 47 | + needs: [common-unit-tests] |
| 48 | + strategy: |
| 49 | + matrix: |
| 50 | + node: [18] |
| 51 | + steps: |
| 52 | + - name: Set up NodeJS |
| 53 | + uses: actions/setup-node@v4 |
| 54 | + with: |
| 55 | + node-version: ${{ matrix.node }} |
| 56 | + - name: Git checkout |
| 57 | + uses: actions/checkout@v4 |
| 58 | + - name: Configure Git |
| 59 | + run: | |
| 60 | + git config --global user.email "[email protected]" |
| 61 | + git config --global user.name "Unit Tests" |
| 62 | + - name: NPM ci, build, & test |
| 63 | + run: | |
| 64 | + npm ci |
| 65 | + npm run build --if-present |
| 66 | + npm link |
| 67 | + zk example sudoku |
| 68 | + cd sudoku |
| 69 | + npm run test |
| 70 | + npm run build |
| 71 | + npm run start |
| 72 | + env: |
| 73 | + CI: true |
| 74 | + |
| 75 | + tictactoe-example-unit-tests: |
| 76 | + runs-on: ubuntu-latest |
| 77 | + needs: [common-unit-tests] |
| 78 | + strategy: |
| 79 | + matrix: |
| 80 | + node: [18] |
| 81 | + steps: |
| 82 | + - name: Set up NodeJS |
| 83 | + uses: actions/setup-node@v4 |
| 84 | + with: |
| 85 | + node-version: ${{ matrix.node }} |
| 86 | + - name: Git checkout |
| 87 | + uses: actions/checkout@v4 |
| 88 | + - name: Configure Git |
| 89 | + run: | |
| 90 | + git config --global user.email "[email protected]" |
| 91 | + git config --global user.name "Unit Tests" |
| 92 | + - name: NPM ci, build, & test |
| 93 | + run: | |
| 94 | + npm ci |
| 95 | + npm run build --if-present |
| 96 | + npm link |
| 97 | + zk example tictactoe |
| 98 | + cd tictactoe |
| 99 | + npm run test |
| 100 | + npm run build |
| 101 | + npm run start |
| 102 | + env: |
| 103 | + CI: true |
| 104 | + |
| 105 | + smoke-e2e-tests-against-compatible-network: |
| 106 | + needs: [sudoku-example-unit-tests, tictactoe-example-unit-tests] |
| 107 | + timeout-minutes: 30 |
| 108 | + runs-on: ${{ matrix.os }} |
| 109 | + strategy: |
| 110 | + fail-fast: true |
| 111 | + matrix: |
| 112 | + node: [18, 20] |
| 113 | + os: [ubuntu-latest] |
| 114 | + services: |
| 115 | + mina-local-network: |
| 116 | + image: o1labs/mina-local-network:compatible-latest-lightnet |
| 117 | + env: |
| 118 | + NETWORK_TYPE: 'single-node' |
| 119 | + PROOF_LEVEL: 'none' |
| 120 | + ports: |
| 121 | + - 3085:3085 |
| 122 | + - 5432:5432 |
| 123 | + - 8080:8080 |
| 124 | + - 8181:8181 |
| 125 | + - 8282:8282 |
| 126 | + volumes: |
| 127 | + - /tmp:/root/logs |
| 128 | + steps: |
| 129 | + - name: Wait for Mina network readiness |
| 130 | + uses: o1-labs/wait-for-mina-network-action@v1 |
| 131 | + with: |
| 132 | + mina-graphql-port: 8080 |
| 133 | + max-attempts: 60 |
| 134 | + polling-interval-ms: 10000 |
| 135 | + - uses: actions/checkout@v4 |
| 136 | + - name: Use shared E2E testing steps |
| 137 | + uses: ./.github/actions/e2e-shared |
| 138 | + with: |
| 139 | + node-version: ${{ matrix.node }} |
| 140 | + os-type: ${{ matrix.os }} |
| 141 | + shell: bash |
| 142 | + mina-branch: 'compatible' |
| 143 | + test-script: 'npm run e2e:test:smoke' |
| 144 | + artifacts-prefix: 'smoke-e2e-tests' |
| 145 | + |
| 146 | + smoke-e2e-tests-against-master-network: |
| 147 | + needs: [sudoku-example-unit-tests, tictactoe-example-unit-tests] |
| 148 | + timeout-minutes: 30 |
| 149 | + runs-on: ${{ matrix.os }} |
| 150 | + strategy: |
| 151 | + fail-fast: true |
| 152 | + matrix: |
| 153 | + node: [18, 20] |
| 154 | + os: [ubuntu-latest] |
| 155 | + services: |
| 156 | + mina-local-network: |
| 157 | + image: o1labs/mina-local-network:master-latest-lightnet |
| 158 | + env: |
| 159 | + NETWORK_TYPE: 'single-node' |
| 160 | + PROOF_LEVEL: 'none' |
| 161 | + ports: |
| 162 | + - 3085:3085 |
| 163 | + - 5432:5432 |
| 164 | + - 8080:8080 |
| 165 | + - 8181:8181 |
| 166 | + - 8282:8282 |
| 167 | + volumes: |
| 168 | + - /tmp:/root/logs |
| 169 | + steps: |
| 170 | + - name: Wait for Mina network readiness |
| 171 | + uses: o1-labs/wait-for-mina-network-action@v1 |
| 172 | + with: |
| 173 | + mina-graphql-port: 8080 |
| 174 | + max-attempts: 60 |
| 175 | + polling-interval-ms: 10000 |
| 176 | + - uses: actions/checkout@v4 |
| 177 | + - name: Use shared E2E testing steps |
| 178 | + uses: ./.github/actions/e2e-shared |
| 179 | + with: |
| 180 | + node-version: ${{ matrix.node }} |
| 181 | + os-type: ${{ matrix.os }} |
| 182 | + shell: bash |
| 183 | + mina-branch: 'master' |
| 184 | + test-script: 'npm run e2e:test:smoke' |
| 185 | + artifacts-prefix: 'smoke-e2e-tests' |
| 186 | + |
| 187 | + publish-to-npm: |
| 188 | + needs: |
| 189 | + [ |
| 190 | + smoke-e2e-tests-against-compatible-network, |
| 191 | + smoke-e2e-tests-against-master-network, |
| 192 | + ] |
| 193 | + if: github.ref == 'refs/heads/main' |
| 194 | + runs-on: ubuntu-latest |
| 195 | + strategy: |
| 196 | + matrix: |
| 197 | + node: [20] |
| 198 | + steps: |
| 199 | + - name: Set up NodeJS |
| 200 | + uses: actions/setup-node@v4 |
| 201 | + with: |
| 202 | + node-version: ${{ matrix.node }} |
| 203 | + - name: Git checkout |
| 204 | + uses: actions/checkout@v4 |
| 205 | + - name: NPM ci & build |
| 206 | + run: | |
| 207 | + npm ci |
| 208 | + npm run build --if-present |
| 209 | + - name: Publish to NPM if version has changed |
| 210 | + uses: JS-DevTools/npm-publish@v3 |
| 211 | + with: |
| 212 | + token: ${{ secrets.NPM_TOKEN }} |
| 213 | + strategy: upgrade |
| 214 | + env: |
| 215 | + INPUT_TOKEN: ${{ secrets.NPM_TOKEN }} |
0 commit comments