|
1 | | -name: CI test |
| 1 | +name: CI test and publish Docker image |
2 | 2 |
|
3 | | -on: [push] |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - master |
| 7 | + - dev |
| 8 | + pull_request: |
| 9 | + branches: |
| 10 | + - master |
| 11 | + - dev |
4 | 12 |
|
5 | 13 | jobs: |
6 | | - build: |
7 | | - |
8 | | - runs-on: ubuntu-16.04 |
9 | | - |
| 14 | + test: |
| 15 | + name: Run Tests |
| 16 | + runs-on: ubuntu-latest |
10 | 17 | strategy: |
11 | 18 | matrix: |
12 | | - node-version: [10.x, 12.x] |
| 19 | + node-version: [12.x, 14.x] |
| 20 | + mongodb-version: [4.2, 4.4] |
| 21 | + |
| 22 | + steps: |
| 23 | + - name: Git Checkout |
| 24 | + uses: actions/checkout@v2 |
| 25 | + |
| 26 | + - name: Use Node.js ${{ matrix.node-version }} |
| 27 | + uses: actions/setup-node@v1 |
| 28 | + with: |
| 29 | + node-version: ${{ matrix.node-version }} |
| 30 | + |
| 31 | + - name: Start MongoDB ${{ matrix.mongodb-version }} |
| 32 | + uses: supercharge/[email protected] |
| 33 | + with: |
| 34 | + mongodb-version: ${{ matrix.mongodb-version }} |
| 35 | + |
| 36 | + - name: Install dependencies |
| 37 | + run: npm install |
| 38 | + - name: Run Tests |
| 39 | + run: npm run-script test-ci |
| 40 | + - name: Send Coverage |
| 41 | + run: npm run-script coverage |
| 42 | + |
| 43 | + publish_dev: |
| 44 | + name: Publish dev branch to Docker Hub |
| 45 | + needs: test |
| 46 | + runs-on: ubuntu-latest |
| 47 | + if: github.ref == 'refs/heads/dev' && github.repository_owner == 'nightscout' |
| 48 | + env: |
| 49 | + DOCKER_IMAGE: nightscout/cgm-remote-monitor |
| 50 | + steps: |
| 51 | + - name: Login to Docker Hub |
| 52 | + uses: docker/login-action@v1 |
| 53 | + with: |
| 54 | + username: ${{ secrets.DOCKER_USER }} |
| 55 | + password: ${{ secrets.DOCKER_PASS }} |
| 56 | + - name: Clean git Checkout |
| 57 | + if: success() |
| 58 | + uses: actions/checkout@v2 |
| 59 | + - name: Build, tag and push the dev Docker image |
| 60 | + if: success() |
| 61 | + run: | |
| 62 | + docker build --no-cache=true -t ${{ env.DOCKER_IMAGE }}:dev_${{ github.sha }} . |
| 63 | + docker image push ${{ env.DOCKER_IMAGE }}:dev_${{ github.sha }} |
| 64 | + docker tag ${{ env.DOCKER_IMAGE }}:dev_${{ github.sha }} ${{ env.DOCKER_IMAGE }}:latest_dev |
| 65 | + docker image push ${{ env.DOCKER_IMAGE }}:latest_dev |
13 | 66 |
|
| 67 | + publish_master: |
| 68 | + name: Publish master branch to Docker Hub |
| 69 | + needs: test |
| 70 | + runs-on: ubuntu-latest |
| 71 | + if: github.ref == 'refs/heads/master' && github.repository_owner == 'nightscout' |
| 72 | + env: |
| 73 | + DOCKER_IMAGE: nightscout/cgm-remote-monitor |
14 | 74 | steps: |
15 | | - - uses: actions/checkout@v1 |
16 | | - - name: Use Node.js ${{ matrix.node-version }} |
17 | | - uses: actions/setup-node@v1 |
18 | | - with: |
19 | | - node-version: ${{ matrix.node-version }} |
20 | | - - name: Install dependencies |
21 | | - run: npm install |
22 | | - - name: Install MongoDB |
23 | | - run: | |
24 | | - wget -qO - https://www.mongodb.org/static/pgp/server-3.6.asc | sudo apt-key add - |
25 | | - echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.6 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.6.list |
26 | | - sudo apt-get update |
27 | | - sudo apt-get install -y mongodb-org |
28 | | - sudo apt-get install -y --allow-downgrades mongodb-org=3.6.14 mongodb-org-server=3.6.14 mongodb-org-shell=3.6.14 mongodb-org-mongos=3.6.14 mongodb-org-tools=3.6.14 |
29 | | - - name: Start MongoDB |
30 | | - run: sudo systemctl start mongod |
31 | | - - name: Run tests |
32 | | - run: npm run-script test-ci |
| 75 | + - name: Login to Docker Hub |
| 76 | + uses: docker/login-action@v1 |
| 77 | + with: |
| 78 | + username: ${{ secrets.DOCKER_USER }} |
| 79 | + password: ${{ secrets.DOCKER_PASS }} |
| 80 | + - name: Clean git Checkout |
| 81 | + if: success() |
| 82 | + uses: actions/checkout@v2 |
| 83 | + - name: get-npm-version |
| 84 | + if: success() |
| 85 | + id: package-version |
| 86 | + uses: martinbeentjes/npm-get-version-action@master |
| 87 | + - name: Build, tag and push the master Docker image |
| 88 | + if: success() |
| 89 | + run: | |
| 90 | + docker build --no-cache=true -t ${{ env.DOCKER_IMAGE }}:${{ steps.package-version.outputs.current-version }} . |
| 91 | + docker image push ${{ env.DOCKER_IMAGE }}:${{ steps.package-version.outputs.current-version }} |
| 92 | + docker tag ${{ env.DOCKER_IMAGE }}:${{ steps.package-version.outputs.current-version }} ${{ env.DOCKER_IMAGE }}:latest |
| 93 | + docker image push ${{ env.DOCKER_IMAGE }}:latest |
0 commit comments