|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - master |
| 7 | + - develop |
| 8 | + - beta |
| 9 | + tags-ignore: |
| 10 | + - '**' |
| 11 | + paths-ignore: |
| 12 | + - '**/CHANGELOG.md' |
| 13 | + - '**/package.json' |
| 14 | + pull_request: |
| 15 | + workflow_dispatch: |
| 16 | + |
| 17 | +jobs: |
| 18 | + lint: |
| 19 | + runs-on: ubuntu-latest |
| 20 | + steps: |
| 21 | + - uses: actions/checkout@v2 |
| 22 | + |
| 23 | + - name: Use Node.js |
| 24 | + uses: actions/setup-node@v2 |
| 25 | + with: |
| 26 | + node-version-file: '.nvmrc' |
| 27 | + |
| 28 | + - name: Cache node modules |
| 29 | + uses: actions/cache@v2 |
| 30 | + env: |
| 31 | + cache-name: cache-node-modules |
| 32 | + with: |
| 33 | + path: | |
| 34 | + ~/.npm |
| 35 | + **/node_modules |
| 36 | + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} |
| 37 | + restore-keys: | |
| 38 | + ${{ runner.os }}-build-${{ env.cache-name }}- |
| 39 | + ${{ runner.os }}-build- |
| 40 | + ${{ runner.os }}- |
| 41 | +
|
| 42 | + - name: Install deps |
| 43 | + run: npm ci --audit=false |
| 44 | + |
| 45 | + - name: Lint ESLint |
| 46 | + run: npm run lint:eslint |
| 47 | + |
| 48 | + - name: Lint Prettier |
| 49 | + run: npm run lint:prettier |
| 50 | + |
| 51 | + test: |
| 52 | + runs-on: ubuntu-latest |
| 53 | + env: |
| 54 | + API_HOST: 127.0.0.1 |
| 55 | + API_PORT: 3000 |
| 56 | + PGHOST: 127.0.0.1 |
| 57 | + PGPORT: 5432 |
| 58 | + PGUSER: postgres |
| 59 | + PGPASSWORD: postgres |
| 60 | + PGDATABASE: postgres |
| 61 | + BLOCKCHAIN_API_PGHOST: 127.0.0.1 |
| 62 | + BLOCKCHAIN_API_PGPORT: 5432 |
| 63 | + BLOCKCHAIN_API_PGUSER: postgres |
| 64 | + BLOCKCHAIN_API_PGPASSWORD: postgres |
| 65 | + BLOCKCHAIN_API_PGDATABASE: postgres |
| 66 | + STACKS_NODE_RPC_HOST: 127.0.0.1 |
| 67 | + STACKS_NODE_RPC_PORT: 24440 |
| 68 | + steps: |
| 69 | + - uses: actions/checkout@v2 |
| 70 | + with: |
| 71 | + fetch-depth: 0 |
| 72 | + |
| 73 | + - name: Use Node.js |
| 74 | + uses: actions/setup-node@v2 |
| 75 | + with: |
| 76 | + node-version-file: '.nvmrc' |
| 77 | + |
| 78 | + - name: Cache node modules |
| 79 | + uses: actions/cache@v2 |
| 80 | + env: |
| 81 | + cache-name: cache-node-modules |
| 82 | + with: |
| 83 | + path: | |
| 84 | + ~/.npm |
| 85 | + **/node_modules |
| 86 | + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} |
| 87 | + restore-keys: | |
| 88 | + ${{ runner.os }}-build-${{ env.cache-name }}- |
| 89 | + ${{ runner.os }}-build- |
| 90 | + ${{ runner.os }}- |
| 91 | +
|
| 92 | + - name: Install deps |
| 93 | + run: npm ci --audit=false |
| 94 | + |
| 95 | + - name: Setup integration environment |
| 96 | + run: | |
| 97 | + sudo ufw disable |
| 98 | + npm run testenv:run -- -d |
| 99 | + npm run testenv:logs -- --no-color &> docker-compose-logs.txt & |
| 100 | +
|
| 101 | + - name: Run tests |
| 102 | + run: npm run test |
| 103 | + |
| 104 | + - name: Print integration environment logs |
| 105 | + run: cat docker-compose-logs.txt |
| 106 | + if: failure() |
| 107 | + |
| 108 | + - name: Teardown integration environment |
| 109 | + run: npm run testenv:stop |
| 110 | + if: always() |
| 111 | + |
| 112 | + build-publish: |
| 113 | + runs-on: ubuntu-latest |
| 114 | + needs: |
| 115 | + - lint |
| 116 | + - test |
| 117 | + steps: |
| 118 | + - uses: actions/checkout@v2 |
| 119 | + with: |
| 120 | + token: ${{ secrets.GH_TOKEN || secrets.GITHUB_TOKEN }} |
| 121 | + fetch-depth: 0 |
| 122 | + persist-credentials: false |
| 123 | + |
| 124 | + - name: Semantic Release |
| 125 | + |
| 126 | + id: semantic |
| 127 | + # Only run on non-PR events or only PRs that aren't from forks |
| 128 | + if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository |
| 129 | + env: |
| 130 | + GITHUB_TOKEN: ${{ secrets.GH_TOKEN || secrets.GITHUB_TOKEN }} |
| 131 | + SEMANTIC_RELEASE_PACKAGE: ${{ github.event.repository.name }} |
| 132 | + with: |
| 133 | + semantic_version: 19 |
| 134 | + extra_plugins: | |
| 135 | + @semantic-release/changelog |
| 136 | + @semantic-release/git |
| 137 | + conventional-changelog-conventionalcommits |
| 138 | +
|
| 139 | + - name: Set up Docker Buildx |
| 140 | + uses: docker/setup-buildx-action@v1 |
| 141 | + |
| 142 | + - name: Docker Meta |
| 143 | + id: meta |
| 144 | + uses: docker/metadata-action@v3 |
| 145 | + with: |
| 146 | + images: | |
| 147 | + hirosystems/${{ github.event.repository.name }} |
| 148 | + tags: | |
| 149 | + type=ref,event=branch |
| 150 | + type=ref,event=pr |
| 151 | + type=semver,pattern={{version}},value=${{ steps.semantic.outputs.new_release_version }},enable=${{ steps.semantic.outputs.new_release_version != '' }} |
| 152 | + type=semver,pattern={{major}}.{{minor}},value=${{ steps.semantic.outputs.new_release_version }},enable=${{ steps.semantic.outputs.new_release_version != '' }} |
| 153 | +
|
| 154 | + - name: Login to DockerHub |
| 155 | + uses: docker/login-action@v1 |
| 156 | + with: |
| 157 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 158 | + password: ${{ secrets.DOCKERHUB_PASSWORD }} |
| 159 | + |
| 160 | + - name: Build/Tag/Push Image |
| 161 | + uses: docker/build-push-action@v2 |
| 162 | + with: |
| 163 | + context: . |
| 164 | + tags: ${{ steps.meta.outputs.tags }} |
| 165 | + labels: ${{ steps.meta.outputs.labels }} |
| 166 | + # Only push if (there's a new release on main branch, or if building a non-main branch) and (Only run on non-PR events or only PRs that aren't from forks) |
| 167 | + push: ${{ (github.ref != 'refs/heads/master' || steps.semantic.outputs.new_release_version != '') && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) }} |
0 commit comments