/ .github / workflows / test.yml
test.yml
  1  # SPDX-FileCopyrightText: 2024 Mass Labs
  2  #
  3  # SPDX-License-Identifier: MIT
  4  
  5  name: test
  6  
  7  on: [push]
  8  
  9  jobs:
 10    browser-tests:
 11      timeout-minutes: 15
 12      runs-on: [self-hosted, linux]
 13  
 14      permissions:
 15        contents: read
 16  
 17      steps:
 18        - uses: actions/checkout@v4
 19          with:
 20            path: Tennessine
 21  
 22        # not needed on self-hosted but kept around if we want to use it on github-hosted
 23        #- name: Install Nix
 24        #  uses: DeterminateSystems/nix-installer-action@main
 25        #- uses: DeterminateSystems/magic-nix-cache-action@main
 26        - uses: DeterminateSystems/flake-checker-action@main
 27          with:
 28            flake-lock-path: Tennessine/packages/client/flake.lock
 29  
 30        - name: Start local testnet
 31          run: |
 32            nix develop -c local-testnet -D -L logs/process-compose.log
 33          working-directory: Tennessine/
 34  
 35        - name: Run Lint
 36          run: nix develop -c bash -c "deno lint"
 37          working-directory: Tennessine/
 38  
 39        - name: Run formatting check
 40          run: nix develop -c bash -c "deno fmt --check"
 41          working-directory: Tennessine/
 42  
 43        - name: Type Check packages
 44          run: nix develop -c bash -c "deno check ."
 45          working-directory: Tennessine/
 46  
 47        # if this fails check the logs of the prior job. The relay should log it's failure reason there.
 48        # the logs for the other services might be bit harder to come by since they are orchestrated by docker.
 49        - name: check services running? 1. relay, 2. ipfs, 3. anvil
 50          run: |
 51            set -e
 52            # TODO: would be nice to have this all in probes and use a process-compose cli call to check readiness
 53            curl http://localhost:8321/live
 54            curl http://localhost:8321/processes | jq .data
 55  
 56            timeout=10;
 57            while [ $timeout -gt 0 ]; do
 58              # check if relay is ready
 59              processStateFname=Tennessine/logs/processes-${timeout}.json
 60              curl http://localhost:8321/processes > $processStateFname
 61              isReady=$(cat $processStateFname | jq -r '.data[] | select(.name == "relay") | .is_ready')
 62              if [ "$isReady" == "Ready" ]; then
 63                break
 64              fi
 65              echo "Relay is not ready, waiting for $timeout seconds"
 66              timeout=$((timeout - 1))
 67              sleep 5
 68            done
 69  
 70            if [ "$isReady" != "Ready" ]; then
 71              echo "Relay is not ready"
 72              nix run '.#local-testnet-dev' -- down
 73              exit 1
 74            fi
 75  
 76            # TODO: redundant once probes are in place
 77            curl http://localhost:4444/health
 78            curl http://localhost:5001/api/v0/version -X POST
 79            curl http://localhost:8545/ -X POST -H 'content-type: application/json' --data-raw '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":0}'
 80  
 81        - name: Run tests
 82          run: nix develop -c bash -c "deno test -A --no-check --fail-fast"
 83          working-directory: Tennessine/
 84  
 85        - name: Shut down local testnet
 86          run: nix develop -c local-testnet down
 87          working-directory: Tennessine/
 88  
 89        - name: build frontend
 90          run: nix develop -c bash -c "deno run production"
 91          working-directory: Tennessine/packages/frontend
 92  
 93        - name: Upload frontend to IPFS
 94          run: |
 95            REPO_NAME=$(echo "${{ github.repository }}" | tr '/' '-')
 96            COMMIT_SHA="${{ github.event.pull_request.head.sha || github.sha }}"
 97            COMMIT_SHA_SHORT="${COMMIT_SHA:0:7}"
 98            ipfs-cluster-ctl add -r -n $REPO_NAME-$COMMIT_SHA_SHORT --cid-version 1 ./dist > ipfs-cluster-add.log
 99            cid=$(egrep -o 'added (.*)' ipfs-cluster-add.log | cut -d ' ' -f2 | tail -n 1)
100            echo "CID=$cid" >> $GITHUB_ENV
101  
102            echo "Build Available as:" >> $GITHUB_STEP_SUMMARY
103            echo "https://$cid.ipfs.inbrowser.link" >> $GITHUB_STEP_SUMMARY
104            echo "https://$cid.ipfs.dweb.link" >> $GITHUB_STEP_SUMMARY
105  
106          working-directory: Tennessine/packages/frontend
107  
108        - name: Set ENS contenthash
109          if: ${{ github.ref == 'refs/heads/release/mainnet' }}
110          working-directory: Tennessine/packages/frontend
111          run: |
112            BLUMEN_PK=${{ secrets.BLUMEN_PK }} nix run --impure nixpkgs#deno -- run -A npm:blumen ens $CID shop.mass.eth --safe eth:0xec3DFB875fa5FdDe4916BEDdeB012Ef67a2f229F
113          env:
114            CID: ${{ env.CID }}
115  
116        - name: Upload frontend build as artifact
117          uses: actions/upload-artifact@v4
118          with:
119            name: frontend-build.zip
120            path: Tennessine/packages/frontend/dist
121  
122        - name: Upload service compose log on failure
123          if: ${{ failure() }}
124          uses: actions/upload-artifact@v4
125          with:
126            name: process-compose-log.txt
127            path: Tennessine/logs/