|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v*.*.*' |
| 7 | + pull_request: |
| 8 | + branches: |
| 9 | + - master |
| 10 | + |
| 11 | +jobs: |
| 12 | + setup: |
| 13 | + name: Set up |
| 14 | + runs-on: ubuntu-20.04 |
| 15 | + |
| 16 | + steps: |
| 17 | + - name: Cancel previous workflow runs |
| 18 | + |
| 19 | + with: |
| 20 | + access_token: ${{ github.token }} |
| 21 | + |
| 22 | + - name: Load current commit |
| 23 | + uses: actions/checkout@v3 |
| 24 | + with: |
| 25 | + ref: ${{ github.ref }} |
| 26 | + |
| 27 | + - name: Read nvmrc |
| 28 | + id: read-nvmrc |
| 29 | + run: echo "version=$(cat .nvmrc)" >> $GITHUB_OUTPUT |
| 30 | + shell: bash |
| 31 | + |
| 32 | + - name: Setup Node.js |
| 33 | + uses: actions/setup-node@v3 |
| 34 | + with: |
| 35 | + node-version: ${{ steps.read-nvmrc.outputs.version }} |
| 36 | + |
| 37 | + - name: Install dependencies |
| 38 | + run: npm ci |
| 39 | + |
| 40 | + static-checks: |
| 41 | + name: Static checks |
| 42 | + needs: setup |
| 43 | + if: ${{ !contains(github.ref, 'refs/tags/') }} |
| 44 | + runs-on: ubuntu-20.04 |
| 45 | + |
| 46 | + steps: |
| 47 | + - name: Load current commit |
| 48 | + uses: actions/checkout@v3 |
| 49 | + with: |
| 50 | + ref: ${{ github.ref }} |
| 51 | + |
| 52 | + - name: Read nvmrc |
| 53 | + id: read-nvmrc |
| 54 | + run: echo "version=$(cat .nvmrc)" >> $GITHUB_OUTPUT |
| 55 | + shell: bash |
| 56 | + |
| 57 | + - name: Setup Node.js |
| 58 | + uses: actions/setup-node@v3 |
| 59 | + with: |
| 60 | + node-version: ${{ steps.read-nvmrc.outputs.version }} |
| 61 | + |
| 62 | + - name: Install dependencies and check package-lock.json |
| 63 | + run: | |
| 64 | + cp package-lock.json package-lock.json.orig |
| 65 | + npm install |
| 66 | + if ! diff --color=always package-lock.json.orig package-lock.json ; then |
| 67 | + echo "package-lock.json changed, failing build" |
| 68 | + exit 1 |
| 69 | + fi |
| 70 | +
|
| 71 | + - name: Linter |
| 72 | + run: npm run lint |
| 73 | + |
| 74 | + tests: |
| 75 | + name: Unit tests |
| 76 | + needs: setup |
| 77 | + if: ${{ !contains(github.ref, 'refs/tags/') }} |
| 78 | + runs-on: ubuntu-20.04 |
| 79 | + |
| 80 | + steps: |
| 81 | + - name: Load current commit |
| 82 | + uses: actions/checkout@v3 |
| 83 | + with: |
| 84 | + ref: ${{ github.ref }} |
| 85 | + |
| 86 | + - name: Read nvmrc |
| 87 | + id: read-nvmrc |
| 88 | + run: echo "version=$(cat .nvmrc)" >> $GITHUB_OUTPUT |
| 89 | + shell: bash |
| 90 | + |
| 91 | + - name: Setup Node.js |
| 92 | + uses: actions/setup-node@v3 |
| 93 | + with: |
| 94 | + node-version: ${{ steps.read-nvmrc.outputs.version }} |
| 95 | + |
| 96 | + - name: Install dependencies |
| 97 | + run: npm ci |
| 98 | + |
| 99 | + - name: Run unit tests and check coverage |
| 100 | + run: npm run test |
| 101 | + |
| 102 | + publish: |
| 103 | + name: Publish package |
| 104 | + needs: |
| 105 | + - setup |
| 106 | + runs-on: ubuntu-20.04 |
| 107 | + if: contains(github.ref, 'refs/tags/') |
| 108 | + |
| 109 | + steps: |
| 110 | + - name: Load current commit |
| 111 | + uses: actions/checkout@v3 |
| 112 | + with: |
| 113 | + ref: ${{ github.ref }} |
| 114 | + |
| 115 | + - name: Read nvmrc |
| 116 | + id: read-nvmrc |
| 117 | + run: echo "version=$(cat .nvmrc)" >> $GITHUB_OUTPUT |
| 118 | + shell: bash |
| 119 | + |
| 120 | + - name: Setup Node.js |
| 121 | + uses: actions/setup-node@v3 |
| 122 | + with: |
| 123 | + node-version: ${{ steps.read-nvmrc.outputs.version }} |
| 124 | + |
| 125 | + - name: Install dependencies |
| 126 | + run: npm ci |
| 127 | + |
| 128 | + - name: Setup Node.js |
| 129 | + uses: actions/setup-node@v3 |
| 130 | + with: |
| 131 | + node-version: ${{ steps.read-nvmrc.outputs.version }} |
| 132 | + registry-url: 'https://npm.pkg.github.com' |
| 133 | + |
| 134 | + - name: Publish package |
| 135 | + run: npm publish |
| 136 | + env: |
| 137 | + NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments